-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·73 lines (59 loc) · 1.91 KB
/
index.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
#!/usr/bin/env node
const { Command } = require("commander");
const fs = require("fs");
const resolve = require("path").resolve;
const join = require("path").join;
const chalk = require("./Utils/chalk");
const gitCommit = require("./Utils/gitCommit");
const npmVersionCommand = require("./Commands/npmVersion");
const fastServeCommand = require("./Commands/fastServe");
const gitInitCommand = require("./Commands/gitInit");
const sortPackageCommand = require("./Commands/sortPackage");
const runPrettierCommand = require("./Commands/runPrettier");
const program = new Command();
program
.version("0.0.1")
.description("An example CLI for managing a directory")
.option("-w, --working-dir <value>", "working directory")
.option("-v, --npm-version", "NPM version")
.option("-f, --fast-serve", "Fast Serve")
.option("-g, --git-init", "git init")
.option("-s, --sort-package", "sort Package JSON")
.option("-p, --prettier", "run prettier")
.parse(process.argv);
const options = program.opts();
let path;
if (options.workingDir) {
path = resolve(options.workingDir);
} else {
path = process.cwd();
}
if (!fs.existsSync(join(path, "gulpfile.js"))) {
chalk.Error(
"path not found or does not contain gulpfile.js, exiting with code 1"
);
process.exit(1);
}
chalk.Message("SPFx folder path");
chalk.Message(path);
let gitInstalled;
if (options.gitInit) {
gitInstalled = gitInitCommand.gitInit(path);
gitInstalled && gitCommit("gitInit");
}
if (options.npmVersion) {
npmVersionCommand.npmVersion(join(path, "gulpfile.js"));
gitInstalled && gitCommit("npmVersion");
}
if (options.fastServe) {
fastServeCommand.fastServe(path);
gitInstalled && gitCommit("fastServe");
}
if (options.sortPackage) {
sortPackageCommand.sortPackage(join(path, "package.json"));
gitInstalled && gitCommit("sortPackage");
}
if (options.prettier) {
runPrettierCommand.runPrettier(path);
gitInstalled && gitCommit("prettier");
}