1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 |
|
5 |
|
6 | var fs_extra_1 = require("fs-extra");
|
7 | var chalk_1 = tslib_1.__importDefault(require("chalk"));
|
8 | var path_1 = require("path");
|
9 | var ts_lib_scripts_utils_1 = require("ts-lib-scripts-utils");
|
10 | var paths_1 = require("../config/paths");
|
11 | var genDoczFiles_1 = tslib_1.__importDefault(require("./genDoczFiles"));
|
12 | var updateREADMEFile_1 = tslib_1.__importDefault(require("./fns/updateREADMEFile"));
|
13 | var updateLicense_1 = tslib_1.__importDefault(require("./fns/updateLicense"));
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | function genPackageFile(projectPath, options) {
|
21 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
22 | var packagePath, packageInfo;
|
23 | return tslib_1.__generator(this, function (_a) {
|
24 | switch (_a.label) {
|
25 | case 0:
|
26 | packagePath = path_1.resolve(projectPath, 'package.json');
|
27 | return [4 , fs_extra_1.readJSON(packagePath)];
|
28 | case 1:
|
29 | packageInfo = _a.sent();
|
30 | packageInfo.version = options.packageVersion;
|
31 | packageInfo.name = options.packageName;
|
32 | packageInfo.description = options.packageDescription;
|
33 | packageInfo.files = ['dist', 'assets'];
|
34 | packageInfo['umd:main'] = "dist/" + ts_lib_scripts_utils_1.safePackageName(options.packageName) + ".umd.production.js";
|
35 | packageInfo.module = "dist/" + ts_lib_scripts_utils_1.safePackageName(options.packageName) + ".esm.js";
|
36 | return [4 , fs_extra_1.outputJSON(packagePath, packageInfo, {
|
37 | spaces: 2,
|
38 | })];
|
39 | case 2:
|
40 | _a.sent();
|
41 | return [2 ];
|
42 | }
|
43 | });
|
44 | });
|
45 | }
|
46 | exports.genPackageFile = genPackageFile;
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | function genProject(options) {
|
53 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
54 | var projectPath, exists;
|
55 | return tslib_1.__generator(this, function (_a) {
|
56 | switch (_a.label) {
|
57 | case 0:
|
58 | projectPath = paths_1.resolveRoot(options.projectName);
|
59 | return [4 , fs_extra_1.pathExists(projectPath)];
|
60 | case 1:
|
61 | exists = _a.sent();
|
62 | if (exists) {
|
63 | console.error(chalk_1.default.red("\u5DF2\u7ECF\u5B58\u5728" + options.projectName + "\u6587\u4EF6\u5939\uFF0C\u8BF7\u9009\u62E9\u4E00\u4E2A\u65B0\u7684\u9879\u76EE\u540D\u79F0\u3002"));
|
64 | process.exit(1);
|
65 | }
|
66 | return [4 , fs_extra_1.copy(paths_1.COMMON_TEMPLATE_PATH, projectPath)];
|
67 | case 2:
|
68 | _a.sent();
|
69 | return [4 , fs_extra_1.copy(options.react ? paths_1.REACT_TEMPLATE_PATH : paths_1.TEMPLATE_PATH, projectPath)];
|
70 | case 3:
|
71 | _a.sent();
|
72 | return [4 , fs_extra_1.copy(paths_1.GIT_IGNORE_FILE_PATH, path_1.resolve(projectPath, '.gitignore'))];
|
73 | case 4:
|
74 | _a.sent();
|
75 | return [4 , genPackageFile(projectPath, options)];
|
76 | case 5:
|
77 | _a.sent();
|
78 | return [4 , updateREADMEFile_1.default(projectPath, options)];
|
79 | case 6:
|
80 | _a.sent();
|
81 | return [4 , updateLicense_1.default(projectPath, options)];
|
82 | case 7:
|
83 | _a.sent();
|
84 | if (!options.docz) return [3 , 9];
|
85 | return [4 , genDoczFiles_1.default(projectPath, options)];
|
86 | case 8:
|
87 | _a.sent();
|
88 | _a.label = 9;
|
89 | case 9: return [2 ];
|
90 | }
|
91 | });
|
92 | });
|
93 | }
|
94 | exports.genProject = genProject;
|
95 |
|
\ | No newline at end of file |