create-windowless-app 9.3.7 → 10.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cliParser.js +103 -103
- package/dist/consts.js +65 -65
- package/dist/createWindowlessApp.js +267 -267
- package/dist/createWindowlessAppUtils.js +99 -99
- package/dist/fileUtils.js +37 -37
- package/dist/index.js +5 -5
- package/dist/interactive.js +54 -54
- package/dist/launcherCompiler.js +64 -64
- package/dist/main.js +28 -28
- package/dist/nodeUtils.js +119 -119
- package/dist/validation.js +18 -18
- package/npm-shrinkwrap.json +237 -166
- package/package.json +14 -14
- package/templates/typescript/tsconfig.json +1 -1
|
@@ -1,267 +1,267 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.createWindowlessApp = exports.buildLauncher = void 0;
|
|
39
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
40
|
-
const path = __importStar(require("path"));
|
|
41
|
-
const fs_extra_1 = require("fs-extra");
|
|
42
|
-
const cross_spawn_1 = __importDefault(require("cross-spawn"));
|
|
43
|
-
const launcherCompiler_1 = require("./launcherCompiler");
|
|
44
|
-
const consts_1 = __importDefault(require("./consts"));
|
|
45
|
-
const createWindowlessAppUtils_1 = require("./createWindowlessAppUtils");
|
|
46
|
-
const fileUtils_1 = require("./fileUtils");
|
|
47
|
-
const nodeUtils_1 = require("./nodeUtils");
|
|
48
|
-
const cliParser_1 = require("./cliParser");
|
|
49
|
-
// TypeScript
|
|
50
|
-
const tsWebpackConfigResourceLocation = "../templates/typescript/webpack.config.ts";
|
|
51
|
-
const tsConfigBuildResourceLocation = "../templates/typescript/tsconfig.build.json";
|
|
52
|
-
const tsConfigResourceLocation = "../templates/typescript/tsconfig.json";
|
|
53
|
-
const tsIndexResourceLocation = "../templates/typescript/src/index.ts";
|
|
54
|
-
const tsLauncherCompilerLocation = "../templates/typescript/launcher/launcherCompiler.ts";
|
|
55
|
-
// JavaScript
|
|
56
|
-
const jsWebpackConfigResourceLocation = "../templates/javascript/webpack.config.js";
|
|
57
|
-
const jsIndexResourceLocation = "../templates/javascript/src/index.js";
|
|
58
|
-
const jsLauncherCompilerLocation = "../templates/javascript/launcher/launcherCompiler.js";
|
|
59
|
-
// Launcher Source
|
|
60
|
-
const launcherSrcResourceLocation = "../templates/common/src/launcher.cs";
|
|
61
|
-
const launcherSrcModifiedLocation = "launcher/launcher.cs";
|
|
62
|
-
const launcherProjResourceLocation = "../templates/common/launcher.csproj";
|
|
63
|
-
const launcherProjModifiedLocation = "launcher/launcher.csproj";
|
|
64
|
-
// Default icon location
|
|
65
|
-
const defaultLauncherIconLocation = "../templates/common/resources/windows-launcher.ico";
|
|
66
|
-
// Husky config file
|
|
67
|
-
const huskyConfigFileLocation = "../templates/common/husky/pre-commit";
|
|
68
|
-
const install = (root, dependencies, isDev, programConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
-
const { verbose, skipInstall } = programConfig;
|
|
70
|
-
if (!skipInstall) {
|
|
71
|
-
const command = "npm";
|
|
72
|
-
const args = ["install", isDev ? "--save-dev" : "--save", "--save-exact", "--loglevel", "error"].concat(dependencies);
|
|
73
|
-
if (verbose) {
|
|
74
|
-
args.push("--verbose");
|
|
75
|
-
}
|
|
76
|
-
console.log(`Installing ${chalk_1.default.green(isDev ? "dev dependencies" : "dependencies")}.`);
|
|
77
|
-
console.log();
|
|
78
|
-
cross_spawn_1.default.sync(command, args, { stdio: "inherit" });
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
console.log(`Adding ${chalk_1.default.green(isDev ? "dev dependencies" : "dependencies")} to package.json (skipping installation)`);
|
|
82
|
-
console.log();
|
|
83
|
-
const dependenciesObject = dependencies.reduce((acc, dep) => {
|
|
84
|
-
var _a, _b, _c;
|
|
85
|
-
let depName = dep;
|
|
86
|
-
let depVersion = "^x.x.x";
|
|
87
|
-
if (dep.lastIndexOf("@") > 0) {
|
|
88
|
-
depName = dep.substring(0, dep.lastIndexOf("@"));
|
|
89
|
-
const depVersionString = dep.substring(dep.lastIndexOf("@")).split(".");
|
|
90
|
-
depVersion = `^${(_a = depVersionString === null || depVersionString === void 0 ? void 0 : depVersionString[0]) !== null && _a !== void 0 ? _a : "x"}.${(_b = depVersionString === null || depVersionString === void 0 ? void 0 : depVersionString[1]) !== null && _b !== void 0 ? _b : "x"}.${(_c = depVersionString === null || depVersionString === void 0 ? void 0 : depVersionString[2]) !== null && _c !== void 0 ? _c : "x"}`;
|
|
91
|
-
}
|
|
92
|
-
acc[depName] = depVersion;
|
|
93
|
-
return acc;
|
|
94
|
-
}, {});
|
|
95
|
-
(0, createWindowlessAppUtils_1.mergeIntoPackageJson)(root, isDev ? "devDependencies" : "dependencies", dependenciesObject);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
const buildTypeScriptProject = (root, appName, nodeVersion, husky) => {
|
|
99
|
-
console.log(`Building project ${chalk_1.default.green("files")}.`);
|
|
100
|
-
console.log();
|
|
101
|
-
(0, fileUtils_1.writeJson)(path.resolve(root, "tsconfig.build.json"), (0, fileUtils_1.readJsonResource)(tsConfigBuildResourceLocation));
|
|
102
|
-
(0, fileUtils_1.writeJson)(path.resolve(root, "tsconfig.json"), (0, fileUtils_1.readJsonResource)(tsConfigResourceLocation));
|
|
103
|
-
(0, fileUtils_1.writeFile)(path.resolve(root, "webpack.config.ts"), (0, createWindowlessAppUtils_1.replaceAppNamePlaceholder)((0, fileUtils_1.readResource)(tsWebpackConfigResourceLocation), appName));
|
|
104
|
-
(0, fs_extra_1.ensureDirSync)(path.resolve(root, "src"));
|
|
105
|
-
(0, fileUtils_1.writeFile)(path.resolve(root, "src", "index.ts"), (0, createWindowlessAppUtils_1.replaceAppNamePlaceholder)((0, fileUtils_1.readResource)(tsIndexResourceLocation), appName));
|
|
106
|
-
// Add scripts
|
|
107
|
-
const scripts = {
|
|
108
|
-
"start": "ts-node src/index.ts",
|
|
109
|
-
"type-check": "tsc --build tsconfig.json",
|
|
110
|
-
"prewebpack": "rimraf build && rimraf dist",
|
|
111
|
-
"webpack": "webpack",
|
|
112
|
-
"nexe": (0, createWindowlessAppUtils_1.getNexeCommand)(appName, nodeVersion),
|
|
113
|
-
"build": "npm run type-check && npm run webpack && npm run nexe",
|
|
114
|
-
"check-msbuild": "ts-node -e \"require(\"\"./launcher/launcherCompiler\"\").checkMsbuildInPath(true)\"",
|
|
115
|
-
"rebuild-launcher": "msbuild launcher/launcher.csproj"
|
|
116
|
-
};
|
|
117
|
-
// Add husky
|
|
118
|
-
if (husky) {
|
|
119
|
-
scripts["prepare"] = "git config --get core.hookspath || husky install";
|
|
120
|
-
scripts["pre-commit"] = `git diff HEAD --exit-code --stat launcher/* || npm run check-msbuild && npm run rebuild-launcher && git add resources/bin/${appName}-launcher.exe`;
|
|
121
|
-
(0, fs_extra_1.ensureDirSync)(path.resolve(root, ".husky"));
|
|
122
|
-
(0, fileUtils_1.writeFile)(path.resolve(root, ".husky", "pre-commit"), (0, fileUtils_1.readResource)(huskyConfigFileLocation));
|
|
123
|
-
}
|
|
124
|
-
(0, createWindowlessAppUtils_1.mergeIntoPackageJson)(root, "scripts", scripts);
|
|
125
|
-
};
|
|
126
|
-
const buildJavaScriptProject = (root, appName, nodeVersion, husky) => {
|
|
127
|
-
console.log(`Building project ${chalk_1.default.green("files")}.`);
|
|
128
|
-
console.log();
|
|
129
|
-
(0, fileUtils_1.writeFile)(path.resolve(root, "webpack.config.js"), (0, createWindowlessAppUtils_1.replaceAppNamePlaceholder)((0, fileUtils_1.readResource)(jsWebpackConfigResourceLocation), appName));
|
|
130
|
-
(0, fs_extra_1.ensureDirSync)(path.resolve(root, "src"));
|
|
131
|
-
(0, fileUtils_1.writeFile)(path.resolve(root, "src", "index.js"), (0, createWindowlessAppUtils_1.replaceAppNamePlaceholder)((0, fileUtils_1.readResource)(jsIndexResourceLocation), appName));
|
|
132
|
-
// Add scripts
|
|
133
|
-
const scripts = {
|
|
134
|
-
"start": "node src/index.js",
|
|
135
|
-
"prewebpack": "rimraf build && rimraf dist",
|
|
136
|
-
"webpack": "webpack",
|
|
137
|
-
"nexe": (0, createWindowlessAppUtils_1.getNexeCommand)(appName, nodeVersion),
|
|
138
|
-
"build": "npm run webpack && npm run nexe",
|
|
139
|
-
"check-msbuild": "node -e \"require(\"\"./launcher/launcherCompiler\"\").checkMsbuildInPath(true)\"",
|
|
140
|
-
"rebuild-launcher": "msbuild launcher/launcher.csproj"
|
|
141
|
-
};
|
|
142
|
-
// Add husky
|
|
143
|
-
if (husky) {
|
|
144
|
-
scripts["prepare"] = "git config --get core.hookspath || husky install";
|
|
145
|
-
scripts["pre-commit"] = `git diff HEAD --exit-code --stat launcher/* || npm run check-msbuild && npm run rebuild-launcher && git add resources/bin/${appName}-launcher.exe`;
|
|
146
|
-
(0, fs_extra_1.ensureDirSync)(path.resolve(root, ".husky"));
|
|
147
|
-
(0, fileUtils_1.writeFile)(path.resolve(root, ".husky", "pre-commit"), (0, fileUtils_1.readResource)(huskyConfigFileLocation));
|
|
148
|
-
}
|
|
149
|
-
(0, createWindowlessAppUtils_1.mergeIntoPackageJson)(root, "scripts", scripts);
|
|
150
|
-
};
|
|
151
|
-
const buildLauncher = (root, appName, icon, typescript) => {
|
|
152
|
-
console.log(`Building project ${chalk_1.default.green("launcher")}.`);
|
|
153
|
-
console.log();
|
|
154
|
-
(0, fs_extra_1.ensureDirSync)(path.resolve("launcher"));
|
|
155
|
-
(0, fileUtils_1.writeFile)(path.resolve(launcherSrcModifiedLocation), (0, createWindowlessAppUtils_1.replaceAppNamePlaceholder)((0, fileUtils_1.readResource)(launcherSrcResourceLocation), appName));
|
|
156
|
-
(0, fileUtils_1.writeFile)(path.resolve(launcherProjModifiedLocation), (0, createWindowlessAppUtils_1.replaceAppNamePlaceholder)((0, fileUtils_1.readResource)(launcherProjResourceLocation), appName));
|
|
157
|
-
if (typescript) {
|
|
158
|
-
(0, fileUtils_1.copyFile)(path.resolve(__dirname, tsLauncherCompilerLocation), path.resolve(root, "launcher", "launcherCompiler.ts"));
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
(0, fileUtils_1.copyFile)(path.resolve(__dirname, jsLauncherCompilerLocation), path.resolve(root, "launcher", "launcherCompiler.js"));
|
|
162
|
-
}
|
|
163
|
-
// Resolve icon
|
|
164
|
-
let iconLocation;
|
|
165
|
-
if (icon) {
|
|
166
|
-
iconLocation = path.resolve(icon);
|
|
167
|
-
console.log(`Building launcher with icon: ${chalk_1.default.green(icon)}.`);
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
iconLocation = path.resolve(__dirname, defaultLauncherIconLocation);
|
|
171
|
-
console.log(`Building launcher with ${chalk_1.default.green("default")} icon.`);
|
|
172
|
-
}
|
|
173
|
-
(0, fileUtils_1.copyFile)(iconLocation, path.resolve(root, "launcher", "launcher.ico"));
|
|
174
|
-
return (0, launcherCompiler_1.compileLauncher)();
|
|
175
|
-
};
|
|
176
|
-
exports.buildLauncher = buildLauncher;
|
|
177
|
-
const run = (root, appName, originalDirectory, programConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
178
|
-
const { typescript, husky, icon, nodeVersion } = programConfig;
|
|
179
|
-
const dependencies = [...consts_1.default.dependencies];
|
|
180
|
-
const devDependencies = [...consts_1.default.devDependencies];
|
|
181
|
-
if (typescript) {
|
|
182
|
-
devDependencies.push(...consts_1.default.tsDevDependencies);
|
|
183
|
-
}
|
|
184
|
-
if (husky) {
|
|
185
|
-
devDependencies.push(...consts_1.default.huskyDependencies);
|
|
186
|
-
}
|
|
187
|
-
try {
|
|
188
|
-
yield install(root, dependencies, false, programConfig);
|
|
189
|
-
yield install(root, devDependencies, true, programConfig);
|
|
190
|
-
const checkedNodeVersion = yield (0, nodeUtils_1.checkNodeVersion)(nodeVersion);
|
|
191
|
-
if (typescript) {
|
|
192
|
-
buildTypeScriptProject(root, appName, checkedNodeVersion, husky);
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
buildJavaScriptProject(root, appName, checkedNodeVersion, husky);
|
|
196
|
-
}
|
|
197
|
-
// Launcher
|
|
198
|
-
(0, fs_extra_1.ensureDirSync)(path.resolve(root, "resources", "bin"));
|
|
199
|
-
yield (0, exports.buildLauncher)(root, appName, icon, typescript);
|
|
200
|
-
console.log("Done");
|
|
201
|
-
}
|
|
202
|
-
catch (reason) {
|
|
203
|
-
console.log();
|
|
204
|
-
console.log("Aborting installation.");
|
|
205
|
-
if (reason.command) {
|
|
206
|
-
console.log(` ${chalk_1.default.cyan(reason.command)} has failed.`);
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
console.log(chalk_1.default.red("Unexpected error. Please report it as a bug:"));
|
|
210
|
-
console.log(reason);
|
|
211
|
-
}
|
|
212
|
-
console.log();
|
|
213
|
-
// On 'exit' we will delete these files from target directory.
|
|
214
|
-
const knownGeneratedFiles = [...consts_1.default.knownGeneratedFiles];
|
|
215
|
-
const currentFiles = (0, fs_extra_1.readdirSync)(path.join(root));
|
|
216
|
-
currentFiles.forEach((file) => {
|
|
217
|
-
knownGeneratedFiles.forEach((fileToMatch) => {
|
|
218
|
-
// This removes all knownGeneratedFiles.
|
|
219
|
-
if (file === fileToMatch) {
|
|
220
|
-
console.log(`Deleting generated file... ${chalk_1.default.cyan(file)}`);
|
|
221
|
-
(0, fs_extra_1.removeSync)(path.join(root, file));
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
const remainingFiles = (0, fs_extra_1.readdirSync)(path.join(root));
|
|
226
|
-
if (!remainingFiles.length) {
|
|
227
|
-
// Delete target folder if empty
|
|
228
|
-
console.log(`Deleting ${chalk_1.default.cyan(`${appName}/`)} from ${chalk_1.default.cyan(path.resolve(root, ".."))}`);
|
|
229
|
-
process.chdir(path.resolve(root, ".."));
|
|
230
|
-
(0, fs_extra_1.removeSync)(path.join(root));
|
|
231
|
-
}
|
|
232
|
-
console.log("Done (with errors).");
|
|
233
|
-
process.exit(1);
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
const createApp = (programConfig) => {
|
|
237
|
-
const { projectName } = programConfig;
|
|
238
|
-
const root = path.resolve(projectName);
|
|
239
|
-
const appName = path.basename(root);
|
|
240
|
-
(0, createWindowlessAppUtils_1.checkAppName)(appName);
|
|
241
|
-
(0, fs_extra_1.ensureDirSync)(projectName);
|
|
242
|
-
if (!(0, createWindowlessAppUtils_1.isSafeToCreateProjectIn)(root, projectName)) {
|
|
243
|
-
process.exit(1);
|
|
244
|
-
}
|
|
245
|
-
console.log(`Creating a new windowless app in ${chalk_1.default.green(root)}.`);
|
|
246
|
-
console.log();
|
|
247
|
-
const packageJson = {
|
|
248
|
-
name: appName,
|
|
249
|
-
version: "0.1.0",
|
|
250
|
-
private: true,
|
|
251
|
-
main: "_build/index.js"
|
|
252
|
-
};
|
|
253
|
-
(0, fileUtils_1.writeJson)(path.join(root, "package.json"), packageJson);
|
|
254
|
-
const originalDirectory = process.cwd();
|
|
255
|
-
process.chdir(root);
|
|
256
|
-
if (!(0, nodeUtils_1.checkThatNpmCanReadCwd)()) {
|
|
257
|
-
process.exit(1);
|
|
258
|
-
}
|
|
259
|
-
return run(root, appName, originalDirectory, programConfig);
|
|
260
|
-
};
|
|
261
|
-
const createWindowlessApp = (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
262
|
-
const programConfig = yield (0, cliParser_1.parseCommand)(argv);
|
|
263
|
-
if (programConfig.projectName) {
|
|
264
|
-
return createApp(programConfig);
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
exports.createWindowlessApp = createWindowlessApp;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.createWindowlessApp = exports.buildLauncher = void 0;
|
|
39
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const fs_extra_1 = require("fs-extra");
|
|
42
|
+
const cross_spawn_1 = __importDefault(require("cross-spawn"));
|
|
43
|
+
const launcherCompiler_1 = require("./launcherCompiler");
|
|
44
|
+
const consts_1 = __importDefault(require("./consts"));
|
|
45
|
+
const createWindowlessAppUtils_1 = require("./createWindowlessAppUtils");
|
|
46
|
+
const fileUtils_1 = require("./fileUtils");
|
|
47
|
+
const nodeUtils_1 = require("./nodeUtils");
|
|
48
|
+
const cliParser_1 = require("./cliParser");
|
|
49
|
+
// TypeScript
|
|
50
|
+
const tsWebpackConfigResourceLocation = "../templates/typescript/webpack.config.ts";
|
|
51
|
+
const tsConfigBuildResourceLocation = "../templates/typescript/tsconfig.build.json";
|
|
52
|
+
const tsConfigResourceLocation = "../templates/typescript/tsconfig.json";
|
|
53
|
+
const tsIndexResourceLocation = "../templates/typescript/src/index.ts";
|
|
54
|
+
const tsLauncherCompilerLocation = "../templates/typescript/launcher/launcherCompiler.ts";
|
|
55
|
+
// JavaScript
|
|
56
|
+
const jsWebpackConfigResourceLocation = "../templates/javascript/webpack.config.js";
|
|
57
|
+
const jsIndexResourceLocation = "../templates/javascript/src/index.js";
|
|
58
|
+
const jsLauncherCompilerLocation = "../templates/javascript/launcher/launcherCompiler.js";
|
|
59
|
+
// Launcher Source
|
|
60
|
+
const launcherSrcResourceLocation = "../templates/common/src/launcher.cs";
|
|
61
|
+
const launcherSrcModifiedLocation = "launcher/launcher.cs";
|
|
62
|
+
const launcherProjResourceLocation = "../templates/common/launcher.csproj";
|
|
63
|
+
const launcherProjModifiedLocation = "launcher/launcher.csproj";
|
|
64
|
+
// Default icon location
|
|
65
|
+
const defaultLauncherIconLocation = "../templates/common/resources/windows-launcher.ico";
|
|
66
|
+
// Husky config file
|
|
67
|
+
const huskyConfigFileLocation = "../templates/common/husky/pre-commit";
|
|
68
|
+
const install = (root, dependencies, isDev, programConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
const { verbose, skipInstall } = programConfig;
|
|
70
|
+
if (!skipInstall) {
|
|
71
|
+
const command = "npm";
|
|
72
|
+
const args = ["install", isDev ? "--save-dev" : "--save", "--save-exact", "--loglevel", "error"].concat(dependencies);
|
|
73
|
+
if (verbose) {
|
|
74
|
+
args.push("--verbose");
|
|
75
|
+
}
|
|
76
|
+
console.log(`Installing ${chalk_1.default.green(isDev ? "dev dependencies" : "dependencies")}.`);
|
|
77
|
+
console.log();
|
|
78
|
+
cross_spawn_1.default.sync(command, args, { stdio: "inherit" });
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
console.log(`Adding ${chalk_1.default.green(isDev ? "dev dependencies" : "dependencies")} to package.json (skipping installation)`);
|
|
82
|
+
console.log();
|
|
83
|
+
const dependenciesObject = dependencies.reduce((acc, dep) => {
|
|
84
|
+
var _a, _b, _c;
|
|
85
|
+
let depName = dep;
|
|
86
|
+
let depVersion = "^x.x.x";
|
|
87
|
+
if (dep.lastIndexOf("@") > 0) {
|
|
88
|
+
depName = dep.substring(0, dep.lastIndexOf("@"));
|
|
89
|
+
const depVersionString = dep.substring(dep.lastIndexOf("@")).split(".");
|
|
90
|
+
depVersion = `^${(_a = depVersionString === null || depVersionString === void 0 ? void 0 : depVersionString[0]) !== null && _a !== void 0 ? _a : "x"}.${(_b = depVersionString === null || depVersionString === void 0 ? void 0 : depVersionString[1]) !== null && _b !== void 0 ? _b : "x"}.${(_c = depVersionString === null || depVersionString === void 0 ? void 0 : depVersionString[2]) !== null && _c !== void 0 ? _c : "x"}`;
|
|
91
|
+
}
|
|
92
|
+
acc[depName] = depVersion;
|
|
93
|
+
return acc;
|
|
94
|
+
}, {});
|
|
95
|
+
(0, createWindowlessAppUtils_1.mergeIntoPackageJson)(root, isDev ? "devDependencies" : "dependencies", dependenciesObject);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
const buildTypeScriptProject = (root, appName, nodeVersion, husky) => {
|
|
99
|
+
console.log(`Building project ${chalk_1.default.green("files")}.`);
|
|
100
|
+
console.log();
|
|
101
|
+
(0, fileUtils_1.writeJson)(path.resolve(root, "tsconfig.build.json"), (0, fileUtils_1.readJsonResource)(tsConfigBuildResourceLocation));
|
|
102
|
+
(0, fileUtils_1.writeJson)(path.resolve(root, "tsconfig.json"), (0, fileUtils_1.readJsonResource)(tsConfigResourceLocation));
|
|
103
|
+
(0, fileUtils_1.writeFile)(path.resolve(root, "webpack.config.ts"), (0, createWindowlessAppUtils_1.replaceAppNamePlaceholder)((0, fileUtils_1.readResource)(tsWebpackConfigResourceLocation), appName));
|
|
104
|
+
(0, fs_extra_1.ensureDirSync)(path.resolve(root, "src"));
|
|
105
|
+
(0, fileUtils_1.writeFile)(path.resolve(root, "src", "index.ts"), (0, createWindowlessAppUtils_1.replaceAppNamePlaceholder)((0, fileUtils_1.readResource)(tsIndexResourceLocation), appName));
|
|
106
|
+
// Add scripts
|
|
107
|
+
const scripts = {
|
|
108
|
+
"start": "ts-node src/index.ts",
|
|
109
|
+
"type-check": "tsc --build tsconfig.json",
|
|
110
|
+
"prewebpack": "rimraf build && rimraf dist",
|
|
111
|
+
"webpack": "webpack",
|
|
112
|
+
"nexe": (0, createWindowlessAppUtils_1.getNexeCommand)(appName, nodeVersion),
|
|
113
|
+
"build": "npm run type-check && npm run webpack && npm run nexe",
|
|
114
|
+
"check-msbuild": "ts-node -e \"require(\"\"./launcher/launcherCompiler\"\").checkMsbuildInPath(true)\"",
|
|
115
|
+
"rebuild-launcher": "msbuild launcher/launcher.csproj"
|
|
116
|
+
};
|
|
117
|
+
// Add husky
|
|
118
|
+
if (husky) {
|
|
119
|
+
scripts["prepare"] = "git config --get core.hookspath || husky install";
|
|
120
|
+
scripts["pre-commit"] = `git diff HEAD --exit-code --stat launcher/* || npm run check-msbuild && npm run rebuild-launcher && git add resources/bin/${appName}-launcher.exe`;
|
|
121
|
+
(0, fs_extra_1.ensureDirSync)(path.resolve(root, ".husky"));
|
|
122
|
+
(0, fileUtils_1.writeFile)(path.resolve(root, ".husky", "pre-commit"), (0, fileUtils_1.readResource)(huskyConfigFileLocation));
|
|
123
|
+
}
|
|
124
|
+
(0, createWindowlessAppUtils_1.mergeIntoPackageJson)(root, "scripts", scripts);
|
|
125
|
+
};
|
|
126
|
+
const buildJavaScriptProject = (root, appName, nodeVersion, husky) => {
|
|
127
|
+
console.log(`Building project ${chalk_1.default.green("files")}.`);
|
|
128
|
+
console.log();
|
|
129
|
+
(0, fileUtils_1.writeFile)(path.resolve(root, "webpack.config.js"), (0, createWindowlessAppUtils_1.replaceAppNamePlaceholder)((0, fileUtils_1.readResource)(jsWebpackConfigResourceLocation), appName));
|
|
130
|
+
(0, fs_extra_1.ensureDirSync)(path.resolve(root, "src"));
|
|
131
|
+
(0, fileUtils_1.writeFile)(path.resolve(root, "src", "index.js"), (0, createWindowlessAppUtils_1.replaceAppNamePlaceholder)((0, fileUtils_1.readResource)(jsIndexResourceLocation), appName));
|
|
132
|
+
// Add scripts
|
|
133
|
+
const scripts = {
|
|
134
|
+
"start": "node src/index.js",
|
|
135
|
+
"prewebpack": "rimraf build && rimraf dist",
|
|
136
|
+
"webpack": "webpack",
|
|
137
|
+
"nexe": (0, createWindowlessAppUtils_1.getNexeCommand)(appName, nodeVersion),
|
|
138
|
+
"build": "npm run webpack && npm run nexe",
|
|
139
|
+
"check-msbuild": "node -e \"require(\"\"./launcher/launcherCompiler\"\").checkMsbuildInPath(true)\"",
|
|
140
|
+
"rebuild-launcher": "msbuild launcher/launcher.csproj"
|
|
141
|
+
};
|
|
142
|
+
// Add husky
|
|
143
|
+
if (husky) {
|
|
144
|
+
scripts["prepare"] = "git config --get core.hookspath || husky install";
|
|
145
|
+
scripts["pre-commit"] = `git diff HEAD --exit-code --stat launcher/* || npm run check-msbuild && npm run rebuild-launcher && git add resources/bin/${appName}-launcher.exe`;
|
|
146
|
+
(0, fs_extra_1.ensureDirSync)(path.resolve(root, ".husky"));
|
|
147
|
+
(0, fileUtils_1.writeFile)(path.resolve(root, ".husky", "pre-commit"), (0, fileUtils_1.readResource)(huskyConfigFileLocation));
|
|
148
|
+
}
|
|
149
|
+
(0, createWindowlessAppUtils_1.mergeIntoPackageJson)(root, "scripts", scripts);
|
|
150
|
+
};
|
|
151
|
+
const buildLauncher = (root, appName, icon, typescript) => {
|
|
152
|
+
console.log(`Building project ${chalk_1.default.green("launcher")}.`);
|
|
153
|
+
console.log();
|
|
154
|
+
(0, fs_extra_1.ensureDirSync)(path.resolve("launcher"));
|
|
155
|
+
(0, fileUtils_1.writeFile)(path.resolve(launcherSrcModifiedLocation), (0, createWindowlessAppUtils_1.replaceAppNamePlaceholder)((0, fileUtils_1.readResource)(launcherSrcResourceLocation), appName));
|
|
156
|
+
(0, fileUtils_1.writeFile)(path.resolve(launcherProjModifiedLocation), (0, createWindowlessAppUtils_1.replaceAppNamePlaceholder)((0, fileUtils_1.readResource)(launcherProjResourceLocation), appName));
|
|
157
|
+
if (typescript) {
|
|
158
|
+
(0, fileUtils_1.copyFile)(path.resolve(__dirname, tsLauncherCompilerLocation), path.resolve(root, "launcher", "launcherCompiler.ts"));
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
(0, fileUtils_1.copyFile)(path.resolve(__dirname, jsLauncherCompilerLocation), path.resolve(root, "launcher", "launcherCompiler.js"));
|
|
162
|
+
}
|
|
163
|
+
// Resolve icon
|
|
164
|
+
let iconLocation;
|
|
165
|
+
if (icon) {
|
|
166
|
+
iconLocation = path.resolve(icon);
|
|
167
|
+
console.log(`Building launcher with icon: ${chalk_1.default.green(icon)}.`);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
iconLocation = path.resolve(__dirname, defaultLauncherIconLocation);
|
|
171
|
+
console.log(`Building launcher with ${chalk_1.default.green("default")} icon.`);
|
|
172
|
+
}
|
|
173
|
+
(0, fileUtils_1.copyFile)(iconLocation, path.resolve(root, "launcher", "launcher.ico"));
|
|
174
|
+
return (0, launcherCompiler_1.compileLauncher)();
|
|
175
|
+
};
|
|
176
|
+
exports.buildLauncher = buildLauncher;
|
|
177
|
+
const run = (root, appName, originalDirectory, programConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
178
|
+
const { typescript, husky, icon, nodeVersion } = programConfig;
|
|
179
|
+
const dependencies = [...consts_1.default.dependencies];
|
|
180
|
+
const devDependencies = [...consts_1.default.devDependencies];
|
|
181
|
+
if (typescript) {
|
|
182
|
+
devDependencies.push(...consts_1.default.tsDevDependencies);
|
|
183
|
+
}
|
|
184
|
+
if (husky) {
|
|
185
|
+
devDependencies.push(...consts_1.default.huskyDependencies);
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
yield install(root, dependencies, false, programConfig);
|
|
189
|
+
yield install(root, devDependencies, true, programConfig);
|
|
190
|
+
const checkedNodeVersion = yield (0, nodeUtils_1.checkNodeVersion)(nodeVersion);
|
|
191
|
+
if (typescript) {
|
|
192
|
+
buildTypeScriptProject(root, appName, checkedNodeVersion, husky);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
buildJavaScriptProject(root, appName, checkedNodeVersion, husky);
|
|
196
|
+
}
|
|
197
|
+
// Launcher
|
|
198
|
+
(0, fs_extra_1.ensureDirSync)(path.resolve(root, "resources", "bin"));
|
|
199
|
+
yield (0, exports.buildLauncher)(root, appName, icon, typescript);
|
|
200
|
+
console.log("Done");
|
|
201
|
+
}
|
|
202
|
+
catch (reason) {
|
|
203
|
+
console.log();
|
|
204
|
+
console.log("Aborting installation.");
|
|
205
|
+
if (reason.command) {
|
|
206
|
+
console.log(` ${chalk_1.default.cyan(reason.command)} has failed.`);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
console.log(chalk_1.default.red("Unexpected error. Please report it as a bug:"));
|
|
210
|
+
console.log(reason);
|
|
211
|
+
}
|
|
212
|
+
console.log();
|
|
213
|
+
// On 'exit' we will delete these files from target directory.
|
|
214
|
+
const knownGeneratedFiles = [...consts_1.default.knownGeneratedFiles];
|
|
215
|
+
const currentFiles = (0, fs_extra_1.readdirSync)(path.join(root));
|
|
216
|
+
currentFiles.forEach((file) => {
|
|
217
|
+
knownGeneratedFiles.forEach((fileToMatch) => {
|
|
218
|
+
// This removes all knownGeneratedFiles.
|
|
219
|
+
if (file === fileToMatch) {
|
|
220
|
+
console.log(`Deleting generated file... ${chalk_1.default.cyan(file)}`);
|
|
221
|
+
(0, fs_extra_1.removeSync)(path.join(root, file));
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
const remainingFiles = (0, fs_extra_1.readdirSync)(path.join(root));
|
|
226
|
+
if (!remainingFiles.length) {
|
|
227
|
+
// Delete target folder if empty
|
|
228
|
+
console.log(`Deleting ${chalk_1.default.cyan(`${appName}/`)} from ${chalk_1.default.cyan(path.resolve(root, ".."))}`);
|
|
229
|
+
process.chdir(path.resolve(root, ".."));
|
|
230
|
+
(0, fs_extra_1.removeSync)(path.join(root));
|
|
231
|
+
}
|
|
232
|
+
console.log("Done (with errors).");
|
|
233
|
+
process.exit(1);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
const createApp = (programConfig) => {
|
|
237
|
+
const { projectName } = programConfig;
|
|
238
|
+
const root = path.resolve(projectName);
|
|
239
|
+
const appName = path.basename(root);
|
|
240
|
+
(0, createWindowlessAppUtils_1.checkAppName)(appName);
|
|
241
|
+
(0, fs_extra_1.ensureDirSync)(projectName);
|
|
242
|
+
if (!(0, createWindowlessAppUtils_1.isSafeToCreateProjectIn)(root, projectName)) {
|
|
243
|
+
process.exit(1);
|
|
244
|
+
}
|
|
245
|
+
console.log(`Creating a new windowless app in ${chalk_1.default.green(root)}.`);
|
|
246
|
+
console.log();
|
|
247
|
+
const packageJson = {
|
|
248
|
+
name: appName,
|
|
249
|
+
version: "0.1.0",
|
|
250
|
+
private: true,
|
|
251
|
+
main: "_build/index.js"
|
|
252
|
+
};
|
|
253
|
+
(0, fileUtils_1.writeJson)(path.join(root, "package.json"), packageJson);
|
|
254
|
+
const originalDirectory = process.cwd();
|
|
255
|
+
process.chdir(root);
|
|
256
|
+
if (!(0, nodeUtils_1.checkThatNpmCanReadCwd)()) {
|
|
257
|
+
process.exit(1);
|
|
258
|
+
}
|
|
259
|
+
return run(root, appName, originalDirectory, programConfig);
|
|
260
|
+
};
|
|
261
|
+
const createWindowlessApp = (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
262
|
+
const programConfig = yield (0, cliParser_1.parseCommand)(argv);
|
|
263
|
+
if (programConfig.projectName) {
|
|
264
|
+
return createApp(programConfig);
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
exports.createWindowlessApp = createWindowlessApp;
|