1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 |
|
5 | var fs_extra_1 = require("fs-extra");
|
6 | var chalk_1 = tslib_1.__importDefault(require("chalk"));
|
7 | var path_1 = require("path");
|
8 | var paths_1 = require("../config/paths");
|
9 | var updateREADMEFile_1 = tslib_1.__importDefault(require("./fns/updateREADMEFile"));
|
10 | var updateLicense_1 = tslib_1.__importDefault(require("./fns/updateLicense"));
|
11 | var genDoczFiles_1 = tslib_1.__importDefault(require("./genDoczFiles"));
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | function updatePackageInfo(projectPath, options) {
|
19 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
20 | var packagePath, packageInfo;
|
21 | return tslib_1.__generator(this, function (_a) {
|
22 | switch (_a.label) {
|
23 | case 0:
|
24 | packagePath = path_1.resolve(projectPath, 'package.json');
|
25 | return [4 , fs_extra_1.readJSON(packagePath)];
|
26 | case 1:
|
27 | packageInfo = _a.sent();
|
28 | packageInfo.version = options.packageVersion;
|
29 | packageInfo.name = options.packageName;
|
30 | packageInfo.description = options.packageDescription;
|
31 | return [4 , fs_extra_1.outputJSON(packagePath, packageInfo, {
|
32 | spaces: 2,
|
33 | })];
|
34 | case 2:
|
35 | _a.sent();
|
36 | return [2 ];
|
37 | }
|
38 | });
|
39 | });
|
40 | }
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | function updateProjectConfig(projectPath, options) {
|
48 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
49 | var configPath, projectConfig;
|
50 | return tslib_1.__generator(this, function (_a) {
|
51 | switch (_a.label) {
|
52 | case 0:
|
53 | configPath = path_1.resolve(projectPath, 'ts-lib.config.json');
|
54 | return [4 , fs_extra_1.readJSON(configPath)];
|
55 | case 1:
|
56 | projectConfig = _a.sent();
|
57 | projectConfig.npmScope = options.npmScope || options.packageName;
|
58 | return [4 , fs_extra_1.outputJSON(configPath, projectConfig, {
|
59 | spaces: 2,
|
60 | })];
|
61 | case 2:
|
62 | _a.sent();
|
63 | return [2 ];
|
64 | }
|
65 | });
|
66 | });
|
67 | }
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | function updateTsConfig(projectPath, options) {
|
75 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
76 | var tsconfigPath, tsconfig;
|
77 | var _a;
|
78 | return tslib_1.__generator(this, function (_b) {
|
79 | switch (_b.label) {
|
80 | case 0:
|
81 | tsconfigPath = path_1.resolve(projectPath, 'tsconfig.json');
|
82 | return [4 , fs_extra_1.readJSON(tsconfigPath)];
|
83 | case 1:
|
84 | tsconfig = _b.sent();
|
85 | tsconfig.compilerOptions.paths = (_a = {},
|
86 | _a["@" + (options.npmScope || options.packageName) + "/*"] = ['packages/*/src'],
|
87 | _a);
|
88 | return [4 , fs_extra_1.outputJSON(tsconfigPath, tsconfig, {
|
89 | spaces: 2,
|
90 | })];
|
91 | case 2:
|
92 | _b.sent();
|
93 | return [2 ];
|
94 | }
|
95 | });
|
96 | });
|
97 | }
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 | function genMonorepoProject(options) {
|
104 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
105 | var projectPath, exists;
|
106 | return tslib_1.__generator(this, function (_a) {
|
107 | switch (_a.label) {
|
108 | case 0:
|
109 | projectPath = paths_1.resolveRoot(options.projectName);
|
110 | return [4 , fs_extra_1.pathExists(projectPath)];
|
111 | case 1:
|
112 | exists = _a.sent();
|
113 | if (exists) {
|
114 | 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"));
|
115 | process.exit(1);
|
116 | }
|
117 | return [4 , fs_extra_1.copy(paths_1.COMMON_TEMPLATE_PATH, projectPath)];
|
118 | case 2:
|
119 | _a.sent();
|
120 | return [4 , fs_extra_1.copy(paths_1.MONOREPO_TEMPLATE_PATH, projectPath)];
|
121 | case 3:
|
122 | _a.sent();
|
123 | return [4 , fs_extra_1.copy(paths_1.GIT_IGNORE_FILE_PATH, path_1.resolve(projectPath, '.gitignore'))];
|
124 | case 4:
|
125 | _a.sent();
|
126 | return [4 , updatePackageInfo(projectPath, options)];
|
127 | case 5:
|
128 | _a.sent();
|
129 | return [4 , updateProjectConfig(projectPath, options)];
|
130 | case 6:
|
131 | _a.sent();
|
132 | return [4 , updateREADMEFile_1.default(projectPath, options)];
|
133 | case 7:
|
134 | _a.sent();
|
135 | return [4 , updateLicense_1.default(projectPath, options)];
|
136 | case 8:
|
137 | _a.sent();
|
138 | return [4 , updateTsConfig(projectPath, options)];
|
139 | case 9:
|
140 | _a.sent();
|
141 | return [4 , fs_extra_1.remove(path_1.resolve(projectPath, 'src'))];
|
142 | case 10:
|
143 | _a.sent();
|
144 | if (!options.docz) return [3 , 13];
|
145 | return [4 , genDoczFiles_1.default(projectPath, options)];
|
146 | case 11:
|
147 | _a.sent();
|
148 | return [4 , fs_extra_1.remove(path_1.resolve(projectPath, 'docs/Counter.mdx'))];
|
149 | case 12:
|
150 | _a.sent();
|
151 | _a.label = 13;
|
152 | case 13: return [2 ];
|
153 | }
|
154 | });
|
155 | });
|
156 | }
|
157 | exports.default = genMonorepoProject;
|
158 |
|
\ | No newline at end of file |