swico 0.6.0 → 0.6.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/package.json +1 -1
- package/src/command/start.js +6 -6
- package/src/config/webpack.prod.js +4 -2
- package/src/utils/config.js +56 -44
- package/src/utils/tools.d.ts +1 -2
- package/src/utils/tools.js +76 -50
package/package.json
CHANGED
package/src/command/start.js
CHANGED
|
@@ -58,10 +58,8 @@ var config_1 = require("../utils/config");
|
|
|
58
58
|
var chokidar_1 = __importDefault(require("chokidar"));
|
|
59
59
|
var path_1 = __importDefault(require("path"));
|
|
60
60
|
var cross_spawn_1 = __importDefault(require("cross-spawn"));
|
|
61
|
-
var
|
|
61
|
+
var _a = process.env, envPort = _a.PORT, RESTART = _a.RESTART;
|
|
62
62
|
var package_json_1 = __importDefault(require("../../package.json"));
|
|
63
|
-
var ora_1 = __importDefault(require("ora"));
|
|
64
|
-
var spinner = (0, ora_1.default)();
|
|
65
63
|
var handleWatch = function (projectPath, devServer) {
|
|
66
64
|
var configFilesWatcher = chokidar_1.default
|
|
67
65
|
.watch([
|
|
@@ -116,7 +114,7 @@ var handleWatch = function (projectPath, devServer) {
|
|
|
116
114
|
};
|
|
117
115
|
var availablePort;
|
|
118
116
|
var restartServer = function () {
|
|
119
|
-
var result = cross_spawn_1.default.sync('cross-env', ["PORT=".concat(availablePort), 'swico', 'start'], {
|
|
117
|
+
var result = cross_spawn_1.default.sync('cross-env', ["PORT=".concat(availablePort), 'RESTART=true', 'swico', 'start'], {
|
|
120
118
|
stdio: 'inherit'
|
|
121
119
|
});
|
|
122
120
|
if (result.error) {
|
|
@@ -131,8 +129,10 @@ function start() {
|
|
|
131
129
|
switch (_b.label) {
|
|
132
130
|
case 0:
|
|
133
131
|
process.env.SWICO_ENV = 'dev';
|
|
134
|
-
|
|
135
|
-
|
|
132
|
+
if (RESTART !== 'true') {
|
|
133
|
+
tools_1.toast.info("Swico v".concat(package_json_1.default.version));
|
|
134
|
+
tools_1.toast.info('Initializing Swico development config...');
|
|
135
|
+
}
|
|
136
136
|
return [4, (0, tools_1.initIndexFile)()];
|
|
137
137
|
case 1:
|
|
138
138
|
_b.sent();
|
|
@@ -85,7 +85,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
85
85
|
var webpack_bundle_analyzer_1 = __importDefault(require("webpack-bundle-analyzer"));
|
|
86
86
|
var copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
|
|
87
87
|
var path_1 = __importDefault(require("path"));
|
|
88
|
-
var
|
|
88
|
+
var fs_extra_1 = __importDefault(require("fs-extra"));
|
|
89
89
|
var config_1 = require("../utils/config");
|
|
90
90
|
var webpack_merge_1 = require("webpack-merge");
|
|
91
91
|
var esbuild_loader_1 = require("esbuild-loader");
|
|
@@ -106,7 +106,9 @@ function default_1(options) {
|
|
|
106
106
|
case 2:
|
|
107
107
|
baseConfig = _h.sent();
|
|
108
108
|
consoleAvailable = (_b = (_a = customConfig.prod) === null || _a === void 0 ? void 0 : _a.console) !== null && _b !== void 0 ? _b : config_1.initConfig.console;
|
|
109
|
-
|
|
109
|
+
return [4, fs_extra_1.default.exists(path_1.default.join(projectPath, '/public'))];
|
|
110
|
+
case 3:
|
|
111
|
+
isPublicDirExist = _h.sent();
|
|
110
112
|
copyConfig = (_d = (_c = customConfig.prod) === null || _c === void 0 ? void 0 : _c.copy) !== null && _d !== void 0 ? _d : config_1.initConfig.copy;
|
|
111
113
|
customDevtool = (_e = customConfig.prod.devtool) !== null && _e !== void 0 ? _e : customConfig.base.devtool;
|
|
112
114
|
return [2, (0, webpack_merge_1.merge)(baseConfig, {
|
package/src/utils/config.js
CHANGED
|
@@ -98,10 +98,12 @@ var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0,
|
|
|
98
98
|
switch (_h.label) {
|
|
99
99
|
case 0:
|
|
100
100
|
curConfigFilePath = configPath[key];
|
|
101
|
-
|
|
102
|
-
if (!exists) return [3, 3];
|
|
103
|
-
return [4, Promise.resolve("".concat(curConfigFilePath)).then(function (s) { return __importStar(require(s)); })];
|
|
101
|
+
return [4, fs_extra_1.default.exists(curConfigFilePath)];
|
|
104
102
|
case 1:
|
|
103
|
+
exists = _h.sent();
|
|
104
|
+
if (!exists) return [3, 4];
|
|
105
|
+
return [4, Promise.resolve("".concat(curConfigFilePath)).then(function (s) { return __importStar(require(s)); })];
|
|
106
|
+
case 2:
|
|
105
107
|
configObj = (_h.sent()).default;
|
|
106
108
|
configFields = Object.keys(configObj);
|
|
107
109
|
configFileName = void 0;
|
|
@@ -150,10 +152,10 @@ var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0,
|
|
|
150
152
|
_f = customConfig;
|
|
151
153
|
_g = key;
|
|
152
154
|
return [4, Promise.resolve("".concat(curConfigFilePath)).then(function (s) { return __importStar(require(s)); })];
|
|
153
|
-
case
|
|
155
|
+
case 3:
|
|
154
156
|
_f[_g] = (_h.sent()).default;
|
|
155
|
-
_h.label =
|
|
156
|
-
case
|
|
157
|
+
_h.label = 4;
|
|
158
|
+
case 4: return [2];
|
|
157
159
|
}
|
|
158
160
|
});
|
|
159
161
|
};
|
|
@@ -227,19 +229,23 @@ var initCliIndexFile = function (templateType) { return __awaiter(void 0, void 0
|
|
|
227
229
|
case 0:
|
|
228
230
|
targetPath = path_1.default.resolve(__dirname, '../index.js');
|
|
229
231
|
targetTypesPath = path_1.default.resolve(__dirname, '../index.d.ts');
|
|
230
|
-
|
|
231
|
-
|
|
232
|
+
return [4, fs_extra_1.default.readFile(path_1.default.resolve(__dirname, "../index.".concat(templateType, ".js")), 'utf8')];
|
|
233
|
+
case 1:
|
|
234
|
+
replaceFileText = _a.sent();
|
|
235
|
+
return [4, fs_extra_1.default.readFile(path_1.default.resolve(__dirname, "../index.".concat(templateType, ".d.ts")), 'utf8')];
|
|
236
|
+
case 2:
|
|
237
|
+
fileTypesText = _a.sent();
|
|
232
238
|
if (templateType === 'react') {
|
|
233
239
|
formatHooksPath = path_1.default
|
|
234
240
|
.resolve(projectPath, './src/.swico/react-hooks')
|
|
235
241
|
.replaceAll('\\', '/');
|
|
236
242
|
replaceFileText = replaceFileText.replaceAll('require("./template/react/react-hooks");', "require(\"".concat(formatHooksPath, "\");"));
|
|
237
243
|
}
|
|
238
|
-
return [4,
|
|
239
|
-
case
|
|
244
|
+
return [4, fs_extra_1.default.writeFile(targetPath, replaceFileText)];
|
|
245
|
+
case 3:
|
|
240
246
|
_a.sent();
|
|
241
|
-
return [4,
|
|
242
|
-
case
|
|
247
|
+
return [4, fs_extra_1.default.writeFile(targetTypesPath, fileTypesText)];
|
|
248
|
+
case 4:
|
|
243
249
|
_a.sent();
|
|
244
250
|
return [2];
|
|
245
251
|
}
|
|
@@ -256,11 +262,13 @@ var formatRouterConfig = function (_a, templateType, env) {
|
|
|
256
262
|
formatRouter = getFormatRouter(routes, templateType);
|
|
257
263
|
textData = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.default = ".concat(JSON.stringify(formatRouter), ";");
|
|
258
264
|
modifiedText = textData.replace(/"(\(\)=>import\('[^']+'\))"/g, '$1');
|
|
259
|
-
return [4,
|
|
265
|
+
return [4, fs_extra_1.default.writeFile(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "routes.js")), modifiedText)];
|
|
260
266
|
case 1:
|
|
261
267
|
_a.sent();
|
|
262
268
|
configFilePath = path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "config.js"));
|
|
263
|
-
|
|
269
|
+
return [4, fs_extra_1.default.readFile(configFilePath, 'utf8')];
|
|
270
|
+
case 2:
|
|
271
|
+
replaceConfigText = _a.sent();
|
|
264
272
|
if (base) {
|
|
265
273
|
replaceConfigText = replaceConfigText.replace(/exports\.routerBase\s*=\s*(.*)/gm, function (match, p1) {
|
|
266
274
|
return "exports.routerBase = '".concat(templateType === 'react' && type === 'hash' ? '/' : base, "';");
|
|
@@ -271,8 +279,8 @@ var formatRouterConfig = function (_a, templateType, env) {
|
|
|
271
279
|
return "exports.routerType = '".concat(type, "';");
|
|
272
280
|
});
|
|
273
281
|
}
|
|
274
|
-
return [4,
|
|
275
|
-
case
|
|
282
|
+
return [4, fs_extra_1.default.writeFile(configFilePath, replaceConfigText)];
|
|
283
|
+
case 3:
|
|
276
284
|
_a.sent();
|
|
277
285
|
resolve(null);
|
|
278
286
|
return [2];
|
|
@@ -304,52 +312,56 @@ var initTemplateConfig = function (routerConfig, templateType, env) {
|
|
|
304
312
|
return [4, formatRouterConfig(routerConfig, templateType, env)];
|
|
305
313
|
case 3:
|
|
306
314
|
_a.sent();
|
|
307
|
-
|
|
315
|
+
return [4, fs_extra_1.default.readFile(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), 'utf8')];
|
|
316
|
+
case 4:
|
|
317
|
+
replaceIndexText = _a.sent();
|
|
308
318
|
hooksFilePath = path_1.default.resolve(projectPath, "./src/.swico/".concat(templateType, "-hooks.js"));
|
|
309
|
-
|
|
319
|
+
return [4, fs_extra_1.default.readFile(hooksFilePath, 'utf8')];
|
|
320
|
+
case 5:
|
|
321
|
+
replaceHooksText = _a.sent();
|
|
310
322
|
replaceHooksText = replaceHooksText.replaceAll('$env', ".".concat(env));
|
|
311
|
-
return [4,
|
|
312
|
-
case
|
|
323
|
+
return [4, fs_extra_1.default.writeFile(hooksFilePath, replaceHooksText)];
|
|
324
|
+
case 6:
|
|
313
325
|
_a.sent();
|
|
314
|
-
_a.label =
|
|
315
|
-
case
|
|
316
|
-
_a.trys.push([
|
|
326
|
+
_a.label = 7;
|
|
327
|
+
case 7:
|
|
328
|
+
_a.trys.push([7, 9, , 10]);
|
|
317
329
|
return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.less'), fs_extra_1.default.constants.F_OK)];
|
|
318
|
-
case
|
|
330
|
+
case 8:
|
|
319
331
|
_a.sent();
|
|
320
332
|
replaceIndexText = replaceIndexText.replaceAll('require("../../global.less");', '');
|
|
321
333
|
replaceIndexText = 'require("../../global.less");\n' + replaceIndexText;
|
|
322
|
-
return [3,
|
|
323
|
-
case
|
|
334
|
+
return [3, 10];
|
|
335
|
+
case 9:
|
|
324
336
|
e_1 = _a.sent();
|
|
325
337
|
replaceIndexText = replaceIndexText.replaceAll('require("../../global.less");', '');
|
|
326
|
-
return [3,
|
|
327
|
-
case 8:
|
|
328
|
-
if (!(templateType === 'vue')) return [3, 10];
|
|
329
|
-
replaceIndexText = replaceIndexText.replace('"../Container"', '"../Container.vue"');
|
|
330
|
-
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), replaceIndexText)];
|
|
331
|
-
case 9:
|
|
332
|
-
_a.sent();
|
|
333
|
-
return [3, 16];
|
|
338
|
+
return [3, 10];
|
|
334
339
|
case 10:
|
|
335
|
-
if (!(templateType === '
|
|
336
|
-
|
|
340
|
+
if (!(templateType === 'vue')) return [3, 12];
|
|
341
|
+
replaceIndexText = replaceIndexText.replace('"../Container"', '"../Container.vue"');
|
|
342
|
+
return [4, fs_extra_1.default.writeFile(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), replaceIndexText)];
|
|
337
343
|
case 11:
|
|
338
|
-
_a.
|
|
339
|
-
return [
|
|
344
|
+
_a.sent();
|
|
345
|
+
return [3, 18];
|
|
340
346
|
case 12:
|
|
347
|
+
if (!(templateType === 'react')) return [3, 18];
|
|
348
|
+
_a.label = 13;
|
|
349
|
+
case 13:
|
|
350
|
+
_a.trys.push([13, 15, 16, 18]);
|
|
351
|
+
return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/loading/index.tsx'), fs_extra_1.default.constants.F_OK)];
|
|
352
|
+
case 14:
|
|
341
353
|
_a.sent();
|
|
342
354
|
replaceIndexText = replaceIndexText.replace('"../loading"', '"../../loading"');
|
|
343
|
-
return [3,
|
|
344
|
-
case
|
|
355
|
+
return [3, 18];
|
|
356
|
+
case 15:
|
|
345
357
|
e_2 = _a.sent();
|
|
346
358
|
replaceIndexText = replaceIndexText.replace('"../../loading"', '"../loading"');
|
|
347
|
-
return [3,
|
|
348
|
-
case
|
|
349
|
-
case
|
|
359
|
+
return [3, 18];
|
|
360
|
+
case 16: return [4, fs_extra_1.default.writeFile(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), replaceIndexText)];
|
|
361
|
+
case 17:
|
|
350
362
|
_a.sent();
|
|
351
363
|
return [7];
|
|
352
|
-
case
|
|
364
|
+
case 18:
|
|
353
365
|
resolve(null);
|
|
354
366
|
return [2];
|
|
355
367
|
}
|
package/src/utils/tools.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
export declare const copyDirFiles: (src: any, dest: any, filter?: (fileName: any) => boolean) => Promise<
|
|
1
|
+
export declare const copyDirFiles: (src: any, dest: any, filter?: (fileName: any) => boolean) => Promise<void>;
|
|
2
2
|
export declare const getPort: () => Promise<number>;
|
|
3
3
|
export declare const toast: {
|
|
4
4
|
info: (message: string) => void;
|
|
5
5
|
error: (message: string | string[]) => void;
|
|
6
6
|
warning: (message: string | string[]) => void;
|
|
7
7
|
};
|
|
8
|
-
export declare const writeFile: (sourcePath: any, text: any) => Promise<unknown>;
|
|
9
8
|
export declare const initIndexFile: () => Promise<void>;
|
package/src/utils/tools.js
CHANGED
|
@@ -58,11 +58,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
58
58
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
62
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
63
|
+
var m = o[Symbol.asyncIterator], i;
|
|
64
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
65
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
66
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
67
|
+
};
|
|
61
68
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62
69
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
70
|
};
|
|
64
71
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
-
exports.initIndexFile = exports.
|
|
72
|
+
exports.initIndexFile = exports.toast = exports.getPort = exports.copyDirFiles = void 0;
|
|
66
73
|
var portfinder_1 = __importDefault(require("portfinder"));
|
|
67
74
|
var fs_extra_1 = __importDefault(require("fs-extra"));
|
|
68
75
|
var path_1 = __importDefault(require("path"));
|
|
@@ -74,45 +81,78 @@ var copyDirFiles = function (src, dest, filter) { return __awaiter(void 0, void
|
|
|
74
81
|
switch (_a.label) {
|
|
75
82
|
case 0:
|
|
76
83
|
_copy = function (src, dest) { return __awaiter(void 0, void 0, void 0, function () {
|
|
77
|
-
var files;
|
|
78
|
-
|
|
79
|
-
|
|
84
|
+
var files, filterFiles, _a, filterFiles_1, filterFiles_1_1, file, srcPath, destPath, srcStat, e_2_1;
|
|
85
|
+
var _b, e_2, _c, _d;
|
|
86
|
+
return __generator(this, function (_e) {
|
|
87
|
+
switch (_e.label) {
|
|
80
88
|
case 0: return [4, fs_extra_1.default.readdir(src)];
|
|
81
89
|
case 1:
|
|
82
|
-
files =
|
|
83
|
-
files.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return [
|
|
90
|
+
files = _e.sent();
|
|
91
|
+
filterFiles = files.filter(function (fileName) { return (filter ? filter(fileName) === true : true); });
|
|
92
|
+
_e.label = 2;
|
|
93
|
+
case 2:
|
|
94
|
+
_e.trys.push([2, 10, 11, 16]);
|
|
95
|
+
_a = true, filterFiles_1 = __asyncValues(filterFiles);
|
|
96
|
+
_e.label = 3;
|
|
97
|
+
case 3: return [4, filterFiles_1.next()];
|
|
98
|
+
case 4:
|
|
99
|
+
if (!(filterFiles_1_1 = _e.sent(), _b = filterFiles_1_1.done, !_b)) return [3, 9];
|
|
100
|
+
_d = filterFiles_1_1.value;
|
|
101
|
+
_a = false;
|
|
102
|
+
file = _d;
|
|
103
|
+
srcPath = path_1.default.join(src, file);
|
|
104
|
+
destPath = path_1.default.join(dest, file);
|
|
105
|
+
return [4, fs_extra_1.default.stat(srcPath)];
|
|
106
|
+
case 5:
|
|
107
|
+
srcStat = _e.sent();
|
|
108
|
+
if (!srcStat.isDirectory()) return [3, 6];
|
|
109
|
+
_copy(srcPath, destPath);
|
|
110
|
+
return [3, 8];
|
|
111
|
+
case 6: return [4, fs_extra_1.default.copyFile(srcPath, destPath)];
|
|
112
|
+
case 7:
|
|
113
|
+
_e.sent();
|
|
114
|
+
_e.label = 8;
|
|
115
|
+
case 8:
|
|
116
|
+
_a = true;
|
|
117
|
+
return [3, 3];
|
|
118
|
+
case 9: return [3, 16];
|
|
119
|
+
case 10:
|
|
120
|
+
e_2_1 = _e.sent();
|
|
121
|
+
e_2 = { error: e_2_1 };
|
|
122
|
+
return [3, 16];
|
|
123
|
+
case 11:
|
|
124
|
+
_e.trys.push([11, , 14, 15]);
|
|
125
|
+
if (!(!_a && !_b && (_c = filterFiles_1.return))) return [3, 13];
|
|
126
|
+
return [4, _c.call(filterFiles_1)];
|
|
127
|
+
case 12:
|
|
128
|
+
_e.sent();
|
|
129
|
+
_e.label = 13;
|
|
130
|
+
case 13: return [3, 15];
|
|
131
|
+
case 14:
|
|
132
|
+
if (e_2) throw e_2.error;
|
|
133
|
+
return [7];
|
|
134
|
+
case 15: return [7];
|
|
135
|
+
case 16: return [2, null];
|
|
98
136
|
}
|
|
99
137
|
});
|
|
100
138
|
}); };
|
|
101
139
|
_a.label = 1;
|
|
102
140
|
case 1:
|
|
103
|
-
_a.trys.push([1, 3, ,
|
|
141
|
+
_a.trys.push([1, 3, , 5]);
|
|
104
142
|
return [4, fs_extra_1.default.access(dest)];
|
|
105
143
|
case 2:
|
|
106
144
|
_a.sent();
|
|
107
|
-
return [3,
|
|
145
|
+
return [3, 5];
|
|
108
146
|
case 3:
|
|
109
147
|
e_1 = _a.sent();
|
|
110
|
-
fs_extra_1.default.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
148
|
+
return [4, fs_extra_1.default.mkdir(dest, { recursive: true })];
|
|
149
|
+
case 4:
|
|
150
|
+
_a.sent();
|
|
151
|
+
return [3, 5];
|
|
152
|
+
case 5: return [4, _copy(src, dest)];
|
|
153
|
+
case 6:
|
|
114
154
|
_a.sent();
|
|
115
|
-
return [2
|
|
155
|
+
return [2];
|
|
116
156
|
}
|
|
117
157
|
});
|
|
118
158
|
}); };
|
|
@@ -126,7 +166,7 @@ var getPort = function () {
|
|
|
126
166
|
exports.getPort = getPort;
|
|
127
167
|
exports.toast = {
|
|
128
168
|
info: function (message) {
|
|
129
|
-
console.log("
|
|
169
|
+
console.log("> ".concat(chalk_1.default.hex('#5f72f5')(message), "\n"));
|
|
130
170
|
},
|
|
131
171
|
error: function (message) {
|
|
132
172
|
console.log("\n> ".concat(chalk_1.default.hex('#5f72f5')('There are some errors about Swico:'), " \n"));
|
|
@@ -151,38 +191,24 @@ exports.toast = {
|
|
|
151
191
|
}
|
|
152
192
|
}
|
|
153
193
|
};
|
|
154
|
-
var writeFile = function (sourcePath, text) {
|
|
155
|
-
return new Promise(function (resolve, reject) {
|
|
156
|
-
fs_extra_1.default.writeFile(sourcePath, text, function (err) {
|
|
157
|
-
if (err) {
|
|
158
|
-
var errText = 'An error occurred during the Swico configuration.';
|
|
159
|
-
exports.toast.error(errText);
|
|
160
|
-
return reject(errText);
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
return resolve(null);
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
};
|
|
168
|
-
exports.writeFile = writeFile;
|
|
169
194
|
var initIndexFile = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
170
195
|
var fileText, targetPath, formatHooksPath;
|
|
171
196
|
return __generator(this, function (_a) {
|
|
172
197
|
switch (_a.label) {
|
|
173
|
-
case 0:
|
|
174
|
-
|
|
198
|
+
case 0: return [4, fs_extra_1.default.readFile(path_1.default.resolve(__dirname, '../index.js'), 'utf8')];
|
|
199
|
+
case 1:
|
|
200
|
+
fileText = _a.sent();
|
|
175
201
|
targetPath = path_1.default.resolve(__dirname, '../index.js');
|
|
176
202
|
formatHooksPath = path_1.default
|
|
177
203
|
.resolve(process.cwd(), './src/.swico/react-hooks')
|
|
178
204
|
.replaceAll('\\', '/');
|
|
179
|
-
if (!fileText.includes("require(\"".concat(formatHooksPath, "\");"))) return [3,
|
|
205
|
+
if (!fileText.includes("require(\"".concat(formatHooksPath, "\");"))) return [3, 3];
|
|
180
206
|
fileText = fileText.replaceAll("require(\"".concat(formatHooksPath, "\");"), 'require("./template/react/react-hooks");');
|
|
181
|
-
return [4,
|
|
182
|
-
case
|
|
207
|
+
return [4, fs_extra_1.default.writeFile(targetPath, fileText)];
|
|
208
|
+
case 2:
|
|
183
209
|
_a.sent();
|
|
184
|
-
_a.label =
|
|
185
|
-
case
|
|
210
|
+
_a.label = 3;
|
|
211
|
+
case 3: return [2];
|
|
186
212
|
}
|
|
187
213
|
});
|
|
188
214
|
}); };
|