@form8ion/project 21.0.1 → 21.0.3
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/lib/index.js +75 -67
- package/lib/index.js.map +1 -1
- package/package.json +17 -14
- package/src/contributing/index.js +1 -0
- package/src/contributing/scaffolder.js +17 -0
- package/src/contributing/scaffolder.test.js +22 -0
- package/src/dependency-updater/prompt.js +11 -0
- package/src/dependency-updater/prompt.test.js +30 -0
- package/src/dependency-updater/scaffolder.js +14 -0
- package/src/dependency-updater/scaffolder.test.js +42 -0
- package/src/dependency-updater/schema.js +4 -0
- package/src/dependency-updater/schema.test.js +43 -0
- package/src/editorconfig/index.js +1 -0
- package/src/editorconfig/scaffolder.js +7 -0
- package/src/editorconfig/scaffolder.test.js +26 -0
- package/src/index.js +9 -0
- package/src/language/index.js +2 -0
- package/src/language/prompt.js +12 -0
- package/src/language/prompt.test.js +30 -0
- package/src/language/scaffolder.js +12 -0
- package/src/language/scaffolder.test.js +32 -0
- package/src/language/schema.js +4 -0
- package/src/language/schema.test.js +43 -0
- package/src/license/index.js +3 -0
- package/src/license/lifter.js +19 -0
- package/src/license/lifter.test.js +30 -0
- package/src/license/scaffolder.js +24 -0
- package/src/license/scaffolder.test.js +60 -0
- package/src/license/tester.js +5 -0
- package/src/license/tester.test.js +25 -0
- package/src/lift.js +18 -0
- package/src/lift.test.js +40 -0
- package/src/options-schemas.js +3 -0
- package/src/options-schemas.test.js +20 -0
- package/src/options-validator.js +18 -0
- package/src/options-validator.test.js +50 -0
- package/src/prompts/conditionals.js +13 -0
- package/src/prompts/conditionals.test.js +51 -0
- package/src/prompts/question-names.js +7 -0
- package/src/prompts/questions.js +6 -0
- package/src/prompts/questions.test.js +25 -0
- package/src/prompts/terminal-prompt.js +5 -0
- package/src/prompts/terminal-prompt.test.js +20 -0
- package/src/scaffolder.js +76 -0
- package/src/scaffolder.test.js +297 -0
- package/src/template-path.js +8 -0
- package/src/template-path.test.js +14 -0
- package/src/vcs/git/index.js +1 -0
- package/src/vcs/git/remotes.js +51 -0
- package/src/vcs/git/remotes.test.js +86 -0
- package/src/vcs/host/index.js +1 -0
- package/src/vcs/host/prompt.js +15 -0
- package/src/vcs/host/prompt.test.js +47 -0
- package/src/vcs/host/scaffolder.js +16 -0
- package/src/vcs/host/scaffolder.test.js +41 -0
- package/src/vcs/host/schema.js +4 -0
- package/src/vcs/host/schema.test.js +46 -0
- package/src/vcs/index.js +1 -0
- package/src/vcs/prompt.js +17 -0
- package/src/vcs/prompt.test.js +27 -0
- package/src/vcs/scaffolder.js +34 -0
- package/src/vcs/scaffolder.test.js +60 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {validateOptions} from '@form8ion/core';
|
|
2
|
+
|
|
3
|
+
import {describe, expect, it} from 'vitest';
|
|
4
|
+
import any from '@travi/any';
|
|
5
|
+
|
|
6
|
+
import vcsHostSchema from './schema.js';
|
|
7
|
+
|
|
8
|
+
describe('vcs-host plugins schema', () => {
|
|
9
|
+
const key = any.word();
|
|
10
|
+
|
|
11
|
+
it('should return the validated options', () => {
|
|
12
|
+
const options = any.objectWithKeys(
|
|
13
|
+
any.listOf(any.string),
|
|
14
|
+
{
|
|
15
|
+
factory: () => ({
|
|
16
|
+
scaffold: foo => foo,
|
|
17
|
+
prompt: () => undefined,
|
|
18
|
+
public: any.boolean(),
|
|
19
|
+
private: any.boolean()
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
expect(validateOptions(vcsHostSchema, options)).toEqual(options);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should require options to be provided as an object', () => {
|
|
28
|
+
expect(() => validateOptions(vcsHostSchema, {[key]: []}))
|
|
29
|
+
.toThrowError(`"${key}" must be of type object`);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should require a `scaffold` to be included', () => {
|
|
33
|
+
expect(() => validateOptions(vcsHostSchema, {[key]: {}}))
|
|
34
|
+
.toThrowError(`"${key}.scaffold" is required`);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should require `scaffold` to be a function', () => {
|
|
38
|
+
expect(() => validateOptions(vcsHostSchema, {[key]: {scaffold: any.word()}}))
|
|
39
|
+
.toThrowError(`"${key}.scaffold" must be of type function`);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should require the scaffold to accept a single argument', () => {
|
|
43
|
+
expect(() => validateOptions(vcsHostSchema, {[key]: {scaffold: () => undefined}}))
|
|
44
|
+
.toThrowError(`"${key}.scaffold" must have an arity greater or equal to 1`);
|
|
45
|
+
});
|
|
46
|
+
});
|
package/src/vcs/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {default as scaffold} from './scaffolder.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {prompt} from '@form8ion/overridable-prompts';
|
|
2
|
+
|
|
3
|
+
import {questionNames} from '../prompts/question-names.js';
|
|
4
|
+
|
|
5
|
+
export default async function promptForRepoCreation(decisions) {
|
|
6
|
+
const {[questionNames.GIT_REPO]: gitRepoShouldBeCreated} = await prompt(
|
|
7
|
+
[{
|
|
8
|
+
name: questionNames.GIT_REPO,
|
|
9
|
+
type: 'confirm',
|
|
10
|
+
default: true,
|
|
11
|
+
message: 'Should a git repository be initialized?'
|
|
12
|
+
}],
|
|
13
|
+
decisions
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
return gitRepoShouldBeCreated;
|
|
17
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {prompt} from '@form8ion/overridable-prompts';
|
|
2
|
+
|
|
3
|
+
import {describe, vi, it, expect} from 'vitest';
|
|
4
|
+
import {when} from 'vitest-when';
|
|
5
|
+
import any from '@travi/any';
|
|
6
|
+
|
|
7
|
+
import {questionNames} from '../prompts/question-names.js';
|
|
8
|
+
import promptForRepoCreation from './prompt.js';
|
|
9
|
+
|
|
10
|
+
vi.mock('@form8ion/overridable-prompts');
|
|
11
|
+
|
|
12
|
+
describe('git prompt', () => {
|
|
13
|
+
it('should ask whether a repository should be created', async () => {
|
|
14
|
+
const decisions = any.simpleObject();
|
|
15
|
+
const repoShouldBeCreated = any.boolean();
|
|
16
|
+
when(prompt)
|
|
17
|
+
.calledWith([{
|
|
18
|
+
name: questionNames.GIT_REPO,
|
|
19
|
+
type: 'confirm',
|
|
20
|
+
default: true,
|
|
21
|
+
message: 'Should a git repository be initialized?'
|
|
22
|
+
}], decisions)
|
|
23
|
+
.thenResolve({[questionNames.GIT_REPO]: repoShouldBeCreated});
|
|
24
|
+
|
|
25
|
+
expect(await promptForRepoCreation(decisions)).toBe(repoShouldBeCreated);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {info} from '@travi/cli-messages';
|
|
2
|
+
import {scaffold as scaffoldGit, test as alreadyVersionedByGit} from '@form8ion/git';
|
|
3
|
+
|
|
4
|
+
import repositoryShouldBeCreated from './prompt.js';
|
|
5
|
+
import {determineExistingVcsDetails, defineRemoteOrigin} from './git/index.js';
|
|
6
|
+
import {scaffold as scaffoldVcsHost} from './host/index.js';
|
|
7
|
+
|
|
8
|
+
export default async function scaffoldVcs({projectRoot, projectName, decisions, vcsHosts, visibility, description}) {
|
|
9
|
+
if (await repositoryShouldBeCreated(decisions)) {
|
|
10
|
+
if (await alreadyVersionedByGit({projectRoot})) {
|
|
11
|
+
info('Git repository already exists');
|
|
12
|
+
|
|
13
|
+
return {vcs: await determineExistingVcsDetails({projectRoot})};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const [{vcs: {host, owner, name, sshUrl}}] = await Promise.all([
|
|
17
|
+
scaffoldVcsHost(
|
|
18
|
+
vcsHosts,
|
|
19
|
+
decisions,
|
|
20
|
+
{projectName, projectRoot, description, visibility}
|
|
21
|
+
),
|
|
22
|
+
scaffoldGit({projectRoot})
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const remoteOriginResults = await defineRemoteOrigin(projectRoot, sshUrl);
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
vcs: {host, owner, name},
|
|
29
|
+
nextSteps: [{summary: 'Commit scaffolded files'}, ...remoteOriginResults.nextSteps]
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {};
|
|
34
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {test as alreadyVersionedByGit, scaffold as scaffoldGit} from '@form8ion/git';
|
|
2
|
+
|
|
3
|
+
import {describe, expect, it, vi} from 'vitest';
|
|
4
|
+
import {when} from 'vitest-when';
|
|
5
|
+
import any from '@travi/any';
|
|
6
|
+
|
|
7
|
+
import {scaffold as scaffoldVcsHost} from './host/index.js';
|
|
8
|
+
import {determineExistingVcsDetails, defineRemoteOrigin} from './git/index.js';
|
|
9
|
+
import promptForRepoCreation from './prompt.js';
|
|
10
|
+
import scaffoldVcs from './scaffolder.js';
|
|
11
|
+
|
|
12
|
+
vi.mock('@form8ion/git');
|
|
13
|
+
vi.mock('./git/index.js');
|
|
14
|
+
vi.mock('./host/index.js');
|
|
15
|
+
vi.mock('./prompt.js');
|
|
16
|
+
|
|
17
|
+
describe('vcs scaffolder', () => {
|
|
18
|
+
const projectRoot = any.string();
|
|
19
|
+
const decisions = any.simpleObject();
|
|
20
|
+
|
|
21
|
+
it('should scaffold the repository and vcs host details', async () => {
|
|
22
|
+
const host = any.word();
|
|
23
|
+
const owner = any.word();
|
|
24
|
+
const name = any.word();
|
|
25
|
+
const vcsHosts = any.simpleObject();
|
|
26
|
+
const visibility = any.word();
|
|
27
|
+
const projectName = any.word();
|
|
28
|
+
const description = any.sentence();
|
|
29
|
+
const vcsHostDetails = {host, owner, name};
|
|
30
|
+
const sshUrl = any.url();
|
|
31
|
+
const remoteOriginNextSteps = any.listOf(any.simpleObject);
|
|
32
|
+
when(promptForRepoCreation).calledWith(decisions).thenResolve(true);
|
|
33
|
+
when(alreadyVersionedByGit).calledWith({projectRoot}).thenResolve(false);
|
|
34
|
+
when(scaffoldVcsHost)
|
|
35
|
+
.calledWith(vcsHosts, decisions, {projectName, projectRoot, description, visibility})
|
|
36
|
+
.thenResolve({vcs: {...vcsHostDetails, sshUrl, ...any.simpleObject()}});
|
|
37
|
+
when(defineRemoteOrigin).calledWith(projectRoot, sshUrl).thenResolve({nextSteps: remoteOriginNextSteps});
|
|
38
|
+
|
|
39
|
+
expect(await scaffoldVcs({projectRoot, projectName, decisions, vcsHosts, visibility, description})).toEqual({
|
|
40
|
+
vcs: vcsHostDetails,
|
|
41
|
+
nextSteps: [{summary: 'Commit scaffolded files'}, ...remoteOriginNextSteps]
|
|
42
|
+
});
|
|
43
|
+
expect(scaffoldGit).toHaveBeenCalledWith({projectRoot});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should not scaffold a repository or vcs host details when the project is already versioned by git', async () => {
|
|
47
|
+
const existingVcsDetails = any.simpleObject();
|
|
48
|
+
when(promptForRepoCreation).calledWith(decisions).thenResolve(true);
|
|
49
|
+
when(alreadyVersionedByGit).calledWith({projectRoot}).thenResolve(true);
|
|
50
|
+
when(determineExistingVcsDetails).calledWith({projectRoot}).thenResolve(existingVcsDetails);
|
|
51
|
+
|
|
52
|
+
expect(await scaffoldVcs({projectRoot, decisions})).toEqual({vcs: existingVcsDetails});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should not scaffold a repository or vcs host details when a repository should not be created', async () => {
|
|
56
|
+
when(promptForRepoCreation).calledWith(decisions).thenResolve(false);
|
|
57
|
+
|
|
58
|
+
expect(await scaffoldVcs({projectRoot, decisions})).toEqual({});
|
|
59
|
+
});
|
|
60
|
+
});
|