swico 0.1.0

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.
Files changed (56) hide show
  1. package/package.json +90 -0
  2. package/src/bin.d.ts +2 -0
  3. package/src/bin.js +46 -0
  4. package/src/command/build.d.ts +1 -0
  5. package/src/command/build.js +91 -0
  6. package/src/command/start.d.ts +1 -0
  7. package/src/command/start.js +166 -0
  8. package/src/config/webpack.base.react.d.ts +82 -0
  9. package/src/config/webpack.base.react.js +286 -0
  10. package/src/config/webpack.base.vue.d.ts +106 -0
  11. package/src/config/webpack.base.vue.js +303 -0
  12. package/src/config/webpack.dev.d.ts +2 -0
  13. package/src/config/webpack.dev.js +140 -0
  14. package/src/config/webpack.prod.d.ts +2 -0
  15. package/src/config/webpack.prod.js +183 -0
  16. package/src/index.d.ts +15 -0
  17. package/src/index.js +10 -0
  18. package/src/index.react.d.ts +19 -0
  19. package/src/index.react.js +19 -0
  20. package/src/index.vue.d.ts +34 -0
  21. package/src/index.vue.js +29 -0
  22. package/src/task.d.ts +1 -0
  23. package/src/task.js +61 -0
  24. package/src/template/global.d.ts +3 -0
  25. package/src/template/global.js +3 -0
  26. package/src/template/hooks/react.d.ts +12 -0
  27. package/src/template/hooks/react.js +45 -0
  28. package/src/template/hooks/vue.d.ts +2 -0
  29. package/src/template/hooks/vue.js +34 -0
  30. package/src/template/layout/Layout.d.ts +2 -0
  31. package/src/template/layout/Layout.js +6 -0
  32. package/src/template/layout/index.d.ts +4 -0
  33. package/src/template/layout/index.js +6 -0
  34. package/src/template/react/config.d.ts +3 -0
  35. package/src/template/react/config.js +5 -0
  36. package/src/template/react/history.d.ts +11 -0
  37. package/src/template/react/history.js +109 -0
  38. package/src/template/react/index.d.ts +11 -0
  39. package/src/template/react/index.js +63 -0
  40. package/src/template/react/loading.d.ts +2 -0
  41. package/src/template/react/loading.js +3 -0
  42. package/src/template/react/routes.d.ts +3 -0
  43. package/src/template/react/routes.js +3 -0
  44. package/src/template/vue/Container.d.ts +2 -0
  45. package/src/template/vue/Container.js +4 -0
  46. package/src/template/vue/Container.vue +7 -0
  47. package/src/template/vue/config.d.ts +3 -0
  48. package/src/template/vue/config.js +5 -0
  49. package/src/template/vue/index.d.ts +1 -0
  50. package/src/template/vue/index.js +46 -0
  51. package/src/template/vue/routes.d.ts +6 -0
  52. package/src/template/vue/routes.js +3 -0
  53. package/src/utils/config.d.ts +47 -0
  54. package/src/utils/config.js +394 -0
  55. package/src/utils/tools.d.ts +7 -0
  56. package/src/utils/tools.js +141 -0
