1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var fs_extra_1 = require("fs-extra");
|
5 | var path_1 = require("path");
|
6 | var paths_1 = require("../config/paths");
|
7 | var appendContentToFile_1 = tslib_1.__importDefault(require("./fns/appendContentToFile"));
|
8 | function 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 |
|
20 |
|
21 | function 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 |
|
28 | return [4 , fs_extra_1.copy(paths_1.DOCZ_TEMPLATE_PATH, projectPath)];
|
29 | case 1:
|
30 |
|
31 | _a.sent();
|
32 | return [4 , fs_extra_1.readFile(path_1.resolve(projectPath, './doczrc.js'), 'utf-8')];
|
33 | case 2:
|
34 | content = _a.sent();
|
35 | return [4 , 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 , 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 , fs_extra_1.outputJSON(path_1.resolve(projectPath, './package.json'), packageInfo, {
|
48 | spaces: 2,
|
49 | })];
|
50 | case 5:
|
51 | _a.sent();
|
52 |
|
53 | return [4 , appendContentToFile_1.default(path_1.resolve(projectPath, 'README.md'), '\n', fs_extra_1.createReadStream(paths_1.DOC_README_PATH))];
|
54 | case 6:
|
55 |
|
56 | _a.sent();
|
57 | return [2 ];
|
58 | }
|
59 | });
|
60 | });
|
61 | }
|
62 | exports.default = genDoczFiles;
|
63 |
|
\ | No newline at end of file |