-
Notifications
You must be signed in to change notification settings - Fork 0
/
kodesmell-init.js
72 lines (61 loc) · 1.58 KB
/
kodesmell-init.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
const program = require('commander');
const path = require('path');
const chalk = require('chalk');
const fs = require('fs')
const co = require('co')
const prompt = require('co-prompt')
const { createProject } = require('./lib/upload')
const package = require('./package.json')
const { promisify } = require('util')
const writeFile = promisify(fs.writeFile)
const readFile = promisify(fs.readFile)
const exists = promisify(fs.exists)
const mkdir = promisify(fs.mkdir)
const rmdir = promisify(fs.rmdir)
const open = promisify(fs.open)
const { title, error } = require('./lib/constants')
const headline = chalk.hex('#08f').bold('Kodesmell ')
const text = chalk.gray
const configs = require('./lib/config.js')
async function makeKodesmellDir({ id, name }) {
await mkdir(configs.KODESMELL_ROOT);
await writeFile(
configs.KODESMELL_JSON,
JSON.stringify(
{
project: id,
name,
_v: package.version
}
),
{
flag: "w",
encoding: 'utf-8'
}
);
console.log(headline + 'Suceessfully inited.')
console.log(headline + 'Start with \'kodesmell run\' in this repo')
}
async function init() {
const name = process.cwd().split(path.sep).pop()
try {
let data = await createProject({ name })
await makeKodesmellDir(data.createProject)
process.exit();
} catch(e) {
console.error(e);
process.exit(0);
}
}
(async function main() {
console.log(title('kodesmell init v' + package.version))
try {
let json = await open(configs.KODESMELL_JSON, 'r')
console.log('Project is already inited.')
process.exit();
} catch(e) {
if (e.code === 'ENOENT') {
init()
}
}
})()