Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 34 additions & 18 deletions README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,22 +45,38 @@ $ npm install @form8ion/javascript --save

#### Import

```javascript
import 'validate-npm-package-name';
```

```javascript
const {dialects, projectTypes} = await import('@form8ion/javascript-core');
const {
scaffold: scaffoldJavaScript,
lift: liftJavascript,
test: thisIsAJavaScriptProject,
scaffoldUnitTesting,
questionNames
promptConstants
} = await import('./lib/index.js');

const {
questionNames
} = promptConstants;
const {BASE_DETAILS} = questionNames;
const {UNIT_TEST_FRAMEWORK} = questionNames.UNIT_TESTING;
```

#### Execute

```javascript
const accountName = 'form8ion';
const projectRoot = process.cwd();
const logger = {
info: () => undefined,
warn: () => undefined,
error: () => undefined,
success: () => undefined
};

await scaffoldJavaScript({
projectRoot,
Expand All@@ -81,22 +97,22 @@ await scaffoldJavaScript({
ciServices: {}
},
decisions: {
[questionNames.DIALECT]: dialects.BABEL,
[questionNames.NODE_VERSION_CATEGORY]: 'LTS',
[questionNames.PACKAGE_MANAGER]: 'npm',
[questionNames.PROJECT_TYPE]: projectTypes.PACKAGE,
[questionNames.SHOULD_BE_SCOPED]: true,
[questionNames.SCOPE]: accountName,
[questionNames.AUTHOR_NAME]: 'Your Name',
[questionNames.AUTHOR_EMAIL]: 'you@domain.tld',
[questionNames.AUTHOR_URL]: 'https://your.website.tld',
[questionNames.UNIT_TESTS]: true,
[questionNames.INTEGRATION_TESTS]: true,
[questionNames.PROVIDE_EXAMPLE]: true
[BASE_DETAILS.DIALECT]: dialects.BABEL,
[BASE_DETAILS.NODE_VERSION_CATEGORY]: 'LTS',
[BASE_DETAILS.PACKAGE_MANAGER]: 'npm',
[BASE_DETAILS.PROJECT_TYPE]: projectTypes.PACKAGE,
[BASE_DETAILS.SHOULD_BE_SCOPED]: true,
[BASE_DETAILS.SCOPE]: accountName,
[BASE_DETAILS.AUTHOR_NAME]: 'Your Name',
[BASE_DETAILS.AUTHOR_EMAIL]: 'you@domain.tld',
[BASE_DETAILS.AUTHOR_URL]: 'https://your.website.tld',
[BASE_DETAILS.UNIT_TESTS]: true,
[BASE_DETAILS.INTEGRATION_TESTS]: true,
[BASE_DETAILS.PROVIDE_EXAMPLE]: true
}
});
}, {logger});

if (await thisIsAJavaScriptProject({projectRoot})) {
if (await thisIsAJavaScriptProject({projectRoot}, {logger})) {
await liftJavascript({
projectRoot,
configs: {eslint: {scope: '@foo'}},
Expand All@@ -112,7 +128,7 @@ if (await thisIsAJavaScriptProject({projectRoot})) {
lift: () => ({})
}
}
});
}, {logger});
}

await scaffoldUnitTesting({
Expand All@@ -123,8 +139,8 @@ await scaffoldUnitTesting({
},
visibility: 'OSS',
vcs: {host: 'GitHub', owner: 'foo', name: 'bar'},
decisions: {[questionNames.UNIT_TEST_FRAMEWORK]: 'Mocha'}
});
decisions: {[UNIT_TEST_FRAMEWORK]: 'Mocha'}
}, {logger});
```

### Documentation
Expand Down
51 changes: 32 additions & 19 deletions example.js
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
// #### Import
// remark-usage-ignore-next 4
import {resolve} from 'path';
import {existsSync} from 'fs';
import stubbedFs from 'mock-fs';
import * as td from 'testdouble';
import 'validate-npm-package-name';
Expand All@@ -10,7 +11,7 @@ stubbedFs({
node_modules: stubbedFs.load(resolve('node_modules')),
'.nvmrc': 'v1.2.3',
lib: stubbedFs.load(resolve('lib')),
templates: stubbedFs.load(resolve('templates'))
...existsSync(resolve('templates')) && {templates: stubbedFs.load(resolve('templates'))}
});
const {execa} = await td.replaceEsm('execa');
td.when(execa('. ~/.nvm/nvm.sh && nvm ls-remote --lts', {shell: true}))
Expand All@@ -24,12 +25,24 @@ const {
lift: liftJavascript,
test: thisIsAJavaScriptProject,
scaffoldUnitTesting,
questionNames
promptConstants
} = await import('./lib/index.js');

