-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsao.js
86 lines (85 loc) · 2.09 KB
/
sao.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const superb = require('superb')
const { exec } = require('child_process')
const fs = require('fs')
// https://sao.js.org/#/create?id=config-file
module.exports = {
enforceNewFolder: true,
showTip: false,
gitInit: false,
installDependencies: false,
prompts: {
domain: {
message: 'What is your vsc domain?',
default: 'github.com',
},
namespace: {
message: 'What is your vsc namespace?',
default: ':gitUser:',
},
description: {
message: 'How would you describe the new project?',
default: `my ${superb()} Go project`,
},
},
data({ domain, namespace }) {
return {
domainDir: `${domain}/${namespace}/`,
}
},
move: {
gitignore: '.gitignore',
},
post(
{
answers: { domain, namespace },
folderName,
folderPath,
log,
chalk,
},
stream
) {
// check for GOPATH env
if (!process.env.GOPATH) {
log.error(
`${chalk.magenta(
'$GOPATH'
)} is not set, it is mandatory for Go projects`
)
process.exit(1)
}
// check if same project src already exist
const srcPath = `${process.env.GOPATH}/src/${domain + '/' + namespace}`
const projectPath = `${srcPath}/${folderName}`
if (fs.existsSync(projectPath)) {
log.error(
`${chalk.magenta(
projectPath
)} already exist, please remove it or use a different project name!`
)
process.exit(1)
}
// move src to srcPath, because of how GOPATH works. In future releases
// where Go module is more stable we wouldn't have to do this.
exec(
`mkdir -p ${srcPath} && mv -n ${folderPath} ${srcPath}/${folderName}`,
(err, stdout, stderr) => {
if (err) {
log.error(err.message)
process.exit(1)
}
if (stderr) {
log.error(stderr)
process.exit(1)
}
// tips
log.success('Done, let the hacking begin!')
log.info(
`Type ${chalk.magenta(
'cd ' + srcPath + '/' + folderName
)} to get started!`
)
}
)
},
}