@@ -0,0 +1,47 @@
1
+ export type ConfigRoutesItemType = {
2
+ component?: string;
3
+ children?: ConfigRoutesItemType[];
4
+ path: string;
5
+ redirect?: string;
6
+ name?: string;
7
+ decorator?: string;
8
+ [key: string]: any;
9
+ };
10
+ export type ConfigRouterType = {
11
+ type?: 'browser' | 'hash';
12
+ base?: string;
13
+ routes?: ConfigRoutesItemType[];
14
+ };
15
+ export interface GlobalSecywoConfigType {
16
+ template: 'react' | 'vue';
17
+ npmType?: 'npm' | 'pnpm';
18
+ plugins?: any[];
19
+ publicPath?: string;
20
+ console?: boolean;
21
+ define?: Record<string, any>;
22
+ alias?: Record<string, any>;
23
+ proxy?: Record<string, any>;
24
+ https?: boolean;
25
+ copy?: Array<string | {
26
+ from: string;
27
+ to: string;
28
+ }>;
29
+ devtool?: string;
30
+ externals?: any;
31
+ router?: ConfigRouterType;
32
+ }
33
+ export interface GlobalData {
34
+ templateType?: GlobalSecywoConfigType['template'];
35
+ projectPath: string;
36
+ entryPath: string;
37
+ templatePath: string;
38
+ env?: 'dev' | 'prod';
39
+ customConfig: {
40
+ base: Pick<GlobalSecywoConfigType, 'plugins' | 'publicPath' | 'alias' | 'define' | 'devtool' | 'externals' | 'npmType' | 'router' | 'template'>;
41
+ dev: Pick<GlobalSecywoConfigType, 'plugins' | 'proxy' | 'https' | 'devtool' | 'router'>;
42
+ prod: Pick<GlobalSecywoConfigType, 'plugins' | 'console' | 'copy' | 'devtool' | 'router'>;
43
+ };
44
+ }
45
+ export declare const getProjectConfig: (env?: GlobalData['env']) => Promise<GlobalData>;
46
+ export declare const getFormatDefineVars: (defineVarsConfigData: any) => Promise<{}>;
47
+ export declare const initConfig: Omit<GlobalSecywoConfigType, 'template'>;
@@ -0,0 +1,394 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
+ return new (P || (P = Promise))(function (resolve, reject) {
39
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
43
+ });
44
+ };
45
+ var __generator = (this && this.__generator) || function (thisArg, body) {
46
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
47
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
48
+ function verb(n) { return function (v) { return step([n, v]); }; }
49
+ function step(op) {
50
+ if (f) throw new TypeError("Generator is already executing.");
51
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
52
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
53
+ if (y = 0, t) op = [op[0] & 2, t.value];
54
+ switch (op[0]) {
55
+ case 0: case 1: t = op; break;
56
+ case 4: _.label++; return { value: op[1], done: false };
57
+ case 5: _.label++; y = op[1]; op = [0]; continue;
58
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
59
+ default:
60
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
61
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
62
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
63
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
64
+ if (t[2]) _.ops.pop();
65
+ _.trys.pop(); continue;
66
+ }
67
+ op = body.call(thisArg, _);
68
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
69
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
+ }
71
+ };
72
+ var __importDefault = (this && this.__importDefault) || function (mod) {
73
+ return (mod && mod.__esModule) ? mod : { "default": mod };
74
+ };
75
+ Object.defineProperty(exports, "__esModule", { value: true });
76
+ exports.initConfig = exports.getFormatDefineVars = exports.getProjectConfig = void 0;
77
+ var fs_extra_1 = __importDefault(require("fs-extra"));
78
+ var path_1 = __importDefault(require("path"));
79
+ var chalk_1 = __importDefault(require("chalk"));
80
+ var tools_1 = require("./tools");
81
+ var projectPath = process.cwd();
82
+ var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0, function () {
83
+ var configDir, configPath, customConfig, _loop_1, _i, _a, key, templateType, routerConfig, entryPath, templatePath;
84
+ var _b, _c, _d, _e, _f;
85
+ return __generator(this, function (_g) {
86
+ switch (_g.label) {
87
+ case 0:
88
+ configDir = path_1.default.join(projectPath, '/config');
89
+ configPath = {
90
+ dev: path_1.default.join(configDir, '/secywo.dev.ts'),
91
+ prod: path_1.default.join(configDir, '/secywo.prod.ts'),
92
+ base: path_1.default.join(configDir, '/secywo.ts')
93
+ };
94
+ customConfig = {};
95
+ _loop_1 = function (key) {
96
+ var curConfigFilePath, exists, configObj, configFields, supportedFieldList_1, configFileName, unSupportedField, msgText, _h, _j;
97
+ return __generator(this, function (_k) {
98
+ switch (_k.label) {
99
+ case 0:
100
+ curConfigFilePath = configPath[key];
101
+ exists = fs_extra_1.default.existsSync(curConfigFilePath);
102
+ if (!exists) return [3, 3];
103
+ return [4, Promise.resolve("".concat(curConfigFilePath)).then(function (s) { return __importStar(require(s)); })];
104
+ case 1:
105
+ configObj = (_k.sent()).default;
106
+ configFields = Object.keys(configObj);
107
+ configFileName = void 0;
108
+ switch (key) {
109
+ case 'base':
110
+ supportedFieldList_1 = [
111
+ 'plugins',
112
+ 'publicPath',
113
+ 'alias',
114
+ 'define',
115
+ 'devtool',
116
+ 'externals',
117
+ 'npmType',
118
+ 'router',
119
+ 'template'
120
+ ];
121
+ configFileName = 'secywo.ts';
122
+ break;
123
+ case 'dev':
124
+ supportedFieldList_1 = ['plugins', 'proxy', 'https', 'devtool', 'router'];
125
+ configFileName = 'secywo.dev.ts';
126
+ break;
127
+ case 'prod':
128
+ supportedFieldList_1 = ['plugins', 'console', 'copy', 'devtool', 'router'];
129
+ configFileName = 'secywo.prod.ts';
130
+ }
131
+ unSupportedField = configFields.find(function (field) { return !supportedFieldList_1.includes(field); });
132
+ if (configFields.length > 0 && unSupportedField) {
133
+ msgText = "\n The secywo configuration file '".concat(chalk_1.default.blue(configFileName), "' does not support the field '").concat(chalk_1.default.red(unSupportedField), "' ");
134
+ tools_1.toast.error(msgText);
135
+ process.exit();
136
+ }
137
+ if (key === 'base' && !['vue', 'react'].includes(configObj['template'])) {
138
+ tools_1.toast.error("The field '".concat(chalk_1.default.blue('template'), "' does not support the value '").concat(chalk_1.default.red(configObj['template']), "',the value can be 'vue' or 'react' "));
139
+ process.exit();
140
+ }
141
+ if (key === 'base' &&
142
+ !['npm', 'pnpm'].includes((_b = configObj['npmType']) !== null && _b !== void 0 ? _b : exports.initConfig.npmType)) {
143
+ tools_1.toast.error("The field '".concat(chalk_1.default.blue('npmType'), "' does not support the value '").concat(chalk_1.default.red(configObj['npmType']), "',the value can be 'npm' or 'pnpm' "));
144
+ process.exit();
145
+ }
146
+ if (!['hash', 'browser'].includes((_d = (_c = configObj['router']) === null || _c === void 0 ? void 0 : _c.type) !== null && _d !== void 0 ? _d : exports.initConfig.router.type)) {
147
+ tools_1.toast.error("The field '".concat(chalk_1.default.blue('router.type'), "' does not support the value '").concat(chalk_1.default.red(configObj['router'].type), "',the value can be 'browser' or 'hash' "));
148
+ process.exit();
149
+ }
150
+ _h = customConfig;
151
+ _j = key;
152
+ return [4, Promise.resolve("".concat(curConfigFilePath)).then(function (s) { return __importStar(require(s)); })];
153
+ case 2:
154
+ _h[_j] = (_k.sent()).default;
155
+ _k.label = 3;
156
+ case 3: return [2];
157
+ }
158
+ });
159
+ };
160
+ _i = 0, _a = Object.keys(configPath);
161
+ _g.label = 1;
162
+ case 1:
163
+ if (!(_i < _a.length)) return [3, 4];
164
+ key = _a[_i];
165
+ return [5, _loop_1(key)];
166
+ case 2:
167
+ _g.sent();
168
+ _g.label = 3;
169
+ case 3:
170
+ _i++;
171
+ return [3, 1];
172
+ case 4:
173
+ templateType = customConfig['base'].template;
174
+ routerConfig = (_f = (_e = customConfig[env].router) !== null && _e !== void 0 ? _e : customConfig['base'].router) !== null && _f !== void 0 ? _f : exports.initConfig.router;
175
+ return [4, initTemplateRouterConfig(routerConfig, templateType)];
176
+ case 5:
177
+ _g.sent();
178
+ return [4, handleCliIndexFile(templateType)];
179
+ case 6:
180
+ _g.sent();
181
+ entryPath = path_1.default.resolve(projectPath, './src/.secywo/index.js');
182
+ templatePath = path_1.default.join(projectPath, '/src/index.ejs');
183
+ return [2, {
184
+ projectPath: projectPath,
185
+ entryPath: entryPath,
186
+ templatePath: templatePath,
187
+ customConfig: customConfig,
188
+ templateType: templateType
189
+ }];
190
+ }
191
+ });
192
+ }); };
193
+ exports.getProjectConfig = getProjectConfig;
194
+ var getFormatRouter = function (routes, templateType) {
195
+ var _main = function (item) {
196
+ var path = item.path, component = item.component, name = item.name, children = item.children, redirect = item.redirect, decorator = item.decorator;
197
+ return decorator
198
+ ? __assign(__assign({}, item), { component: "()=>import('".concat(projectPath, "/src/pages/").concat(decorator).concat(templateType === 'vue' ? '.vue' : '', "')"), children: [
199
+ {
200
+ path: '',
201
+ component: component
202
+ ? "()=>import('".concat(projectPath, "/src/pages/").concat(component).concat(templateType === 'vue' ? '.vue' : '', "')")
203
+ : undefined,
204
+ name: name,
205
+ redirect: redirect,
206
+ children: children ? children === null || children === void 0 ? void 0 : children.map(function (item) { return _main(item); }) : undefined
207
+ }
208
+ ] }) : {
209
+ path: path,
210
+ component: component
211
+ ? "()=>import('".concat(projectPath, "/src/pages/").concat(component).concat(templateType === 'vue' ? '.vue' : '', "')")
212
+ : undefined,
213
+ name: name,
214
+ redirect: redirect,
215
+ children: children ? children === null || children === void 0 ? void 0 : children.map(function (item) { return _main(item); }) : undefined
216
+ };
217
+ };
218
+ return routes.map(function (item) {
219
+ return _main(item);
220
+ });
221
+ };
222
+ var handleCliIndexFile = function (templateType) { return __awaiter(void 0, void 0, void 0, function () {
223
+ var targetPath, targetTypesPath, replaceFileText, fileTypesText;
224
+ return __generator(this, function (_a) {
225
+ switch (_a.label) {
226
+ case 0:
227
+ targetPath = path_1.default.resolve(__dirname, '../index.js');
228
+ targetTypesPath = path_1.default.resolve(__dirname, '../index.d.ts');
229
+ replaceFileText = fs_extra_1.default.readFileSync(path_1.default.resolve(__dirname, "../index.".concat(templateType, ".js")), 'utf8');
230
+ fileTypesText = fs_extra_1.default.readFileSync(path_1.default.resolve(__dirname, "../index.".concat(templateType, ".d.ts")), 'utf8');
231
+ return [4, (0, tools_1.writeFile)(targetPath, replaceFileText)];
232
+ case 1:
233
+ _a.sent();
234
+ return [4, (0, tools_1.writeFile)(targetTypesPath, fileTypesText)];
235
+ case 2:
236
+ _a.sent();
237
+ return [2];
238
+ }
239
+ });
240
+ }); };
241
+ var formatTemplateFileText = function (_a, templateType) {
242
+ 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;
243
+ return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
244
+ var formatRouter, textData, modifiedText, indexFilePath, configFilePath, indexText, configText, replaceIndexText, replaceConfigText;
245
+ return __generator(this, function (_a) {
246
+ switch (_a.label) {
247
+ case 0:
248
+ formatRouter = getFormatRouter(routes, templateType);
249
+ textData = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.default = ".concat(JSON.stringify(formatRouter), ";");
250
+ modifiedText = textData.replace(/"(\(\)=>import\('[^']+'\))"/g, '$1');
251
+ return [4, (0, tools_1.writeFile)(path_1.default.resolve(__dirname, "../template/".concat(templateType, "/routes.js")), modifiedText)];
252
+ case 1:
253
+ _a.sent();
254
+ indexFilePath = path_1.default.resolve(__dirname, "../template/".concat(templateType, "/index.js"));
255
+ configFilePath = path_1.default.resolve(__dirname, "../template/".concat(templateType, "/config.js"));
256
+ indexText = fs_extra_1.default.readFileSync(indexFilePath, 'utf8');
257
+ configText = fs_extra_1.default.readFileSync(configFilePath, 'utf8');
258
+ replaceIndexText = indexText;
259
+ replaceConfigText = configText;
260
+ if (base) {
261
+ replaceConfigText = replaceConfigText.replace(/exports\.routerBase\s*=\s*(.*)/gm, function (match, p1) {
262
+ return "exports.routerBase = '".concat(base, "';");
263
+ });
264
+ }
265
+ if (type) {
266
+ replaceConfigText = replaceConfigText.replace(/exports\.routerType\s*=\s*(.*)/gm, function (match, p1) {
267
+ return "exports.routerType = '".concat(type, "';");
268
+ });
269
+ }
270
+ return [4, (0, tools_1.writeFile)(indexFilePath, replaceIndexText)];
271
+ case 2:
272
+ _a.sent();
273
+ return [4, (0, tools_1.writeFile)(configFilePath, replaceConfigText)];
274
+ case 3:
275
+ _a.sent();
276
+ resolve(null);
277
+ return [2];
278
+ }
279
+ });
280
+ }); });
281
+ };
282
+ var initTemplateRouterConfig = function (routerConfig, templateType) {
283
+ return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
284
+ var copyTargetPath, replaceIndexText, e_1, e_2, e_3;
285
+ return __generator(this, function (_a) {
286
+ switch (_a.label) {
287
+ case 0: return [4, formatTemplateFileText(routerConfig, templateType)];
288
+ case 1:
289
+ _a.sent();
290
+ copyTargetPath = path_1.default.resolve(projectPath, './src/.secywo');
291
+ if (!fs_extra_1.default.existsSync(copyTargetPath)) return [3, 3];
292
+ return [4, fs_extra_1.default.remove(copyTargetPath)];
293
+ case 2:
294
+ _a.sent();
295
+ _a.label = 3;
296
+ case 3: return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType)), copyTargetPath, function (fileName) {
297
+ return !fileName.endsWith('.d.ts') &&
298
+ (templateType === 'vue' ? fileName !== 'Container.js' : true);
299
+ })];
300
+ case 4:
301
+ _a.sent();
302
+ replaceIndexText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, './src/.secywo/index.js'), 'utf8');
303
+ _a.label = 5;
304
+ case 5:
305
+ _a.trys.push([5, 7, , 8]);
306
+ return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.ts'), fs_extra_1.default.constants.F_OK)];
307
+ case 6:
308
+ _a.sent();
309
+ replaceIndexText = replaceIndexText.replaceAll('require("../global");', '');
310
+ replaceIndexText = 'require("../global");\n' + replaceIndexText;
311
+ return [3, 8];
312
+ case 7:
313
+ e_1 = _a.sent();
314
+ replaceIndexText = replaceIndexText.replaceAll('require("../global");', '');
315
+ return [3, 8];
316
+ case 8:
317
+ _a.trys.push([8, 10, , 11]);
318
+ return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.less'), fs_extra_1.default.constants.F_OK)];
319
+ case 9:
320
+ _a.sent();
321
+ replaceIndexText = replaceIndexText.replaceAll('require("../global.less");', '');
322
+ replaceIndexText = 'require("../global.less");\n' + replaceIndexText;
323
+ return [3, 11];
324
+ case 10:
325
+ e_2 = _a.sent();
326
+ replaceIndexText = replaceIndexText.replaceAll('require("../global.less");', '');
327
+ return [3, 11];
328
+ case 11:
329
+ if (!(templateType === 'vue')) return [3, 13];
330
+ replaceIndexText = replaceIndexText.replace('"./Container"', '"./Container.vue"');
331
+ return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.secywo/index.js'), replaceIndexText)];
332
+ case 12:
333
+ _a.sent();
334
+ _a.label = 13;
335
+ case 13:
336
+ if (!(templateType === 'react')) return [3, 19];
337
+ _a.label = 14;
338
+ case 14:
339
+ _a.trys.push([14, 16, 17, 19]);
340
+ return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/loading/index.tsx'), fs_extra_1.default.constants.F_OK)];
341
+ case 15:
342
+ _a.sent();
343
+ replaceIndexText = replaceIndexText.replace('"./loading"', '"../loading"');
344
+ return [3, 19];
345
+ case 16:
346
+ e_3 = _a.sent();
347
+ replaceIndexText = replaceIndexText.replace('"../loading"', '"./loading"');
348
+ return [3, 19];
349
+ case 17: return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.secywo/index.js'), replaceIndexText)];
350
+ case 18:
351
+ _a.sent();
352
+ return [7];
353
+ case 19:
354
+ resolve(null);
355
+ return [2];
356
+ }
357
+ });
358
+ }); });
359
+ };
360
+ var getFormatDefineVars = function (defineVarsConfigData) { return __awaiter(void 0, void 0, void 0, function () {
361
+ var formatObj, obj, _i, _a, _b, key, value;
362
+ return __generator(this, function (_c) {
363
+ switch (_c.label) {
364
+ case 0:
365
+ formatObj = {};
366
+ obj = defineVarsConfigData;
367
+ if (!(typeof defineVarsConfigData === 'function')) return [3, 2];
368
+ return [4, Promise.resolve(defineVarsConfigData())];
369
+ case 1:
370
+ obj = _c.sent();
371
+ _c.label = 2;
372
+ case 2:
373
+ for (_i = 0, _a = Object.entries(obj); _i < _a.length; _i++) {
374
+ _b = _a[_i], key = _b[0], value = _b[1];
375
+ formatObj[key] = JSON.stringify(value);
376
+ }
377
+ return [2, formatObj];
378
+ }
379
+ });
380
+ }); };
381
+ exports.getFormatDefineVars = getFormatDefineVars;
382
+ exports.initConfig = {
383
+ npmType: 'npm',
384
+ console: true,
385
+ plugins: [],
386
+ publicPath: '/',
387
+ proxy: undefined,
388
+ copy: [],
389
+ router: {
390
+ base: '/',
391
+ type: 'browser',
392
+ routes: []
393
+ }
394
+ };
@@ -0,0 +1,7 @@
1
+ export declare const copyDirFiles: (src: any, dest: any, filter?: (fileName: any) => boolean) => Promise<any>;
2
+ export declare const getPort: () => Promise<number>;
3
+ export declare const toast: {
4
+ error: (message: string | string[]) => void;
5
+ warning: (message: string | string[]) => void;
6
+ };
7
+ export declare const writeFile: (sourcePath: any, text: any) => Promise<unknown>;
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.writeFile = exports.toast = exports.getPort = exports.copyDirFiles = void 0;
43
+ var portfinder_1 = __importDefault(require("portfinder"));
44
+ var fs_extra_1 = __importDefault(require("fs-extra"));
45
+ var path_1 = __importDefault(require("path"));
46
+ var chalk_1 = __importDefault(require("chalk"));
47
+ var copyDirFiles = function (src, dest, filter) { return __awaiter(void 0, void 0, void 0, function () {
48
+ var _copy, e_1;
49
+ return __generator(this, function (_a) {
50
+ switch (_a.label) {
51
+ case 0:
52
+ _copy = function (src, dest) { return __awaiter(void 0, void 0, void 0, function () {
53
+ var files;
54
+ return __generator(this, function (_a) {
55
+ switch (_a.label) {
56
+ case 0: return [4, fs_extra_1.default.readdir(src)];
57
+ case 1:
58
+ files = _a.sent();
59
+ files.forEach(function (file) {
60
+ var srcPath = path_1.default.join(src, file);
61
+ var destPath = path_1.default.join(dest, file);
62
+ var srcStat = fs_extra_1.default.statSync(srcPath);
63
+ if (srcStat.isDirectory()) {
64
+ _copy(srcPath, destPath);
65
+ }
66
+ else {
67
+ var isFilter = filter ? filter(file) === true : true;
68
+ if (isFilter) {
69
+ fs_extra_1.default.copyFileSync(srcPath, destPath);
70
+ }
71
+ }
72
+ });
73
+ return [2, null];
74
+ }
75
+ });
76
+ }); };
77
+ _a.label = 1;
78
+ case 1:
79
+ _a.trys.push([1, 3, , 4]);
80
+ return [4, fs_extra_1.default.access(dest)];
81
+ case 2:
82
+ _a.sent();
83
+ return [3, 4];
84
+ case 3:
85
+ e_1 = _a.sent();
86
+ fs_extra_1.default.mkdirSync(dest, { recursive: true });
87
+ return [3, 4];
88
+ case 4: return [4, _copy(src, dest)];
89
+ case 5:
90
+ _a.sent();
91
+ return [2, null];
92
+ }
93
+ });
94
+ }); };
95
+ exports.copyDirFiles = copyDirFiles;
96
+ var getPort = function () {
97
+ return portfinder_1.default.getPortPromise({
98
+ port: 3000,
99
+ stopPort: 3333
100
+ });
101
+ };
102
+ exports.getPort = getPort;
103
+ exports.toast = {
104
+ error: function (message) {
105
+ console.log("\n".concat(chalk_1.default.hex('#5f72f5')('There are some errors about secywo:'), " \n"));
106
+ if (Array.isArray(message)) {
107
+ message.forEach(function (item) {
108
+ console.log(" > ".concat(chalk_1.default.red.bold(item), " \n"));
109
+ });
110
+ }
111
+ else {
112
+ console.log(" > ".concat(chalk_1.default.red.bold(message), " \n"));
113
+ }
114
+ },
115
+ warning: function (message) {
116
+ console.log("\n".concat(chalk_1.default.hex('#5f72f5')('There are some warnings about secywo:'), " \n"));
117
+ if (Array.isArray(message)) {
118
+ message.forEach(function (item) {
119
+ console.log(" > ".concat(chalk_1.default.hex('#fb8918').bold(item), " \n"));
120
+ });
121
+ }
122
+ else {
123
+ console.log(" > ".concat(chalk_1.default.hex('#fb8918').bold(message), " \n"));
124
+ }
125
+ }
126
+ };
127
+ var writeFile = function (sourcePath, text) {
128
+ return new Promise(function (resolve, reject) {
129
+ fs_extra_1.default.writeFile(sourcePath, text, function (err) {
130
+ if (err) {
131
+ var errText = 'An error occurred during the secywo configuration.';
132
+ exports.toast.error(errText);
133
+ return reject(errText);
134
+ }
135
+ else {
136
+ return resolve(null);
137
+ }
138
+ });
139
+ });
140
+ };
141
+ exports.writeFile = writeFile;