UNPKG

1.98 kBJavaScriptView Raw
1"use strict";
2var __importStar = (this && this.__importStar) || function (mod) {
3 if (mod && mod.__esModule) return mod;
4 var result = {};
5 if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
6 result["default"] = mod;
7 return result;
8};
9Object.defineProperty(exports, "__esModule", { value: true });
10const fs = __importStar(require("fs"));
11const help_1 = require("../help");
12class InitCommand {
13 constructor(config) {
14 this.config = config;
15 }
16 execute(params) {
17 if (this.repo) {
18 this.config.addRepo(this.repo);
19 this.config.data.current = this.repo.name;
20 console.log(this.repo.name);
21 }
22 }
23 validate(params) {
24 const options = params['options'];
25 if (options['help'] === true) {
26 const help = new help_1.Help();
27 help.initCommand();
28 process.exit(0);
29 }
30 const name = options['name'];
31 if (name === undefined || name === '') {
32 console.error('Error: repo name should supplied');
33 return false;
34 }
35 const dir = options['dir'];
36 if (dir === undefined || dir === '') {
37 console.error('Error: xref directory (--dir) should be supplied');
38 return false;
39 }
40 if (!fs.existsSync(dir)) {
41 console.error(`Error: directory '${dir}' does not exist`);
42 return false;
43 }
44 const dirInfo = fs.lstatSync(dir);
45 if (!dirInfo.isDirectory()) {
46 console.error(`Error: '${dir}' is not a directory`);
47 return false;
48 }
49 const srcdir = options['srcdir'];
50 const srcroot = options['srcroot'];
51 this.repo = {
52 name: name.toLowerCase(),
53 dir: dir,
54 srcdir: srcdir,
55 srcroot: srcroot
56 };
57 return true;
58 }
59}
60exports.InitCommand = InitCommand;
61//# sourceMappingURL=init.js.map
\No newline at end of file