swico 0.6.0-beta2 → 0.6.0-beta21
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/package.json +1 -1
- package/src/command/build.js +7 -4
- package/src/command/start.js +21 -18
- package/src/template/react/config.prod.d.ts +3 -0
- package/src/template/react/config.prod.js +5 -0
- package/src/template/react/history.js +2 -1
- package/src/template/react/routes.prod.d.ts +3 -0
- package/src/template/react/routes.prod.js +3 -0
- package/src/template/vue/config.prod.d.ts +3 -0
- package/src/template/vue/config.prod.js +5 -0
- package/src/template/vue/routes.prod.d.ts +6 -0
- package/src/template/vue/routes.prod.js +3 -0
- package/src/utils/config.d.ts +1 -1
- package/src/utils/config.js +88 -45
- package/src/utils/tools.d.ts +1 -0
- package/src/utils/tools.js +48 -4
package/package.json
CHANGED
package/src/command/build.js
CHANGED
|
@@ -54,9 +54,13 @@ function default_1() {
|
|
|
54
54
|
switch (_a.label) {
|
|
55
55
|
case 0:
|
|
56
56
|
process.env.SWICO_ENV = 'prod';
|
|
57
|
-
tools_1.toast.info("Swico
|
|
58
|
-
|
|
57
|
+
tools_1.toast.info("Swico v".concat(package_json_1.default.version));
|
|
58
|
+
spinner.succeed('Initializing Swico production config...\n');
|
|
59
|
+
return [4, (0, tools_1.initIndexFile)()];
|
|
59
60
|
case 1:
|
|
61
|
+
_a.sent();
|
|
62
|
+
return [4, (0, config_1.getProjectConfig)('prod')];
|
|
63
|
+
case 2:
|
|
60
64
|
projectConfig = _a.sent();
|
|
61
65
|
entryPath = projectConfig.entryPath, templatePath = projectConfig.templatePath, projectPath = projectConfig.projectPath, customConfig = projectConfig.customConfig, templateType = projectConfig.templateType;
|
|
62
66
|
return [4, (0, webpack_prod_1.default)({
|
|
@@ -66,10 +70,9 @@ function default_1() {
|
|
|
66
70
|
customConfig: customConfig,
|
|
67
71
|
templateType: templateType
|
|
68
72
|
})];
|
|
69
|
-
case
|
|
73
|
+
case 3:
|
|
70
74
|
buildConfig = _a.sent();
|
|
71
75
|
compiler = (0, webpack_1.default)(buildConfig);
|
|
72
|
-
console.log("".concat(chalk_1.default.hex('#5f72f5')('Starts building....'), " \n"));
|
|
73
76
|
compiler.run(function (err, stats) {
|
|
74
77
|
if (err) {
|
|
75
78
|
tools_1.toast.error(err.stack || err.toString());
|
package/src/command/start.js
CHANGED
|
@@ -131,40 +131,43 @@ function start() {
|
|
|
131
131
|
switch (_b.label) {
|
|
132
132
|
case 0:
|
|
133
133
|
process.env.SWICO_ENV = 'dev';
|
|
134
|
-
|
|
134
|
+
tools_1.toast.info("Swico v".concat(package_json_1.default.version));
|
|
135
|
+
spinner.succeed('Initializing Swico development config...\n');
|
|
136
|
+
return [4, (0, tools_1.initIndexFile)()];
|
|
137
|
+
case 1:
|
|
138
|
+
_b.sent();
|
|
139
|
+
if (!(envPort !== null && envPort !== void 0)) return [3, 2];
|
|
135
140
|
_a = envPort;
|
|
136
|
-
return [3,
|
|
137
|
-
case
|
|
138
|
-
case 2:
|
|
139
|
-
_a = (_b.sent());
|
|
140
|
-
_b.label = 3;
|
|
141
|
+
return [3, 4];
|
|
142
|
+
case 2: return [4, (0, tools_1.getPort)()];
|
|
141
143
|
case 3:
|
|
144
|
+
_a = (_b.sent());
|
|
145
|
+
_b.label = 4;
|
|
146
|
+
case 4:
|
|
142
147
|
availablePort = _a;
|
|
143
|
-
tools_1.toast.info("Swico V".concat(package_json_1.default.version));
|
|
144
|
-
tools_1.toast.info('Initializing Swico config...');
|
|
145
148
|
return [4, (0, config_1.getProjectConfig)('dev')];
|
|
146
|
-
case
|
|
149
|
+
case 5:
|
|
147
150
|
projectConfig = _b.sent();
|
|
148
151
|
projectPath = projectConfig.projectPath;
|
|
149
152
|
return [4, (0, webpack_dev_1.default)(projectConfig)];
|
|
150
|
-
case
|
|
153
|
+
case 6:
|
|
151
154
|
startConfig = _b.sent();
|
|
152
155
|
compiler = (0, webpack_1.default)(startConfig);
|
|
153
156
|
devServer = new webpack_dev_server_1.default(__assign(__assign({}, startConfig.devServer), { port: availablePort }), compiler);
|
|
154
|
-
_b.label =
|
|
155
|
-
case 6:
|
|
156
|
-
_b.trys.push([6, 8, , 9]);
|
|
157
|
-
return [4, devServer.start()];
|
|
157
|
+
_b.label = 7;
|
|
158
158
|
case 7:
|
|
159
|
+
_b.trys.push([7, 9, , 10]);
|
|
160
|
+
return [4, devServer.start()];
|
|
161
|
+
case 8:
|
|
159
162
|
_b.sent();
|
|
160
163
|
handleWatch(projectPath, devServer);
|
|
161
|
-
return [3,
|
|
162
|
-
case
|
|
164
|
+
return [3, 10];
|
|
165
|
+
case 9:
|
|
163
166
|
e_1 = _b.sent();
|
|
164
167
|
strErr = e_1.toString();
|
|
165
168
|
tools_1.toast.error(strErr);
|
|
166
|
-
return [3,
|
|
167
|
-
case
|
|
169
|
+
return [3, 10];
|
|
170
|
+
case 10: return [2];
|
|
168
171
|
}
|
|
169
172
|
});
|
|
170
173
|
});
|
|
@@ -31,13 +31,14 @@ var interpolatePath = function (pathTemplate, params) {
|
|
|
31
31
|
return interpolatedParts.join('/');
|
|
32
32
|
};
|
|
33
33
|
var interpolatePathParams = function (pathTemplate, path) {
|
|
34
|
+
var _a;
|
|
34
35
|
if (pathTemplate === void 0) { pathTemplate = ''; }
|
|
35
36
|
var regexPattern = pathTemplate.replace(/:(\w+)/g, '([^/]+)');
|
|
36
37
|
var regex = new RegExp("^".concat(regexPattern, "$"));
|
|
37
38
|
var match = path.match(regex);
|
|
38
39
|
if (match) {
|
|
39
40
|
var params_1 = match.slice(1);
|
|
40
|
-
var paramNames = pathTemplate.match(/:(\w+)/g).map(function (name) { return name.slice(1); });
|
|
41
|
+
var paramNames = ((_a = pathTemplate.match(/:(\w+)/g)) === null || _a === void 0 ? void 0 : _a.map(function (name) { return name.slice(1); })) || [];
|
|
41
42
|
var result_1 = {};
|
|
42
43
|
paramNames.forEach(function (name, index) {
|
|
43
44
|
result_1[name] = params_1[index];
|
package/src/utils/config.d.ts
CHANGED
|
@@ -42,6 +42,6 @@ export interface GlobalData {
|
|
|
42
42
|
prod: Pick<GlobalSwicoConfigType, 'plugins' | 'console' | 'copy' | 'devtool' | 'router'>;
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
export declare const getProjectConfig: (env
|
|
45
|
+
export declare const getProjectConfig: (env: GlobalData['env']) => Promise<GlobalData>;
|
|
46
46
|
export declare const getFormatDefineVars: (defineVarsConfigData: any) => Promise<{}>;
|
|
47
47
|
export declare const initConfig: Omit<GlobalSwicoConfigType, 'template'>;
|
package/src/utils/config.js
CHANGED
|
@@ -172,7 +172,7 @@ var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0,
|
|
|
172
172
|
case 4:
|
|
173
173
|
templateType = customConfig['base'].template;
|
|
174
174
|
routerConfig = __assign(__assign(__assign({}, exports.initConfig.router), customConfig['base'].router), customConfig[env].router);
|
|
175
|
-
return [4, initTemplateConfig(routerConfig, templateType)];
|
|
175
|
+
return [4, initTemplateConfig(routerConfig, templateType, env)];
|
|
176
176
|
case 5:
|
|
177
177
|
_e.sent();
|
|
178
178
|
return [4, initCliIndexFile(templateType)];
|
|
@@ -226,9 +226,7 @@ var initCliIndexFile = function (templateType) { return __awaiter(void 0, void 0
|
|
|
226
226
|
case 0:
|
|
227
227
|
targetPath = path_1.default.resolve(__dirname, '../index.js');
|
|
228
228
|
targetTypesPath = path_1.default.resolve(__dirname, '../index.d.ts');
|
|
229
|
-
|
|
230
|
-
case 1:
|
|
231
|
-
replaceFileText = _a.sent();
|
|
229
|
+
replaceFileText = fs_extra_1.default.readFileSync(path_1.default.resolve(__dirname, "../index.".concat(templateType, ".js")), 'utf8');
|
|
232
230
|
fileTypesText = fs_extra_1.default.readFileSync(path_1.default.resolve(__dirname, "../index.".concat(templateType, ".d.ts")), 'utf8');
|
|
233
231
|
if (templateType === 'react') {
|
|
234
232
|
formatHooksPath = path_1.default
|
|
@@ -237,17 +235,18 @@ var initCliIndexFile = function (templateType) { return __awaiter(void 0, void 0
|
|
|
237
235
|
replaceFileText = replaceFileText.replaceAll('require("./template/react/hooks");', "require(\"".concat(formatHooksPath, "\");"));
|
|
238
236
|
}
|
|
239
237
|
return [4, (0, tools_1.writeFile)(targetPath, replaceFileText)];
|
|
240
|
-
case
|
|
238
|
+
case 1:
|
|
241
239
|
_a.sent();
|
|
242
240
|
return [4, (0, tools_1.writeFile)(targetTypesPath, fileTypesText)];
|
|
243
|
-
case
|
|
241
|
+
case 2:
|
|
244
242
|
_a.sent();
|
|
245
243
|
return [2];
|
|
246
244
|
}
|
|
247
245
|
});
|
|
248
246
|
}); };
|
|
249
|
-
var formatRouterConfig = function (_a, templateType) {
|
|
247
|
+
var formatRouterConfig = function (_a, templateType, env) {
|
|
250
248
|
var _b = _a.routes, routes = _b === void 0 ? [] : _b, _c = _a.type, type = _c === void 0 ? 'browser' : _c, _d = _a.base, base = _d === void 0 ? '/' : _d;
|
|
249
|
+
var envPathSuffix = env === 'dev' ? '' : 'prod.';
|
|
251
250
|
return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
252
251
|
var formatRouter, textData, modifiedText, configFilePath, replaceConfigText;
|
|
253
252
|
return __generator(this, function (_a) {
|
|
@@ -256,10 +255,10 @@ var formatRouterConfig = function (_a, templateType) {
|
|
|
256
255
|
formatRouter = getFormatRouter(routes, templateType);
|
|
257
256
|
textData = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.default = ".concat(JSON.stringify(formatRouter), ";");
|
|
258
257
|
modifiedText = textData.replace(/"(\(\)=>import\('[^']+'\))"/g, '$1');
|
|
259
|
-
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath,
|
|
258
|
+
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, "./src/.swico/routes.".concat(envPathSuffix, "js")), modifiedText)];
|
|
260
259
|
case 1:
|
|
261
260
|
_a.sent();
|
|
262
|
-
configFilePath = path_1.default.resolve(projectPath,
|
|
261
|
+
configFilePath = path_1.default.resolve(projectPath, "./src/.swico/config.".concat(envPathSuffix, "js"));
|
|
263
262
|
replaceConfigText = fs_extra_1.default.readFileSync(configFilePath, 'utf8');
|
|
264
263
|
if (base) {
|
|
265
264
|
replaceConfigText = replaceConfigText.replace(/exports\.routerBase\s*=\s*(.*)/gm, function (match, p1) {
|
|
@@ -280,75 +279,119 @@ var formatRouterConfig = function (_a, templateType) {
|
|
|
280
279
|
});
|
|
281
280
|
}); });
|
|
282
281
|
};
|
|
283
|
-
var
|
|
282
|
+
var getCopyFileNameList = function (templateType, env) {
|
|
283
|
+
var list = ['hooks.js', 'index.js', 'history.js', 'loading.js'];
|
|
284
|
+
switch (true) {
|
|
285
|
+
case templateType === 'vue' && env === 'dev':
|
|
286
|
+
list.push('config.js', 'Container.vue', 'routes.js');
|
|
287
|
+
break;
|
|
288
|
+
case templateType === 'vue' && env === 'prod':
|
|
289
|
+
list.push('config.prod.js', 'Container.vue', 'routes.prod.js');
|
|
290
|
+
break;
|
|
291
|
+
case templateType === 'react' && env === 'dev':
|
|
292
|
+
list.push('config.js', 'history.js', 'routes.js');
|
|
293
|
+
break;
|
|
294
|
+
case templateType === 'react' && env === 'prod':
|
|
295
|
+
list.push('config.prod.js', 'history.js', 'routes.prod.js');
|
|
296
|
+
break;
|
|
297
|
+
default:
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
return list;
|
|
301
|
+
};
|
|
302
|
+
var initTemplateConfig = function (routerConfig, templateType, env) {
|
|
284
303
|
return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
285
|
-
var copyTargetPath, replaceIndexText, e_1, e_2, e_3;
|
|
304
|
+
var copyTargetPath, copyFileNameList, replaceIndexText, e_1, e_2, replaceHooksText, e_3, replaceHistoryText;
|
|
286
305
|
return __generator(this, function (_a) {
|
|
287
306
|
switch (_a.label) {
|
|
288
307
|
case 0:
|
|
308
|
+
console.log('0');
|
|
289
309
|
copyTargetPath = path_1.default.resolve(projectPath, './src/.swico');
|
|
290
|
-
|
|
291
|
-
return [4,
|
|
310
|
+
copyFileNameList = getCopyFileNameList(templateType, env);
|
|
311
|
+
return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType)), copyTargetPath, function (fileName) { return copyFileNameList.includes(fileName); })];
|
|
292
312
|
case 1:
|
|
293
313
|
_a.sent();
|
|
294
|
-
|
|
295
|
-
case 2:
|
|
296
|
-
return !fileName.endsWith('.d.ts') &&
|
|
297
|
-
(templateType === 'vue' ? fileName !== 'Container.js' : true);
|
|
298
|
-
})];
|
|
299
|
-
case 3:
|
|
300
|
-
_a.sent();
|
|
301
|
-
return [4, formatRouterConfig(routerConfig, templateType)];
|
|
302
|
-
case 4:
|
|
314
|
+
return [4, formatRouterConfig(routerConfig, templateType, env)];
|
|
315
|
+
case 2:
|
|
303
316
|
_a.sent();
|
|
304
317
|
replaceIndexText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, './src/.swico/index.js'), 'utf8');
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
318
|
+
if (env === 'prod') {
|
|
319
|
+
replaceIndexText = replaceIndexText.replaceAll('require("./config")', 'require("./config.prod")');
|
|
320
|
+
replaceIndexText = replaceIndexText.replaceAll('require("./routes")', 'require("./routes.prod")');
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
replaceIndexText = replaceIndexText.replaceAll('require("./config.prod")', 'require("./config")');
|
|
324
|
+
replaceIndexText = replaceIndexText.replaceAll('require("./routes.prod")', 'require("./routes")');
|
|
325
|
+
}
|
|
326
|
+
_a.label = 3;
|
|
327
|
+
case 3:
|
|
328
|
+
_a.trys.push([3, 5, , 6]);
|
|
308
329
|
return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.ts'), fs_extra_1.default.constants.F_OK)];
|
|
309
|
-
case
|
|
330
|
+
case 4:
|
|
310
331
|
_a.sent();
|
|
311
332
|
replaceIndexText = replaceIndexText.replaceAll('require("../global");', '');
|
|
312
333
|
replaceIndexText = 'require("../global");\n' + replaceIndexText;
|
|
313
|
-
return [3,
|
|
314
|
-
case
|
|
334
|
+
return [3, 6];
|
|
335
|
+
case 5:
|
|
315
336
|
e_1 = _a.sent();
|
|
316
337
|
replaceIndexText = replaceIndexText.replaceAll('require("../global");', '');
|
|
317
|
-
return [3,
|
|
318
|
-
case
|
|
319
|
-
_a.trys.push([
|
|
338
|
+
return [3, 6];
|
|
339
|
+
case 6:
|
|
340
|
+
_a.trys.push([6, 8, , 9]);
|
|
320
341
|
return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.less'), fs_extra_1.default.constants.F_OK)];
|
|
321
|
-
case
|
|
342
|
+
case 7:
|
|
322
343
|
_a.sent();
|
|
323
344
|
replaceIndexText = replaceIndexText.replaceAll('require("../global.less");', '');
|
|
324
345
|
replaceIndexText = 'require("../global.less");\n' + replaceIndexText;
|
|
325
|
-
return [3,
|
|
326
|
-
case
|
|
346
|
+
return [3, 9];
|
|
347
|
+
case 8:
|
|
327
348
|
e_2 = _a.sent();
|
|
328
349
|
replaceIndexText = replaceIndexText.replaceAll('require("../global.less");', '');
|
|
329
|
-
return [3,
|
|
330
|
-
case
|
|
331
|
-
if (!(templateType === 'vue')) return [3,
|
|
350
|
+
return [3, 9];
|
|
351
|
+
case 9:
|
|
352
|
+
if (!(templateType === 'vue')) return [3, 12];
|
|
332
353
|
replaceIndexText = replaceIndexText.replace('"./Container"', '"./Container.vue"');
|
|
333
354
|
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/index.js'), replaceIndexText)];
|
|
334
|
-
case
|
|
355
|
+
case 10:
|
|
356
|
+
_a.sent();
|
|
357
|
+
replaceHooksText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, './src/.swico/hooks.js'), 'utf8');
|
|
358
|
+
if (env === 'prod') {
|
|
359
|
+
replaceHooksText = replaceHooksText.replaceAll('require("./config")', 'require("./config.prod")');
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
replaceHooksText = replaceIndexText.replaceAll('require("./config.prod")', 'require("./config")');
|
|
363
|
+
}
|
|
364
|
+
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/hooks.js'), replaceHooksText)];
|
|
365
|
+
case 11:
|
|
335
366
|
_a.sent();
|
|
367
|
+
return [3, 19];
|
|
368
|
+
case 12:
|
|
369
|
+
if (!(templateType === 'react')) return [3, 19];
|
|
336
370
|
_a.label = 13;
|
|
337
371
|
case 13:
|
|
338
|
-
|
|
339
|
-
_a.label = 14;
|
|
340
|
-
case 14:
|
|
341
|
-
_a.trys.push([14, 16, 17, 19]);
|
|
372
|
+
_a.trys.push([13, 15, 16, 19]);
|
|
342
373
|
return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/loading/index.tsx'), fs_extra_1.default.constants.F_OK)];
|
|
343
|
-
case
|
|
374
|
+
case 14:
|
|
344
375
|
_a.sent();
|
|
345
376
|
replaceIndexText = replaceIndexText.replace('"./loading"', '"../loading"');
|
|
346
377
|
return [3, 19];
|
|
347
|
-
case
|
|
378
|
+
case 15:
|
|
348
379
|
e_3 = _a.sent();
|
|
349
380
|
replaceIndexText = replaceIndexText.replace('"../loading"', '"./loading"');
|
|
350
381
|
return [3, 19];
|
|
351
|
-
case
|
|
382
|
+
case 16: return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/index.js'), replaceIndexText)];
|
|
383
|
+
case 17:
|
|
384
|
+
_a.sent();
|
|
385
|
+
replaceHistoryText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, './src/.swico/history.js'), 'utf8');
|
|
386
|
+
if (env === 'prod') {
|
|
387
|
+
replaceHistoryText = replaceHistoryText.replaceAll('require("./config")', 'require("./config.prod")');
|
|
388
|
+
replaceHistoryText = replaceHistoryText.replaceAll('require("./routes")', 'require("./routes.prod")');
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
replaceHistoryText = replaceHistoryText.replaceAll('require("./config.prod")', 'require("./config")');
|
|
392
|
+
replaceHistoryText = replaceHistoryText.replaceAll('require("./routes.prod")', 'require("./routes")');
|
|
393
|
+
}
|
|
394
|
+
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/history.js'), replaceHistoryText)];
|
|
352
395
|
case 18:
|
|
353
396
|
_a.sent();
|
|
354
397
|
return [7];
|
package/src/utils/tools.d.ts
CHANGED
package/src/utils/tools.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
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
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -39,11 +62,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
62
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
63
|
};
|
|
41
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.writeFile = exports.toast = exports.getPort = exports.copyDirFiles = void 0;
|
|
65
|
+
exports.initIndexFile = exports.writeFile = exports.toast = exports.getPort = exports.copyDirFiles = void 0;
|
|
43
66
|
var portfinder_1 = __importDefault(require("portfinder"));
|
|
44
67
|
var fs_extra_1 = __importDefault(require("fs-extra"));
|
|
45
68
|
var path_1 = __importDefault(require("path"));
|
|
46
69
|
var chalk_1 = __importDefault(require("chalk"));
|
|
70
|
+
var process = __importStar(require("process"));
|
|
47
71
|
var copyDirFiles = function (src, dest, filter) { return __awaiter(void 0, void 0, void 0, function () {
|
|
48
72
|
var _copy, e_1;
|
|
49
73
|
return __generator(this, function (_a) {
|
|
@@ -102,10 +126,10 @@ var getPort = function () {
|
|
|
102
126
|
exports.getPort = getPort;
|
|
103
127
|
exports.toast = {
|
|
104
128
|
info: function (message) {
|
|
105
|
-
console.log("\n".concat(chalk_1.default.hex('#5f72f5')(message), "\n"));
|
|
129
|
+
console.log("\n> ".concat(chalk_1.default.hex('#5f72f5')(message), "\n"));
|
|
106
130
|
},
|
|
107
131
|
error: function (message) {
|
|
108
|
-
console.log("\n".concat(chalk_1.default.hex('#5f72f5')('There are some errors about Swico:'), " \n"));
|
|
132
|
+
console.log("\n> ".concat(chalk_1.default.hex('#5f72f5')('There are some errors about Swico:'), " \n"));
|
|
109
133
|
if (Array.isArray(message)) {
|
|
110
134
|
message.forEach(function (item) {
|
|
111
135
|
console.log(" > ".concat(chalk_1.default.red.bold(item), " \n"));
|
|
@@ -116,7 +140,7 @@ exports.toast = {
|
|
|
116
140
|
}
|
|
117
141
|
},
|
|
118
142
|
warning: function (message) {
|
|
119
|
-
console.log("\n".concat(chalk_1.default.hex('#5f72f5')('There are some warnings about Swico:'), " \n"));
|
|
143
|
+
console.log("\n> ".concat(chalk_1.default.hex('#5f72f5')('There are some warnings about Swico:'), " \n"));
|
|
120
144
|
if (Array.isArray(message)) {
|
|
121
145
|
message.forEach(function (item) {
|
|
122
146
|
console.log(" > ".concat(chalk_1.default.hex('#fb8918').bold(item), " \n"));
|
|
@@ -142,3 +166,23 @@ var writeFile = function (sourcePath, text) {
|
|
|
142
166
|
});
|
|
143
167
|
};
|
|
144
168
|
exports.writeFile = writeFile;
|
|
169
|
+
var initIndexFile = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
170
|
+
var fileText, targetPath, formatHooksPath;
|
|
171
|
+
return __generator(this, function (_a) {
|
|
172
|
+
switch (_a.label) {
|
|
173
|
+
case 0:
|
|
174
|
+
fileText = fs_extra_1.default.readFileSync(path_1.default.resolve(__dirname, '../index.js'), 'utf8');
|
|
175
|
+
console.log('fileText', fileText);
|
|
176
|
+
targetPath = path_1.default.resolve(__dirname, '../index.js');
|
|
177
|
+
formatHooksPath = path_1.default
|
|
178
|
+
.resolve(process.cwd(), './src/.swico/hooks')
|
|
179
|
+
.replaceAll('\\', '/');
|
|
180
|
+
fileText = fileText.replaceAll("require(\"".concat(formatHooksPath, "\");"), 'require("./template/react/hooks");');
|
|
181
|
+
return [4, (0, exports.writeFile)(targetPath, fileText)];
|
|
182
|
+
case 1:
|
|
183
|
+
_a.sent();
|
|
184
|
+
return [2];
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}); };
|
|
188
|
+
exports.initIndexFile = initIndexFile;
|