-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathstart.ts
More file actions
93 lines (84 loc) · 2.58 KB
/
start.ts
File metadata and controls
93 lines (84 loc) · 2.58 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { GoogleAnalytics, ProjectConfig, Util } from "@igniteui/cli-core";
import { ExecSyncOptions } from "child_process";
import * as path from "path";
import * as resolve from "resolve";
import { default as build } from "./build";
import { PositionalArgs, StartCommandType } from "./types";
import { ArgumentsCamelCase } from "yargs";
const execSyncNpmStart = (port: number, options: ExecSyncOptions): void => {
if (port) {
// Validate port is a number to prevent command injection
if (!Number.isInteger(port) || port < 0 || port > 65535) {
Util.error(`Invalid port number: ${port}`, "red");
return;
}
Util.execSync(`npm start -- --port=${port}`, options);
return;
}
Util.execSync(`npm start`, options);
};
const command: StartCommandType = {
command: "start",
describe: "Starts the project",
builder: (yargs) => {
return yargs
.option("port", {
alias: "p",
describe: "Port to serve the app on",
type: "number"
});
},
async handler(argv: ArgumentsCamelCase<PositionalArgs>) {
GoogleAnalytics.post({
t: "screenview",
cd: "Start"
});
command.start(argv);
},
async start(argv: ArgumentsCamelCase<PositionalArgs>) {
if (!ProjectConfig.hasLocalConfig()) {
Util.error("Start command is supported only on existing project created with igniteui-cli", "red");
return;
}
//build
await build.build();
const config = ProjectConfig.getConfig();
const framework = config.project.framework;
const projectType = config.project.projectType;
const defaultPort = config.project.defaultPort;
Util.log(`Starting project.`, "green");
GoogleAnalytics.post({
t: "event",
ec: "$ig start",
cd1: framework,
cd2: projectType,
cd11: !!config.skipGit,
cd14: config.project.theme
});
const port = Number(argv.port) || defaultPort;
// TODO: consider piping the stdin so that we handle the cp's termination
// this may require additional logic to be implemented if the cp asks for input
const options: ExecSyncOptions = { stdio: "inherit", killSignal: "SIGINT" };
switch (framework.toLowerCase()) {
case "jquery":
// browser-sync installed per project
const bs = require(resolve.sync("browser-sync", { basedir: process.cwd() }));
const browserSync = bs.create("igniteui-cli");
const filePath = path.join(process.cwd(), "bs-config.js");
const bsConfig = require(filePath);
if (port) {
bsConfig.port = port;
}
browserSync.init(bsConfig);
break;
case "angular":
case "react":
case "webcomponents":
execSyncNpmStart(port, options);
break;
default:
break;
}
}
};
export default command;