const {
questionNames
} = promptConstants;
const {BASE_DETAILS} = questionNames;
const {UNIT_TEST_FRAMEWORK} = questionNames.UNIT_TESTING;

// #### Execute
const accountName = 'form8ion';
const projectRoot = process.cwd();
const logger = {
info: () => undefined,
warn: () => undefined,
error: () => undefined,
success: () => undefined
};

await scaffoldJavaScript({
projectRoot,
Expand All@@ -50,22 +63,22 @@ await scaffoldJavaScript({
ciServices: {}
},
decisions: {
[questionNames.DIALECT]: dialects.BABEL,
[questionNames.NODE_VERSION_CATEGORY]: 'LTS',
[questionNames.PACKAGE_MANAGER]: 'npm',
[questionNames.PROJECT_TYPE]: projectTypes.PACKAGE,
[questionNames.SHOULD_BE_SCOPED]: true,
[questionNames.SCOPE]: accountName,
[questionNames.AUTHOR_NAME]: 'Your Name',
[questionNames.AUTHOR_EMAIL]: 'you@domain.tld',
[questionNames.AUTHOR_URL]: 'https://your.website.tld',
[questionNames.UNIT_TESTS]: true,
[questionNames.INTEGRATION_TESTS]: true,
[questionNames.PROVIDE_EXAMPLE]: true
[BASE_DETAILS.DIALECT]: dialects.BABEL,
[BASE_DETAILS.NODE_VERSION_CATEGORY]: 'LTS',
[BASE_DETAILS.PACKAGE_MANAGER]: 'npm',
[BASE_DETAILS.PROJECT_TYPE]: projectTypes.PACKAGE,
[BASE_DETAILS.SHOULD_BE_SCOPED]: true,
[BASE_DETAILS.SCOPE]: accountName,
[BASE_DETAILS.AUTHOR_NAME]: 'Your Name',
[BASE_DETAILS.AUTHOR_EMAIL]: 'you@domain.tld',
[BASE_DETAILS.AUTHOR_URL]: 'https://your.website.tld',
[BASE_DETAILS.UNIT_TESTS]: true,
[BASE_DETAILS.INTEGRATION_TESTS]: true,
[BASE_DETAILS.PROVIDE_EXAMPLE]: true
}
});
}, {logger});

if (await thisIsAJavaScriptProject({projectRoot})) {
if (await thisIsAJavaScriptProject({projectRoot}, {logger})) {
await liftJavascript({
projectRoot,
configs: {eslint: {scope: '@foo'}},
Expand All@@ -81,7 +94,7 @@ if (await thisIsAJavaScriptProject({projectRoot})) {
lift: () => ({})
}
}
});
}, {logger});
}

await scaffoldUnitTesting({
Expand All@@ -92,5 +105,5 @@ await scaffoldUnitTesting({
},
visibility: 'OSS',
vcs: {host: 'GitHub', owner: 'foo', name: 'bar'},
decisions: {[questionNames.UNIT_TEST_FRAMEWORK]: 'Mocha'}
});
decisions: {[UNIT_TEST_FRAMEWORK]: 'Mocha'}
}, {logger});
3 changes: 2 additions & 1 deletion src/index.js
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
export {questionNames} from './prompts/question-names.js';
export {questionNames} from './prompts/index.js';
export {constants as promptConstants} from './prompts/index.js';
export {scaffold as scaffoldUnitTesting} from './testing/unit/index.js';
export {default as scaffold} from './scaffolder.js';
export {default as lift} from './lifter.js';
Expand Down
8 changes: 6 additions & 2 deletions src/project-type-plugin/prompt.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,15 +2,19 @@ import {prompt} from '@form8ion/overridable-prompts';

import {questionNames} from '../prompts/question-names.js';

export const PROJECT_TYPE_PLUGIN_PROMPT_ID = 'project-type-plugin';

export default async function gatherProjectTypePluginInput({types, projectType, decisions}) {
const {PROJECT_TYPE_CHOICE} = questionNames.PROJECT_TYPE_PLUGIN;

if (!Object.keys(types).length) return 'Other';

const answers = await prompt([{
name: questionNames.PROJECT_TYPE_CHOICE,
name: PROJECT_TYPE_CHOICE,
type: 'list',
message: `What type of ${projectType} is this?`,
choices: [...Object.keys(types), 'Other']
}], decisions);

return answers[questionNames.PROJECT_TYPE_CHOICE];
return answers[PROJECT_TYPE_CHOICE];
}
5 changes: 3 additions & 2 deletions src/project-type-plugin/prompt.test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,15 +11,16 @@ vi.mock('@form8ion/overridable-prompts');

