UNPKG

2.08 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const command_1 = require("@oclif/command");
4const fs_1 = require("mz/fs");
5const path_1 = require("path");
6const debug_1 = require("../lib/debug");
7const project_1 = require("../lib/project");
8const debug = debug_1.makeDebug(__dirname);
9/**
10 * Create a .clarkrc file in your project root
11 */
12class Init extends command_1.Command {
13 /**
14 * implementation
15 */
16 async run() {
17 const { flags: options } = this.parse(Init);
18 debug('locating root directory');
19 const rootDir = await project_1.findProjectRoot();
20 debug('checking if root dir contains a .clarkrc');
21 if ((await project_1.hasRc(rootDir)) && !options.force) {
22 throw new Error('Project already configured for clark. Pass --force to overwrite');
23 }
24 const extract = (s, item) => {
25 const [key, value] = item.split(/=(.+)/);
26 s[key] = value;
27 return s;
28 };
29 debug('generating scripts hash');
30 let scripts = {};
31 if (options.script) {
32 if (Array.isArray(options.script)) {
33 scripts = options.script.reduce(extract, scripts);
34 }
35 else {
36 extract(scripts, options.script);
37 }
38 }
39 const config = {
40 scripts,
41 };
42 debug(debug_1.format `writing .clarkrc to ${rootDir}`);
43 await fs_1.writeFile(path_1.resolve(rootDir, '.clarkrc'), `${JSON.stringify(config, null, 2)}\n`);
44 debug(debug_1.format `wrote .clarkrc to ${rootDir}`);
45 }
46}
47/**
48 * description
49 */
50Init.description = 'Create a .clarkrc file in your project root';
51/**
52 * flags
53 */
54Init.flags = {
55 force: command_1.flags.boolean({
56 char: 'f',
57 description: 'Overwrite .clarkrc with new config',
58 }),
59 script: command_1.flags.string({
60 char: 's',
61 description: 'Identifies a script to add to the config file',
62 multiple: true,
63 }),
64};
65exports.default = Init;
66//# sourceMappingURL=init.js.map
\No newline at end of file