@form8ion/project 22.0.0-beta.2 → 22.0.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -26
- package/lib/index.js +207 -105
- package/lib/index.js.map +1 -1
- package/package.json +28 -29
- package/src/ci-provider/index.js +1 -0
- package/src/ci-provider/prompt.js +17 -0
- package/src/ci-provider/prompt.test.js +27 -0
- package/src/ci-provider/scaffolder.js +27 -0
- package/src/ci-provider/scaffolder.test.js +68 -0
- package/src/ci-provider/schema.js +4 -0
- package/src/ci-provider/schema.test.js +43 -0
- package/src/contributing/scaffolder.js +2 -2
- package/src/contributing/scaffolder.test.js +14 -2
- package/src/dependency-updater/prompt.js +14 -8
- package/src/dependency-updater/prompt.test.js +16 -17
- package/src/dependency-updater/scaffolder.js +4 -2
- package/src/dependency-updater/scaffolder.test.js +18 -15
- package/src/editorconfig/index.js +1 -0
- package/src/editorconfig/scaffolder.js +1 -1
- package/src/editorconfig/tester.js +5 -0
- package/src/editorconfig/tester.test.js +25 -0
- package/src/index.js +1 -7
- package/src/language/prompt.js +14 -9
- package/src/language/prompt.test.js +15 -16
- package/src/language/scaffolder.js +4 -2
- package/src/language/scaffolder.test.js +13 -8
- package/src/license/lifter.js +1 -1
- package/src/license/scaffolder.js +2 -3
- package/src/license/scaffolder.test.js +5 -8
- package/src/license/tester.js +1 -1
- package/src/lift.js +8 -2
- package/src/lift.test.js +26 -13
- package/src/options-validator.js +3 -3
- package/src/options-validator.test.js +4 -6
- package/src/prompts/index.js +20 -0
- package/src/prompts/question-names.js +19 -5
- package/src/prompts/questions.js +7 -3
- package/src/prompts/questions.test.js +5 -6
- package/src/scaffolder.js +18 -17
- package/src/scaffolder.test.js +39 -31
- package/src/template-path.js +1 -1
- package/src/vcs/git/remotes.js +6 -7
- package/src/vcs/git/remotes.test.js +21 -16
- package/src/vcs/host/prompt.js +15 -10
- package/src/vcs/host/prompt.test.js +31 -25
- package/src/vcs/host/scaffolder.js +4 -2
- package/src/vcs/host/scaffolder.test.js +9 -7
- package/src/vcs/prompt.js +11 -9
- package/src/vcs/prompt.test.js +15 -12
- package/src/vcs/scaffolder.js +9 -11
- package/src/vcs/scaffolder.test.js +10 -9
- package/src/options-schemas.js +0 -3
- package/src/options-schemas.test.js +0 -20
- package/src/prompts/conditionals.js +0 -13
- package/src/prompts/conditionals.test.js +0 -51
package/README.md
CHANGED
|
@@ -71,45 +71,89 @@ a wrapper.
|
|
|
71
71
|
#### Import
|
|
72
72
|
|
|
73
73
|
```javascript
|
|
74
|
-
import {
|
|
74
|
+
import {ungroupObject} from '@form8ion/core';
|
|
75
|
+
import {lift, promptConstants, scaffold} from '@form8ion/project';
|
|
75
76
|
```
|
|
76
77
|
|
|
77
78
|
#### Execute
|
|
78
79
|
|
|
79
80
|
```javascript
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
[questionNames.LICENSE]: 'MIT',
|
|
84
|
-
[questionNames.VISIBILITY]: 'Public',
|
|
85
|
-
[questionNames.DESCRIPTION]: 'My project',
|
|
86
|
-
[questionNames.GIT_REPO]: false,
|
|
87
|
-
[questionNames.COPYRIGHT_HOLDER]: 'John Smith',
|
|
88
|
-
[questionNames.COPYRIGHT_YEAR]: '2022',
|
|
89
|
-
[questionNames.PROJECT_LANGUAGE]: 'foo'
|
|
81
|
+
const plugins = {
|
|
82
|
+
dependencyUpdaters: {
|
|
83
|
+
bar: {scaffold: options => options}
|
|
90
84
|
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
vcsHosts: {
|
|
99
|
-
baz: {
|
|
100
|
-
scaffold: options => options,
|
|
101
|
-
prompt: () => ({repoOwner: 'form8ion'})
|
|
102
|
-
}
|
|
85
|
+
languages: {
|
|
86
|
+
foo: {scaffold: options => options}
|
|
87
|
+
},
|
|
88
|
+
vcsHosts: {
|
|
89
|
+
baz: {
|
|
90
|
+
scaffold: options => options,
|
|
91
|
+
prompt: () => ({repoOwner: 'form8ion'})
|
|
103
92
|
}
|
|
104
93
|
}
|
|
105
|
-
}
|
|
94
|
+
};
|
|
95
|
+
const logger = {
|
|
96
|
+
info: () => undefined,
|
|
97
|
+
success: () => undefined,
|
|
98
|
+
warn: () => undefined,
|
|
99
|
+
error: () => undefined
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
await scaffold(
|
|
103
|
+
{plugins},
|
|
104
|
+
{
|
|
105
|
+
prompt: async ({id}) => {
|
|
106
|
+
const {questionNames, ids} = promptConstants;
|
|
107
|
+
const {
|
|
108
|
+
BASE_DETAILS: baseDetailsPromptId,
|
|
109
|
+
GIT_REPOSITORY: gitRepositoryPromptId,
|
|
110
|
+
PROJECT_LANGUAGE: projectLanguagePromptId
|
|
111
|
+
} = ids;
|
|
112
|
+
|
|
113
|
+
switch (id) {
|
|
114
|
+
case baseDetailsPromptId: {
|
|
115
|
+
const {
|
|
116
|
+
PROJECT_NAME,
|
|
117
|
+
LICENSE,
|
|
118
|
+
VISIBILITY,
|
|
119
|
+
DESCRIPTION,
|
|
120
|
+
COPYRIGHT_HOLDER,
|
|
121
|
+
COPYRIGHT_YEAR
|
|
122
|
+
} = questionNames[baseDetailsPromptId];
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
[PROJECT_NAME]: 'my-project',
|
|
126
|
+
[LICENSE]: 'MIT',
|
|
127
|
+
[VISIBILITY]: 'OSS',
|
|
128
|
+
[DESCRIPTION]: 'My project',
|
|
129
|
+
[COPYRIGHT_HOLDER]: 'John Smith',
|
|
130
|
+
[COPYRIGHT_YEAR]: '2022'
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
case gitRepositoryPromptId: {
|
|
134
|
+
const {GIT_REPO} = questionNames[gitRepositoryPromptId];
|
|
135
|
+
|
|
136
|
+
return {[GIT_REPO]: false};
|
|
137
|
+
}
|
|
138
|
+
case projectLanguagePromptId: {
|
|
139
|
+
const {PROJECT_LANGUAGE} = questionNames[projectLanguagePromptId];
|
|
140
|
+
|
|
141
|
+
return {[PROJECT_LANGUAGE]: 'foo'};
|
|
142
|
+
}
|
|
143
|
+
default:
|
|
144
|
+
throw new Error(`Unknown prompt with ID: ${id}`);
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
logger
|
|
148
|
+
}
|
|
149
|
+
);
|
|
106
150
|
|
|
107
151
|
await lift({
|
|
108
152
|
projectRoot: process.cwd(),
|
|
109
153
|
results: {},
|
|
110
|
-
enhancers:
|
|
154
|
+
enhancers: ungroupObject(plugins),
|
|
111
155
|
vcs: {}
|
|
112
|
-
});
|
|
156
|
+
}, {logger});
|
|
113
157
|
```
|
|
114
158
|
|
|
115
159
|
### API
|
package/lib/index.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { fileExists, questionsForBaseDetails, optionsSchemas, validateOptions, applyEnhancers, questionNames as questionNames$2 } from '@form8ion/core';
|
|
2
1
|
import deepmerge from 'deepmerge';
|
|
3
2
|
import { execa } from 'execa';
|
|
4
|
-
import {
|
|
3
|
+
import { questionNames as questionNames$1, fileExists, questionsForBaseDetails, optionsSchemas, validateOptions, applyEnhancers } from '@form8ion/core';
|
|
5
4
|
import { lift as lift$1, scaffold as scaffold$2 } from '@form8ion/readme';
|
|
6
|
-
import { warn, info } from '@travi/cli-messages';
|
|
7
|
-
import { prompt } from '@form8ion/overridable-prompts';
|
|
8
5
|
import * as gitPlugin from '@form8ion/git';
|
|
9
6
|
import { test, scaffold as scaffold$1 } from '@form8ion/git';
|
|
10
7
|
import { simpleGit } from 'simple-git';
|
|
11
|
-
import
|
|
8
|
+
import parseGitUrl from 'git-url-parse';
|
|
12
9
|
import { promises } from 'fs';
|
|
13
10
|
import wrap from 'word-wrap';
|
|
14
11
|
import mustache from 'mustache';
|
|
@@ -17,26 +14,48 @@ import joi from 'joi';
|
|
|
17
14
|
import { promises as promises$1 } from 'node:fs';
|
|
18
15
|
import { resolve } from 'path';
|
|
19
16
|
import filedirname from 'filedirname';
|
|
17
|
+
import * as misePlugin from '@form8ion/mise';
|
|
20
18
|
|
|
21
|
-
const questionNames
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
const questionNames = {
|
|
20
|
+
BASE_DETAILS: questionNames$1,
|
|
21
|
+
GIT_REPOSITORY: {
|
|
22
|
+
GIT_REPO: 'gitRepo'
|
|
23
|
+
},
|
|
24
|
+
REPOSITORY_HOST: {
|
|
25
|
+
REPO_HOST: 'repoHost',
|
|
26
|
+
REPO_OWNER: 'repoOwner'
|
|
27
|
+
},
|
|
28
|
+
PROJECT_LANGUAGE: {
|
|
29
|
+
PROJECT_LANGUAGE: 'projectLanguage'
|
|
30
|
+
},
|
|
31
|
+
DEPENDENCY_UPDATER: {
|
|
32
|
+
DEPENDENCY_UPDATER: 'dependencyUpdater'
|
|
33
|
+
},
|
|
34
|
+
CI_PROVIDER: {
|
|
35
|
+
CI_PROVIDER: 'ciProvider'
|
|
36
|
+
}
|
|
27
37
|
};
|
|
28
38
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
const PROJECT_LANGUAGE_PROMPT_ID = 'PROJECT_LANGUAGE';
|
|
40
|
+
|
|
41
|
+
const {PROJECT_LANGUAGE: PROJECT_LANGUAGE$1} = questionNames.PROJECT_LANGUAGE;
|
|
42
|
+
|
|
43
|
+
function promptForProjectLanguage(languages, {prompt}) {
|
|
44
|
+
return prompt({
|
|
45
|
+
id: PROJECT_LANGUAGE_PROMPT_ID,
|
|
46
|
+
questions: [{
|
|
47
|
+
name: PROJECT_LANGUAGE$1,
|
|
48
|
+
type: 'list',
|
|
49
|
+
message: 'What type of project is this?',
|
|
50
|
+
choices: [...Object.keys(languages), 'Other']
|
|
51
|
+
}]
|
|
52
|
+
});
|
|
36
53
|
}
|
|
37
54
|
|
|
38
|
-
|
|
39
|
-
|
|
55
|
+
const {PROJECT_LANGUAGE} = questionNames.PROJECT_LANGUAGE;
|
|
56
|
+
|
|
57
|
+
async function scaffoldLanguage(languagePlugins, options, {prompt}) {
|
|
58
|
+
const {[PROJECT_LANGUAGE]: chosenLanguage} = await promptForProjectLanguage(languagePlugins, {prompt});
|
|
40
59
|
|
|
41
60
|
const plugin = languagePlugins[chosenLanguage];
|
|
42
61
|
|
|
@@ -45,16 +64,20 @@ async function scaffoldLanguage (languagePlugins, decisions, options) {
|
|
|
45
64
|
return undefined;
|
|
46
65
|
}
|
|
47
66
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
67
|
+
const GIT_REPOSITORY_PROMPT_ID = 'GIT_REPOSITORY';
|
|
68
|
+
|
|
69
|
+
const {GIT_REPO} = questionNames.GIT_REPOSITORY;
|
|
70
|
+
|
|
71
|
+
async function promptForRepoCreation({prompt}) {
|
|
72
|
+
const {[GIT_REPO]: gitRepoShouldBeCreated} = await prompt({
|
|
73
|
+
id: GIT_REPOSITORY_PROMPT_ID,
|
|
74
|
+
questions: [{
|
|
75
|
+
name: GIT_REPO,
|
|
52
76
|
type: 'confirm',
|
|
53
77
|
default: true,
|
|
54
78
|
message: 'Should a git repository be initialized?'
|
|
55
|
-
}]
|
|
56
|
-
|
|
57
|
-
);
|
|
79
|
+
}]
|
|
80
|
+
});
|
|
58
81
|
|
|
59
82
|
return gitRepoShouldBeCreated;
|
|
60
83
|
}
|
|
@@ -74,14 +97,14 @@ async function getExistingRemotes(git) {
|
|
|
74
97
|
async function determineExistingVcsDetails({projectRoot}) {
|
|
75
98
|
const git = simpleGit({baseDir: projectRoot});
|
|
76
99
|
const remoteOrigin = await git.remote(['get-url', 'origin']);
|
|
77
|
-
const {
|
|
100
|
+
const {owner, name, host} = parseGitUrl(remoteOrigin.trimEnd());
|
|
78
101
|
|
|
79
|
-
return {vcs: {owner
|
|
102
|
+
return {vcs: {owner, name, host}};
|
|
80
103
|
}
|
|
81
104
|
|
|
82
|
-
async function defineRemoteOrigin(projectRoot, sshUrl) {
|
|
105
|
+
async function defineRemoteOrigin(projectRoot, sshUrl, {logger}) {
|
|
83
106
|
if (!sshUrl) {
|
|
84
|
-
warn('URL not available to configure remote `origin`');
|
|
107
|
+
logger.warn('URL not available to configure remote `origin`');
|
|
85
108
|
|
|
86
109
|
return {nextSteps: []};
|
|
87
110
|
}
|
|
@@ -90,7 +113,7 @@ async function defineRemoteOrigin(projectRoot, sshUrl) {
|
|
|
90
113
|
const existingRemotes = await getExistingRemotes(git);
|
|
91
114
|
|
|
92
115
|
if (existingRemotes.includes('origin')) {
|
|
93
|
-
warn('The `origin` remote is already defined for this repository');
|
|
116
|
+
logger.warn('The `origin` remote is already defined for this repository');
|
|
94
117
|
|
|
95
118
|
return {nextSteps: []};
|
|
96
119
|
}
|
|
@@ -107,20 +130,29 @@ async function defineRemoteOrigin(projectRoot, sshUrl) {
|
|
|
107
130
|
return {nextSteps: [{summary: 'Set local `master` branch to track upstream `origin/master`'}]};
|
|
108
131
|
}
|
|
109
132
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
133
|
+
const REPOSITORY_HOST_PROMPT_ID = 'REPOSITORY_HOST';
|
|
134
|
+
|
|
135
|
+
const {REPO_HOST: REPO_HOST$1} = questionNames.REPOSITORY_HOST;
|
|
136
|
+
|
|
137
|
+
async function promptForVcsHostChoice(hosts, {prompt}) {
|
|
138
|
+
const answers = await prompt({
|
|
139
|
+
id: REPOSITORY_HOST_PROMPT_ID,
|
|
140
|
+
questions: [{
|
|
141
|
+
name: REPO_HOST$1,
|
|
142
|
+
type: 'list',
|
|
143
|
+
message: 'Where will the repository be hosted?',
|
|
144
|
+
choices: Object.keys(hosts)
|
|
145
|
+
}]
|
|
146
|
+
});
|
|
147
|
+
const host = hosts[answers[REPO_HOST$1]];
|
|
118
148
|
|
|
119
149
|
return {...answers, ...host};
|
|
120
150
|
}
|
|
121
151
|
|
|
122
|
-
|
|
123
|
-
|
|
152
|
+
const {REPO_HOST} = questionNames.REPOSITORY_HOST;
|
|
153
|
+
|
|
154
|
+
async function scaffoldVcsHost(hosts, options, {prompt}) {
|
|
155
|
+
const {[REPO_HOST]: chosenHost} = await promptForVcsHostChoice(hosts, {prompt});
|
|
124
156
|
|
|
125
157
|
const lowercasedHosts = Object.fromEntries(
|
|
126
158
|
Object.entries(hosts).map(([name, details]) => [name.toLowerCase(), details])
|
|
@@ -132,24 +164,23 @@ async function scaffoldVcsHost(hosts, decisions, options) {
|
|
|
132
164
|
return {vcs: {}};
|
|
133
165
|
}
|
|
134
166
|
|
|
135
|
-
async function scaffoldVcs(
|
|
136
|
-
|
|
167
|
+
async function scaffoldVcs(
|
|
168
|
+
{projectRoot, projectName, vcsHosts, visibility, description},
|
|
169
|
+
{prompt, logger}
|
|
170
|
+
) {
|
|
171
|
+
if (await promptForRepoCreation({prompt})) {
|
|
137
172
|
if (await test({projectRoot})) {
|
|
138
|
-
info('Git repository already exists');
|
|
173
|
+
logger.info('Git repository already exists');
|
|
139
174
|
|
|
140
|
-
return
|
|
175
|
+
return determineExistingVcsDetails({projectRoot});
|
|
141
176
|
}
|
|
142
177
|
|
|
143
178
|
const [{vcs: {host, owner, name, sshUrl}}] = await Promise.all([
|
|
144
|
-
scaffoldVcsHost(
|
|
145
|
-
vcsHosts,
|
|
146
|
-
decisions,
|
|
147
|
-
{projectName, projectRoot, description, visibility}
|
|
148
|
-
),
|
|
179
|
+
scaffoldVcsHost(vcsHosts, {projectName, projectRoot, description, visibility}, {prompt}),
|
|
149
180
|
scaffold$1({projectRoot})
|
|
150
181
|
]);
|
|
151
182
|
|
|
152
|
-
const remoteOriginResults = await defineRemoteOrigin(projectRoot, sshUrl);
|
|
183
|
+
const remoteOriginResults = await defineRemoteOrigin(projectRoot, sshUrl, {logger});
|
|
153
184
|
|
|
154
185
|
return {
|
|
155
186
|
vcs: {host, owner, name},
|
|
@@ -160,9 +191,9 @@ async function scaffoldVcs({projectRoot, projectName, decisions, vcsHosts, visib
|
|
|
160
191
|
return {};
|
|
161
192
|
}
|
|
162
193
|
|
|
163
|
-
async function scaffoldLicense
|
|
194
|
+
async function scaffoldLicense({projectRoot, license, copyright}, {logger}) {
|
|
164
195
|
if (license) {
|
|
165
|
-
info('Generating License');
|
|
196
|
+
logger.info('Generating License');
|
|
166
197
|
|
|
167
198
|
const licenseContent = spdxLicenseList[license].licenseText;
|
|
168
199
|
|
|
@@ -178,7 +209,7 @@ async function scaffoldLicense ({projectRoot, license, copyright}) {
|
|
|
178
209
|
return {};
|
|
179
210
|
}
|
|
180
211
|
|
|
181
|
-
function
|
|
212
|
+
function licenseDefined({projectRoot}) {
|
|
182
213
|
return fileExists(`${projectRoot}/LICENSE`);
|
|
183
214
|
}
|
|
184
215
|
|
|
@@ -186,7 +217,7 @@ function repositoryIsHostedOnGithub(vcs) {
|
|
|
186
217
|
return vcs && 'github' === vcs.host;
|
|
187
218
|
}
|
|
188
219
|
|
|
189
|
-
function
|
|
220
|
+
function liftLicense({vcs}) {
|
|
190
221
|
return {
|
|
191
222
|
...repositoryIsHostedOnGithub(vcs) && {
|
|
192
223
|
badges: {
|
|
@@ -204,25 +235,34 @@ function lifter ({vcs}) {
|
|
|
204
235
|
|
|
205
236
|
var licensePlugin = /*#__PURE__*/Object.freeze({
|
|
206
237
|
__proto__: null,
|
|
207
|
-
lift:
|
|
238
|
+
lift: liftLicense,
|
|
208
239
|
scaffold: scaffoldLicense,
|
|
209
|
-
test:
|
|
240
|
+
test: licenseDefined
|
|
210
241
|
});
|
|
211
242
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
243
|
+
const DEPENDENCY_UPDATER_PROMPT_ID = 'DEPENDENCY_UPDATER';
|
|
244
|
+
|
|
245
|
+
const {DEPENDENCY_UPDATER: DEPENDENCY_UPDATER$1} = questionNames.DEPENDENCY_UPDATER;
|
|
246
|
+
|
|
247
|
+
async function promptForDependencyUpdaterChoice(updaters, {prompt}) {
|
|
248
|
+
return prompt({
|
|
249
|
+
id: DEPENDENCY_UPDATER_PROMPT_ID,
|
|
250
|
+
questions: [{
|
|
251
|
+
name: DEPENDENCY_UPDATER$1,
|
|
252
|
+
type: 'list',
|
|
253
|
+
message: 'Which dependency-update service do you want to manage this project?',
|
|
254
|
+
choices: [...Object.keys(updaters), 'Other']
|
|
255
|
+
}]
|
|
256
|
+
});
|
|
219
257
|
}
|
|
220
258
|
|
|
221
|
-
|
|
259
|
+
const {DEPENDENCY_UPDATER} = questionNames.DEPENDENCY_UPDATER;
|
|
260
|
+
|
|
261
|
+
async function scaffoldDependencyUpdater(plugins, options, {prompt}) {
|
|
222
262
|
if (!Object.keys(plugins).length) return undefined;
|
|
223
263
|
|
|
224
264
|
const plugin = plugins[
|
|
225
|
-
(await promptForDependencyUpdaterChoice(plugins,
|
|
265
|
+
(await promptForDependencyUpdaterChoice(plugins, {prompt}))[DEPENDENCY_UPDATER]
|
|
226
266
|
];
|
|
227
267
|
|
|
228
268
|
if (plugin) return plugin.scaffold(options);
|
|
@@ -230,8 +270,54 @@ async function scaffoldDependencyUpdater (plugins, decisions, options) {
|
|
|
230
270
|
return undefined;
|
|
231
271
|
}
|
|
232
272
|
|
|
233
|
-
|
|
234
|
-
|
|
273
|
+
const CI_PROVIDER_PROMPT_ID = 'CI_PROVIDER';
|
|
274
|
+
|
|
275
|
+
const {CI_PROVIDER: CI_PROVIDER$1} = questionNames.CI_PROVIDER;
|
|
276
|
+
|
|
277
|
+
function promptForCiProvider(providers, {prompt}) {
|
|
278
|
+
return prompt({
|
|
279
|
+
id: CI_PROVIDER_PROMPT_ID,
|
|
280
|
+
questions: [{
|
|
281
|
+
name: CI_PROVIDER$1,
|
|
282
|
+
type: 'list',
|
|
283
|
+
message: 'Which CI service do you want use with this project?',
|
|
284
|
+
choices: [...Object.keys(providers), 'Other']
|
|
285
|
+
}]
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const {CI_PROVIDER} = questionNames.CI_PROVIDER;
|
|
290
|
+
|
|
291
|
+
async function scaffoldCiProvider(plugins, options, {prompt}) {
|
|
292
|
+
if (!Object.keys(plugins).length) return undefined;
|
|
293
|
+
|
|
294
|
+
const {projectRoot} = options;
|
|
295
|
+
|
|
296
|
+
const qualifiedPlugins = Object.fromEntries(
|
|
297
|
+
(await Promise.all(
|
|
298
|
+
Object.entries(plugins).map(async ([name, plugin]) => [
|
|
299
|
+
name,
|
|
300
|
+
plugin,
|
|
301
|
+
plugin.qualify ? await plugin.qualify({projectRoot}) : true
|
|
302
|
+
])
|
|
303
|
+
)).filter(([, , qualified]) => qualified).map(([name, plugin]) => [name, plugin])
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
const chosen = (await promptForCiProvider(qualifiedPlugins, {prompt}))[CI_PROVIDER];
|
|
307
|
+
const plugin = qualifiedPlugins[chosen];
|
|
308
|
+
|
|
309
|
+
if (plugin) return plugin.scaffold(options);
|
|
310
|
+
|
|
311
|
+
return {};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const BASE_DETAILS_PROMPT_ID = 'BASE_DETAILS';
|
|
315
|
+
|
|
316
|
+
function promptForBaseDetails(projectRoot, {prompt}) {
|
|
317
|
+
return prompt({
|
|
318
|
+
id: BASE_DETAILS_PROMPT_ID,
|
|
319
|
+
questions: questionsForBaseDetails(projectRoot)
|
|
320
|
+
});
|
|
235
321
|
}
|
|
236
322
|
|
|
237
323
|
var languagePluginsSchema = joi.object().pattern(/^/, optionsSchemas.form8ionPlugin).default({});
|
|
@@ -240,31 +326,35 @@ var vcsHostPluginsSchema = joi.object().pattern(/^/, optionsSchemas.form8ionPlug
|
|
|
240
326
|
|
|
241
327
|
var dependencyUpdaterPluginsSchema = joi.object().pattern(joi.string(), optionsSchemas.form8ionPlugin).default({});
|
|
242
328
|
|
|
243
|
-
|
|
329
|
+
var ciProviderPluginsSchema = joi.object().pattern(joi.string(), optionsSchemas.form8ionPlugin).default({});
|
|
244
330
|
|
|
245
331
|
function validate(options) {
|
|
246
332
|
return validateOptions(joi.object({
|
|
247
|
-
decisions: decisionsSchema,
|
|
248
333
|
plugins: joi.object({
|
|
249
334
|
dependencyUpdaters: dependencyUpdaterPluginsSchema,
|
|
250
335
|
languages: languagePluginsSchema,
|
|
251
|
-
vcsHosts: vcsHostPluginsSchema
|
|
336
|
+
vcsHosts: vcsHostPluginsSchema,
|
|
337
|
+
ciProviders: ciProviderPluginsSchema
|
|
252
338
|
})
|
|
253
339
|
}), options) || {};
|
|
254
340
|
}
|
|
255
341
|
|
|
256
|
-
function
|
|
342
|
+
function determinePathToTemplate(fileName) {
|
|
257
343
|
const [, __dirname] = filedirname();
|
|
258
344
|
|
|
259
345
|
return resolve(__dirname, '..', 'templates', fileName);
|
|
260
346
|
}
|
|
261
347
|
|
|
262
|
-
function scaffoldEditorConfig
|
|
263
|
-
return promises$1.copyFile(
|
|
348
|
+
function scaffoldEditorConfig({projectRoot}) {
|
|
349
|
+
return promises$1.copyFile(determinePathToTemplate('editorconfig.ini'), `${projectRoot}/.editorconfig`);
|
|
264
350
|
}
|
|
265
351
|
|
|
266
|
-
function
|
|
267
|
-
|
|
352
|
+
function editorconfigInUse({projectRoot}) {
|
|
353
|
+
return fileExists(`${projectRoot}/.editorconfig`);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function scaffoldContribution({visibility}) {
|
|
357
|
+
if (['OSS', 'ISS'].includes(visibility)) {
|
|
268
358
|
return {
|
|
269
359
|
badges: {
|
|
270
360
|
contribution: {
|
|
@@ -281,10 +371,14 @@ function scaffoldContributing ({visibility}) {
|
|
|
281
371
|
return {};
|
|
282
372
|
}
|
|
283
373
|
|
|
284
|
-
async function lift
|
|
374
|
+
async function lift({projectRoot, results, enhancers, vcs}, dependencies) {
|
|
375
|
+
if (!await editorconfigInUse({projectRoot})) {
|
|
376
|
+
await scaffoldEditorConfig({projectRoot});
|
|
377
|
+
}
|
|
378
|
+
|
|
285
379
|
const enhancerResults = await applyEnhancers({
|
|
286
380
|
results,
|
|
287
|
-
enhancers: {...enhancers, gitPlugin, licensePlugin},
|
|
381
|
+
enhancers: {...enhancers, gitPlugin, licensePlugin, misePlugin},
|
|
288
382
|
options: {projectRoot, vcs},
|
|
289
383
|
dependencies
|
|
290
384
|
});
|
|
@@ -294,38 +388,40 @@ async function lift ({projectRoot, results, enhancers, vcs, dependencies}) {
|
|
|
294
388
|
return enhancerResults;
|
|
295
389
|
}
|
|
296
390
|
|
|
297
|
-
async function scaffold(options) {
|
|
391
|
+
async function scaffold(options, dependencies) {
|
|
298
392
|
const projectRoot = process.cwd();
|
|
299
|
-
const {
|
|
393
|
+
const {plugins: {dependencyUpdaters, ciProviders, languages, vcsHosts = {}}} = validate(options);
|
|
394
|
+
const {prompt, logger} = dependencies;
|
|
300
395
|
|
|
301
396
|
const {
|
|
302
|
-
[questionNames$
|
|
303
|
-
[questionNames$
|
|
304
|
-
[questionNames$
|
|
305
|
-
[questionNames$
|
|
306
|
-
[questionNames$
|
|
307
|
-
[questionNames$
|
|
308
|
-
} = await promptForBaseDetails(projectRoot,
|
|
397
|
+
[questionNames$1.PROJECT_NAME]: projectName,
|
|
398
|
+
[questionNames$1.LICENSE]: chosenLicense,
|
|
399
|
+
[questionNames$1.VISIBILITY]: visibility,
|
|
400
|
+
[questionNames$1.DESCRIPTION]: description,
|
|
401
|
+
[questionNames$1.COPYRIGHT_YEAR]: copyrightYear,
|
|
402
|
+
[questionNames$1.COPYRIGHT_HOLDER]: copyHolder
|
|
403
|
+
} = await promptForBaseDetails(projectRoot, {prompt});
|
|
309
404
|
const copyright = {year: copyrightYear, holder: copyHolder};
|
|
310
405
|
|
|
311
406
|
const [vcsResults, contributing, license] = await Promise.all([
|
|
312
|
-
scaffoldVcs({projectRoot, projectName,
|
|
313
|
-
|
|
314
|
-
scaffoldLicense({projectRoot, license: chosenLicense, copyright}),
|
|
407
|
+
scaffoldVcs({projectRoot, projectName, vcsHosts, visibility, description}, {prompt, logger}),
|
|
408
|
+
scaffoldContribution({visibility}),
|
|
409
|
+
scaffoldLicense({projectRoot, license: chosenLicense, copyright}, {logger}),
|
|
315
410
|
scaffold$2({projectName, projectRoot, description}),
|
|
316
411
|
scaffoldEditorConfig({projectRoot})
|
|
317
412
|
]);
|
|
318
413
|
|
|
319
|
-
const dependencyUpdaterResults = vcsResults.vcs
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
414
|
+
const [dependencyUpdaterResults] = vcsResults.vcs
|
|
415
|
+
? await Promise.all([
|
|
416
|
+
scaffoldDependencyUpdater(dependencyUpdaters, {projectRoot}, {prompt}),
|
|
417
|
+
scaffoldCiProvider(ciProviders, {projectRoot}, {prompt})
|
|
418
|
+
])
|
|
419
|
+
: [];
|
|
324
420
|
|
|
325
421
|
const language = await scaffoldLanguage(
|
|
326
422
|
languages,
|
|
327
|
-
|
|
328
|
-
{
|
|
423
|
+
{projectRoot, projectName, vcs: vcsResults.vcs, visibility, license: chosenLicense || 'UNLICENSED', description},
|
|
424
|
+
{prompt}
|
|
329
425
|
);
|
|
330
426
|
|
|
331
427
|
const mergedResults = deepmerge.all([
|
|
@@ -341,23 +437,29 @@ async function scaffold(options) {
|
|
|
341
437
|
vcs: vcsResults.vcs,
|
|
342
438
|
results: mergedResults,
|
|
343
439
|
enhancers: {...dependencyUpdaters, ...languages, ...vcsHosts}
|
|
344
|
-
});
|
|
440
|
+
}, dependencies);
|
|
345
441
|
|
|
346
442
|
if (language && language.verificationCommand) {
|
|
347
|
-
info('Verifying the generated project');
|
|
443
|
+
logger.info('Verifying the generated project');
|
|
348
444
|
|
|
349
445
|
const subprocess = execa(language.verificationCommand, {shell: true});
|
|
350
446
|
subprocess.stdout.pipe(process.stdout);
|
|
351
447
|
await subprocess;
|
|
352
448
|
}
|
|
353
449
|
|
|
354
|
-
|
|
450
|
+
return mergedResults;
|
|
355
451
|
}
|
|
356
452
|
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
|
|
453
|
+
const ids = {
|
|
454
|
+
BASE_DETAILS: BASE_DETAILS_PROMPT_ID,
|
|
455
|
+
GIT_REPOSITORY: GIT_REPOSITORY_PROMPT_ID,
|
|
456
|
+
REPOSITORY_HOST: REPOSITORY_HOST_PROMPT_ID,
|
|
457
|
+
PROJECT_LANGUAGE: PROJECT_LANGUAGE_PROMPT_ID,
|
|
458
|
+
DEPENDENCY_UPDATER: DEPENDENCY_UPDATER_PROMPT_ID,
|
|
459
|
+
CI_PROVIDER: CI_PROVIDER_PROMPT_ID
|
|
360
460
|
};
|
|
361
461
|
|
|
362
|
-
|
|
462
|
+
const constants = {ids, questionNames};
|
|
463
|
+
|
|
464
|
+
export { lift, constants as promptConstants, scaffold };
|
|
363
465
|
//# sourceMappingURL=index.js.map
|