-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.js
47 lines (41 loc) · 976 Bytes
/
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
/**
* Created by WindomZ on 17-11-17.
*/
'use strict';
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
function generateFile(dir) {
dir = path.resolve(dir || process.cwd());
let filePath = path.join(dir, '.ciscript.yml');
// if exist ciscript.yml
// try {
// fs.accessSync(filePath, fs.R_OK);
// return filePath;
// } catch (e) {}
// write to ciscript.yml
try {
fs.writeFileSync(
filePath,
'## Generated by ci-script(https://github.com/WindomZ/ci-script)\n\n' +
yaml.safeDump({
script: ['echo "no script!" && exit 0'],
})
);
} catch (e) {
throw e;
}
return filePath;
}
function generateSync(dir) {
return generateFile(dir);
}
function* generate(dir) {
return yield generateFile(dir);
}
module.exports.initConfig = dir =>
new Promise(resolve => {
generate(dir).next();
resolve();
});
module.exports.initConfigSync = generateSync;