UNPKG

4.38 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4/* eslint-disable no-console */
5/* eslint-disable import/prefer-default-export */
6var fs_extra_1 = require("fs-extra");
7var chalk_1 = tslib_1.__importDefault(require("chalk"));
8var path_1 = require("path");
9var ts_lib_scripts_utils_1 = require("ts-lib-scripts-utils");
10var paths_1 = require("../config/paths");
11var genDoczFiles_1 = tslib_1.__importDefault(require("./genDoczFiles"));
12var updateREADMEFile_1 = tslib_1.__importDefault(require("./fns/updateREADMEFile"));
13var updateLicense_1 = tslib_1.__importDefault(require("./fns/updateLicense"));
14/**
15 * 生成package.json文件
16 *
17 * @param projectPath 项目路径
18 * @param options 配置
19 */
20function 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 /*yield*/, 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 /*yield*/, fs_extra_1.outputJSON(packagePath, packageInfo, {
37 spaces: 2,
38 })];
39 case 2:
40 _a.sent();
41 return [2 /*return*/];
42 }
43 });
44 });
45}
46exports.genPackageFile = genPackageFile;
47/**
48 * 生成项目
49 *
50 * @param options 配置
51 */
52function 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 /*yield*/, 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 /*yield*/, fs_extra_1.copy(paths_1.COMMON_TEMPLATE_PATH, projectPath)];
67 case 2:
68 _a.sent();
69 return [4 /*yield*/, 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 /*yield*/, fs_extra_1.copy(paths_1.GIT_IGNORE_FILE_PATH, path_1.resolve(projectPath, '.gitignore'))];
73 case 4:
74 _a.sent();
75 return [4 /*yield*/, genPackageFile(projectPath, options)];
76 case 5:
77 _a.sent();
78 return [4 /*yield*/, updateREADMEFile_1.default(projectPath, options)];
79 case 6:
80 _a.sent();
81 return [4 /*yield*/, updateLicense_1.default(projectPath, options)];
82 case 7:
83 _a.sent();
84 if (!options.docz) return [3 /*break*/, 9];
85 return [4 /*yield*/, genDoczFiles_1.default(projectPath, options)];
86 case 8:
87 _a.sent();
88 _a.label = 9;
89 case 9: return [2 /*return*/];
90 }
91 });
92 });
93}
94exports.genProject = genProject;
95//# sourceMappingURL=genProject.js.map
\No newline at end of file