describe('project-type prompts', () => {
it('should present the choice of project-type', async () => {
const {PROJECT_TYPE_CHOICE} = questionNames.PROJECT_TYPE_PLUGIN;
const chosenType = any.word();
const projectType = any.word();
const decisions = any.simpleObject();
const answers = {...any.simpleObject(), [questionNames.PROJECT_TYPE_CHOICE]: chosenType};
const answers = {...any.simpleObject(), [PROJECT_TYPE_CHOICE]: chosenType};
const types = any.simpleObject();
when(prompts.prompt)
.calledWith(
[{
name: questionNames.PROJECT_TYPE_CHOICE,
name: PROJECT_TYPE_CHOICE,
type: 'list',
message: `What type of ${projectType} is this?`,
choices: [...Object.keys(types), 'Other']
Expand Down
8 changes: 6 additions & 2 deletions src/project-type/publishable/bundler/prompt.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,15 +2,19 @@ import {prompt} from '@form8ion/overridable-prompts';

import {questionNames} from '../../../prompts/question-names.js';

export const PACKAGE_BUNDLER_PROMPT_ID = 'package-bundler';

export default async function gatherBundlerInput({bundlers, decisions}) {
const {PACKAGE_BUNDLER} = questionNames.PACKAGE_BUNDLER;

if (!Object.keys(bundlers).length) return 'Other';

const answers = await prompt([{
name: questionNames.PACKAGE_BUNDLER,
name: PACKAGE_BUNDLER,
type: 'list',
message: 'Which bundler should be used?',
choices: [...Object.keys(bundlers), 'Other']
}], decisions);

return answers[questionNames.PACKAGE_BUNDLER];
return answers[PACKAGE_BUNDLER];
}
5 changes: 3 additions & 2 deletions src/project-type/publishable/bundler/prompt.test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,12 +15,13 @@ describe('bundler prompt', () => {
});

it('should present the choice of package bundlers', async () => {
const {PACKAGE_BUNDLER} = questionNames.PACKAGE_BUNDLER;
const chosenType = any.word();
const decisions = any.simpleObject();
const answers = {...any.simpleObject(), [questionNames.PACKAGE_BUNDLER]: chosenType};
const answers = {...any.simpleObject(), [PACKAGE_BUNDLER]: chosenType};
const bundlers = any.simpleObject();
when(prompts.prompt).calledWith([{
name: questionNames.PACKAGE_BUNDLER,
name: PACKAGE_BUNDLER,
type: 'list',
message: 'Which bundler should be used?',
choices: [...Object.keys(bundlers), 'Other']
Expand Down
14 changes: 8 additions & 6 deletions src/prompts/conditionals.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,20 +2,22 @@ import {projectTypes} from '@form8ion/javascript-core';

import {questionNames} from './question-names.js';

const {BASE_DETAILS} = questionNames;

function projectIsCLI(answers) {
return projectTypes.CLI === answers[questionNames.PROJECT_TYPE];
return projectTypes.CLI === answers[BASE_DETAILS.PROJECT_TYPE];
}

export function projectIsPackage(answers) {
return projectTypes.PACKAGE === answers[questionNames.PROJECT_TYPE];
return projectTypes.PACKAGE === answers[BASE_DETAILS.PROJECT_TYPE];
}

export function projectIsApplication(answers) {
return projectTypes.APPLICATION === answers[questionNames.PROJECT_TYPE];
return projectTypes.APPLICATION === answers[BASE_DETAILS.PROJECT_TYPE];
}

function packageShouldBeScoped(visibility, answers) {
return ['ISS', 'CS'].includes(visibility) || answers[questionNames.SHOULD_BE_SCOPED];
return ['ISS', 'CS'].includes(visibility) || answers[BASE_DETAILS.SHOULD_BE_SCOPED];
}

function willBePublishedToRegistry(answers) {
Expand All@@ -31,8 +33,8 @@ export function scopePromptShouldBePresentedFactory(visibility) {
}

export function lintingPromptShouldBePresented({
[questionNames.UNIT_TESTS]: unitTested,
[questionNames.INTEGRATION_TESTS]: integrationTested
[BASE_DETAILS.UNIT_TESTS]: unitTested,
[BASE_DETAILS.INTEGRATION_TESTS]: integrationTested
}) {
return !unitTested && !integrationTested;
}
Loading