-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.js
More file actions
64 lines (56 loc) · 1.72 KB
/
install.js
File metadata and controls
64 lines (56 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Requires
*/
const path = require( 'path' );
const isInstalledGlobally = require( 'is-installed-globally' );
const { cfx } = require( '@squirrel-forge/node-cfx' );
const pkg = require( path.join( __dirname, '../package.json' ) );
const { FsInterface } = require( '@squirrel-forge/node-util' );
/**
* Create config
* @return {Promise<boolean|string>} - Path string if created
*/
async function createConfig() {
// Project directory relation is always:
// :/project/node_modules/@squirrel-forge/twighouse/src/
const project_config = path.resolve( __dirname, '../../../../', '.twighouse' );
const has_config = await FsInterface.exists( project_config );
let wrote = false;
if ( !has_config ) {
// Attempt to create a blank config
try {
wrote = await FsInterface.write( project_config, '{}' );
} catch ( e ) {
cfx.log( e.toString() );
}
// On success supply the path written to
if ( wrote === true ) {
wrote = project_config;
}
}
return wrote;
}
/**
* Issue install notice
*/
cfx.success( 'Thanks for trying ' + pkg.name + ' ['
+ ( isInstalledGlobally ? 'global' : 'local' ) + ']' );
/**
* How to run notice
*/
if ( isInstalledGlobally ) {
cfx.info( 'For help run: [fwhite]twighouse -h or --help' );
} else {
cfx.info( 'For help run: [fwhite]npx twighouse -h or --help' );
}
/**
* Create an empty .twighouse config in the project directory
*/
if ( !isInstalledGlobally ) {
// Might issue an exception message, but should never break ;)
createConfig().then( ( created ) => {
if ( created ) {
cfx.success( 'Created an empty project config at: ' + created );
}
} );
}