1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const fs = require("fs-extra");
|
5 | const lazy_get_decorator_1 = require("lazy-get-decorator");
|
6 | const addPkgMgr_1 = require("../../commons/addPkgMgr");
|
7 | const identity_1 = require("../../commons/identity");
|
8 | const PackageManager_1 = require("../../inc/PackageManager");
|
9 | const Fixture_1 = require("../Fixture");
|
10 | const Git_1 = require("../Git");
|
11 | const Log_1 = require("../Log");
|
12 | exports.options = {
|
13 | 'skip-gh-issue-tpl': {
|
14 | default: false,
|
15 | describe: 'Skip issue & contribution template generation',
|
16 | type: 'boolean'
|
17 | }
|
18 | };
|
19 | identity_1.addGhRepo(exports.options);
|
20 | identity_1.addGhUser(exports.options);
|
21 | addPkgMgr_1.addPkgMgrToOptions(exports.options);
|
22 | class Initialiser {
|
23 | constructor(c) {
|
24 | this.c = c;
|
25 | this.gitFiles = [];
|
26 | this.initContributing();
|
27 | this.initIssueTemplate();
|
28 | this.initPR();
|
29 | this.initIssueTemplates();
|
30 | this.gadd();
|
31 | }
|
32 | get fix() {
|
33 | return new Fixture_1.Fixture('init/gh-templates');
|
34 | }
|
35 | get ghRepo() {
|
36 | return this.c.promptedGhRepo();
|
37 | }
|
38 | get ghUser() {
|
39 | return this.c.promptedGhUser();
|
40 | }
|
41 | get issueTplBase() {
|
42 | return this.fix.read('issue_template_base.md').toString().trim();
|
43 | }
|
44 | gadd(...files) {
|
45 | if (files.length) {
|
46 | this.gitFiles.push(...files);
|
47 | }
|
48 | else {
|
49 | Git_1.Git.add(...this.gitFiles);
|
50 | }
|
51 | }
|
52 | initContributing() {
|
53 | const yarnMsg = '- Please ensure you use [yarn package manager](https://yarnpkg.com) and not npm.';
|
54 | this.template('CONTRIBUTING.md', {
|
55 | extraLines: this.c.promptedPkgMgr() === PackageManager_1.PackageManager.YARN ? yarnMsg : '',
|
56 | ghRepo: this.ghRepo,
|
57 | ghUser: this.ghUser,
|
58 | pkgMgr: this.c.promptedPkgMgr()
|
59 | }, '.github/CONTRIBUTING.md');
|
60 | }
|
61 | initIssueTemplate() {
|
62 | this.template('ISSUE_TEMPLATE.md', { issueTemplateBase: this.issueTplBase }, '.github/ISSUE_TEMPLATE.md');
|
63 | }
|
64 | initIssueTemplates() {
|
65 | for (const name of ['bug_report', 'feature_request', 'guidance_request']) {
|
66 | this.template(`ISSUE_TEMPLATE/${name}.md`, { issueTemplateBase: this.issueTplBase }, `.github/ISSUE_TEMPLATE/${name}.md`, false);
|
67 | }
|
68 | }
|
69 | initPR() {
|
70 | this.template('PULL_REQUEST_TEMPLATE.md', { ghUser: this.ghUser, ghRepo: this.ghRepo }, '.github/PULL_REQUEST_TEMPLATE.md');
|
71 | }
|
72 | template(src, tpl, dest, ifNotExists = true) {
|
73 | if (!ifNotExists || !fs.pathExistsSync(dest)) {
|
74 | this.fix.template(src, tpl, dest);
|
75 | this.gadd(dest);
|
76 | }
|
77 | }
|
78 | }
|
79 | tslib_1.__decorate([
|
80 | lazy_get_decorator_1.LazyGetter(),
|
81 | tslib_1.__metadata("design:type", Fixture_1.Fixture),
|
82 | tslib_1.__metadata("design:paramtypes", [])
|
83 | ], Initialiser.prototype, "fix", null);
|
84 | tslib_1.__decorate([
|
85 | lazy_get_decorator_1.LazyGetter(),
|
86 | tslib_1.__metadata("design:type", String),
|
87 | tslib_1.__metadata("design:paramtypes", [])
|
88 | ], Initialiser.prototype, "ghRepo", null);
|
89 | tslib_1.__decorate([
|
90 | lazy_get_decorator_1.LazyGetter(),
|
91 | tslib_1.__metadata("design:type", String),
|
92 | tslib_1.__metadata("design:paramtypes", [])
|
93 | ], Initialiser.prototype, "ghUser", null);
|
94 | tslib_1.__decorate([
|
95 | lazy_get_decorator_1.LazyGetter(),
|
96 | tslib_1.__metadata("design:type", String),
|
97 | tslib_1.__metadata("design:paramtypes", [])
|
98 | ], Initialiser.prototype, "issueTplBase", null);
|
99 | function handle(c) {
|
100 | if (!c.get('skipGhIssueTpl')) {
|
101 | Log_1.Log.info('Generating issue templates');
|
102 | new Initialiser(c);
|
103 | Log_1.Log.success('Generated issue templates');
|
104 | }
|
105 | else {
|
106 | Log_1.Log.info('Skipping issue templates');
|
107 | }
|
108 | }
|
109 | exports.handle = handle;
|