This repository has been archived by the owner on Dec 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app-types): scaffolded the chosen app type
for #185
- Loading branch information
Showing
6 changed files
with
71 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
import chalk from 'chalk'; | ||
import chooseApplicationType from './prompt'; | ||
import scaffoldChosenApplicationType from './choice-scaffolder'; | ||
|
||
export default async function ({applicationTypes}) { | ||
export default async function ({applicationTypes, projectRoot}) { | ||
console.log(chalk.blue('Scaffolding Application Details')); // eslint-disable-line no-console | ||
|
||
await chooseApplicationType({types: applicationTypes}); | ||
const chosenType = await chooseApplicationType({types: applicationTypes}); | ||
const results = await scaffoldChosenApplicationType(applicationTypes, chosenType, {projectRoot}); | ||
|
||
return { | ||
scripts: {start: './lib/index.js'}, | ||
devDependencies: [], | ||
dependencies: [], | ||
vcsIgnore: {files: [], directories: []} | ||
scripts: {start: './lib/index.js', ...results.scripts}, | ||
dependencies: results.dependencies, | ||
devDependencies: results.devDependencies, | ||
vcsIgnore: {files: results.vcsIgnore.files, directories: results.vcsIgnore.directories} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function (typeScaffolders, chosenType, options) { | ||
const typeScaffolder = typeScaffolders[chosenType]; | ||
|
||
if (typeScaffolder) return typeScaffolder(options); | ||
|
||
return {scripts: {}, dependencies: [], devDependencies: [], vcsIgnore: {files: [], directories: []}}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import {prompt, Separator} from 'inquirer'; | ||
|
||
export default function ({types}) { | ||
return prompt([{ | ||
name: 'types', | ||
export default async function ({types}) { | ||
const answers = await prompt([{ | ||
name: 'type', | ||
type: 'list', | ||
message: 'What type of application is this?', | ||
choices: [...Object.keys(types), new Separator(), 'Other'] | ||
}]); | ||
|
||
return answers.type; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {assert} from 'chai'; | ||
import any from '@travi/any'; | ||
import sinon from 'sinon'; | ||
import scaffoldTypeChoice from '../../../src/project-type/choice-scaffolder'; | ||
|
||
suite('type choice scaffolder', () => { | ||
test('that chosen type is scaffolded', async () => { | ||
const chosenType = any.word(); | ||
const options = any.simpleObject(); | ||
const results = any.simpleObject(); | ||
const chosenTypeScaffolder = sinon.stub(); | ||
const typeScaffolders = {...any.simpleObject(), [chosenType]: chosenTypeScaffolder}; | ||
chosenTypeScaffolder.withArgs(options).resolves(results); | ||
|
||
assert.equal(await scaffoldTypeChoice(typeScaffolders, chosenType, options), results); | ||
}); | ||
|
||
test('that that choosing a type without a defined scaffolder does not result in an error', async () => { | ||
assert.deepEqual( | ||
await scaffoldTypeChoice(any.simpleObject(), any.string()), | ||
{scripts: {}, dependencies: [], devDependencies: [], vcsIgnore: {files: [], directories: []}} | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters