-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (49 loc) · 1.74 KB
/
index.js
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
#!/usr/bin/env node
const path = require( 'path' );
const os = require('os');
const fs = require('fs');
const { runner } = require( 'hygen' );
const Logger = require( 'hygen/lib/logger' );
const defaultTemplates = path.resolve( __dirname, 'templates' );
const { prompt } = require( 'enquirer' )
async function run() {
const config = await prompt( [
{
type: 'input',
name: 'appName',
message: "Enter your app's name:"
},
{
type: 'confirm',
name: 'authEnabled',
default: true,
message: "Enable JWT auth?"
}
] )
await runner( [
'create-srfn-app',
'new'
], {
cwd: process.cwd(),
debug: true,
createPrompter: ()=>({prompt:()=>config}),
logger: new Logger( console.log.bind( console ) ),
templates: defaultTemplates
})
return config
}
run().then(config=>{
const home = os.homedir()
let appEnv = path.join(home, `.${config.appName}.env`);
if(fs.existsSync(appEnv)){
console.log(`${appEnv} already exists. You may need to update it to work for this new application.`)
} else {
fs.writeFileSync(appEnv, `#do not check this file in to source control!!\nSRFN_APP_NAME=${config.appName}\nAPP_URL=http://localhost:10420\n`)
if(config.authEnabled) {
console.warn( `With auth enabled, you should update JWT_SECRET and set JWT_ISSUER in ${appEnv}.` )
fs.appendFileSync( appEnv, 'JWT_SECRET=change_this_value\n' )
}
}
console.log( 'App initialized!\nTry `cd '+config.appName+' && npm install && npm run start` to start your app.' )
console.log( 'To get logged in, create a user by running `node createUser.js`.' )
})