UNPKG

2.93 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var fs_extra_1 = require("fs-extra");
5var path_1 = require("path");
6var paths_1 = require("../config/paths");
7var appendContentToFile_1 = tslib_1.__importDefault(require("./fns/appendContentToFile"));
8function getHomepage(options) {
9 if (options.packageName.startsWith('@')) {
10 var matches = options.packageName.match(/@([^/])\/(.+)/);
11 if (matches) {
12 var scopeName = matches[1], packageName = matches[2];
13 return "https://" + scopeName + ".github.io/" + packageName;
14 }
15 }
16 return undefined;
17}
18/**
19 * 生成docz文件
20 */
21function genDoczFiles(projectPath, options) {
22 return tslib_1.__awaiter(this, void 0, void 0, function () {
23 var content, packageInfo;
24 return tslib_1.__generator(this, function (_a) {
25 switch (_a.label) {
26 case 0:
27 // 拷贝docz文件
28 return [4 /*yield*/, fs_extra_1.copy(paths_1.DOCZ_TEMPLATE_PATH, projectPath)];
29 case 1:
30 // 拷贝docz文件
31 _a.sent();
32 return [4 /*yield*/, fs_extra_1.readFile(path_1.resolve(projectPath, './doczrc.js'), 'utf-8')];
33 case 2:
34 content = _a.sent();
35 return [4 /*yield*/, fs_extra_1.writeFile(path_1.resolve(projectPath, './doczrc.js'), content.replace("title: 'rctt',", "title: '" + options.projectName + "',"))];
36 case 3:
37 _a.sent();
38 return [4 /*yield*/, fs_extra_1.readJSON(path_1.resolve(projectPath, './package.json'))];
39 case 4:
40 packageInfo = _a.sent();
41 packageInfo.scripts['doc:dev'] = 'docz dev';
42 packageInfo.scripts['doc:build'] = 'docz build';
43 if (options.doczGithubPages) {
44 packageInfo.scripts['doc:publish'] = 'docz build && gh-pages -d .docz/dist';
45 packageInfo.homepage = getHomepage(options);
46 }
47 return [4 /*yield*/, fs_extra_1.outputJSON(path_1.resolve(projectPath, './package.json'), packageInfo, {
48 spaces: 2,
49 })];
50 case 5:
51 _a.sent();
52 // 添加doc指令说明
53 return [4 /*yield*/, appendContentToFile_1.default(path_1.resolve(projectPath, 'README.md'), '\n', fs_extra_1.createReadStream(paths_1.DOC_README_PATH))];
54 case 6:
55 // 添加doc指令说明
56 _a.sent();
57 return [2 /*return*/];
58 }
59 });
60 });
61}
62exports.default = genDoczFiles;
63//# sourceMappingURL=genDoczFiles.js.map
\No newline at end of file