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
2 changes: 1 addition & 1 deletion README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,7 +102,7 @@ await scaffoldJavaScript(
logger,
prompt: ({id}) => {
const {questionNames, ids} = promptConstants;
const {BASE_DETAILS: baseDetailsPromptId} = ids;
const {JAVASCRIPT_BASE_DETAILS: baseDetailsPromptId} = ids;

switch (id) {
case baseDetailsPromptId: {
Expand Down
2 changes: 1 addition & 1 deletion example.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,7 +68,7 @@ await scaffoldJavaScript(
logger,
prompt: ({id}) => {
const {questionNames, ids} = promptConstants;
const {BASE_DETAILS: baseDetailsPromptId} = ids;
const {JAVASCRIPT_BASE_DETAILS: baseDetailsPromptId} = ids;

switch (id) {
case baseDetailsPromptId: {
Expand Down
14 changes: 7 additions & 7 deletions src/prompts/conditionals.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,22 +2,22 @@ import {projectTypes} from '@form8ion/javascript-core';

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

const {BASE_DETAILS} = questionNames;
const {JAVASCRIPT_BASE_DETAILS} = questionNames;

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

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

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

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

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

export function lintingPromptShouldBePresented({
[BASE_DETAILS.UNIT_TESTS]: unitTested,
[BASE_DETAILS.INTEGRATION_TESTS]: integrationTested
[JAVASCRIPT_BASE_DETAILS.UNIT_TESTS]: unitTested,
[JAVASCRIPT_BASE_DETAILS.INTEGRATION_TESTS]: integrationTested
}) {
return !unitTested && !integrationTested;
}
56 changes: 29 additions & 27 deletions src/prompts/conditionals.test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,106 +11,108 @@ import {
shouldBeScopedPromptShouldBePresented
} from './conditionals.js';

const {BASE_DETAILS} = questionNames;
const {JAVASCRIPT_BASE_DETAILS} = questionNames;

describe('javascript prompt conditionals', () => {
describe('scope', () => {
it('should present the prompt for whether the package should be scoped for `package` project-types', () => {
expect(shouldBeScopedPromptShouldBePresented({[BASE_DETAILS.PROJECT_TYPE]: projectTypes.PACKAGE})).toBe(true);
expect(shouldBeScopedPromptShouldBePresented({[JAVASCRIPT_BASE_DETAILS.PROJECT_TYPE]: projectTypes.PACKAGE}))
.toBe(true);
});

it('should present the prompt for whether the package should be scoped for `cli` project-types', () => {
expect(shouldBeScopedPromptShouldBePresented({[BASE_DETAILS.PROJECT_TYPE]: projectTypes.CLI})).toBe(true);
expect(shouldBeScopedPromptShouldBePresented({[JAVASCRIPT_BASE_DETAILS.PROJECT_TYPE]: projectTypes.CLI}))
.toBe(true);
});

it('shouldnt present the prompt for whether the package should be scoped for non-publishable project-types', () => {
expect(shouldBeScopedPromptShouldBePresented({[BASE_DETAILS.PROJECT_TYPE]: any.string()})).toBe(false);
expect(shouldBeScopedPromptShouldBePresented({[JAVASCRIPT_BASE_DETAILS.PROJECT_TYPE]: any.string()})).toBe(false);
});

it('should present a scope prompt when a package should be scoped', () => {
expect(scopePromptShouldBePresentedFactory()({
[BASE_DETAILS.SHOULD_BE_SCOPED]: true,
[BASE_DETAILS.PROJECT_TYPE]: projectTypes.PACKAGE
[JAVASCRIPT_BASE_DETAILS.SHOULD_BE_SCOPED]: true,
[JAVASCRIPT_BASE_DETAILS.PROJECT_TYPE]: projectTypes.PACKAGE
})).toBe(true);
});

it('should present a scope prompt when a package is inner source, because they must be scoped', () => {
expect(scopePromptShouldBePresentedFactory('ISS')({
[BASE_DETAILS.SHOULD_BE_SCOPED]: false,
[BASE_DETAILS.PROJECT_TYPE]: projectTypes.PACKAGE
[JAVASCRIPT_BASE_DETAILS.SHOULD_BE_SCOPED]: false,
[JAVASCRIPT_BASE_DETAILS.PROJECT_TYPE]: projectTypes.PACKAGE
})).toBe(true);
});

it('should present a scope prompt when a package is closed source, because they must be scoped', () => {
expect(scopePromptShouldBePresentedFactory('CS')({
[BASE_DETAILS.SHOULD_BE_SCOPED]: false,
[BASE_DETAILS.PROJECT_TYPE]: projectTypes.PACKAGE
[JAVASCRIPT_BASE_DETAILS.SHOULD_BE_SCOPED]: false,
[JAVASCRIPT_BASE_DETAILS.PROJECT_TYPE]: projectTypes.PACKAGE
})).toBe(true);
});

it('should present a scope prompt when a CLI should be scoped', () => {
expect(scopePromptShouldBePresentedFactory()({
[BASE_DETAILS.SHOULD_BE_SCOPED]: true,
[BASE_DETAILS.PROJECT_TYPE]: projectTypes.CLI
[JAVASCRIPT_BASE_DETAILS.SHOULD_BE_SCOPED]: true,
[JAVASCRIPT_BASE_DETAILS.PROJECT_TYPE]: projectTypes.CLI
})).toBe(true);
});

it('should present a scope prompt when a CLI is closed source, because they must be scoped', () => {
expect(scopePromptShouldBePresentedFactory('CS')({
[BASE_DETAILS.SHOULD_BE_SCOPED]: false,
[BASE_DETAILS.PROJECT_TYPE]: projectTypes.CLI
[JAVASCRIPT_BASE_DETAILS.SHOULD_BE_SCOPED]: false,
[JAVASCRIPT_BASE_DETAILS.PROJECT_TYPE]: projectTypes.CLI
})).toBe(true);
});

it('should present a scope prompt when a CLI is inner source, because they must be scoped', () => {
expect(scopePromptShouldBePresentedFactory('ISS')({
[BASE_DETAILS.SHOULD_BE_SCOPED]: false,
[BASE_DETAILS.PROJECT_TYPE]: projectTypes.CLI
[JAVASCRIPT_BASE_DETAILS.SHOULD_BE_SCOPED]: false,
[JAVASCRIPT_BASE_DETAILS.PROJECT_TYPE]: projectTypes.CLI
})).toBe(true);
});

it('should not present a scope prompt when an application is closed source', () => {
expect(scopePromptShouldBePresentedFactory('CS')({
[BASE_DETAILS.SHOULD_BE_SCOPED]: false,
[BASE_DETAILS.PROJECT_TYPE]: projectTypes.APPLICATION
[JAVASCRIPT_BASE_DETAILS.SHOULD_BE_SCOPED]: false,
[JAVASCRIPT_BASE_DETAILS.PROJECT_TYPE]: projectTypes.APPLICATION
})).toBe(false);
});

it('should not present a scope prompt when an application is inner source', () => {
expect(scopePromptShouldBePresentedFactory('ISS')({
[BASE_DETAILS.SHOULD_BE_SCOPED]: false,
[BASE_DETAILS.PROJECT_TYPE]: projectTypes.APPLICATION
[JAVASCRIPT_BASE_DETAILS.SHOULD_BE_SCOPED]: false,
[JAVASCRIPT_BASE_DETAILS.PROJECT_TYPE]: projectTypes.APPLICATION
})).toBe(false);
});

it('should not preset a scope prompt for non-publishable projects', () => {
expect(scopePromptShouldBePresentedFactory()({[BASE_DETAILS.SHOULD_BE_SCOPED]: false})).toBe(false);
expect(scopePromptShouldBePresentedFactory()({[JAVASCRIPT_BASE_DETAILS.SHOULD_BE_SCOPED]: false})).toBe(false);
});
});

describe('application', () => {
it('should return `true` when the package-type is `Application`', () => {
expect(projectIsApplication({[BASE_DETAILS.PROJECT_TYPE]: projectTypes.APPLICATION})).toBe(true);
expect(projectIsApplication({[JAVASCRIPT_BASE_DETAILS.PROJECT_TYPE]: projectTypes.APPLICATION})).toBe(true);
});

it('should return `false` when the project-type is not an application', () => {
expect(projectIsApplication({[BASE_DETAILS.PROJECT_TYPE]: any.word()})).toBe(false);
expect(projectIsApplication({[JAVASCRIPT_BASE_DETAILS.PROJECT_TYPE]: any.word()})).toBe(false);
});
});

describe('transpilation/linting', () => {
it('should not show the prompt if the project is unit tested ', () => {
expect(lintingPromptShouldBePresented({[BASE_DETAILS.UNIT_TESTS]: true})).toBe(false);
expect(lintingPromptShouldBePresented({[JAVASCRIPT_BASE_DETAILS.UNIT_TESTS]: true})).toBe(false);
});

it('should not show the prompt if the project is integration tested', () => {
expect(lintingPromptShouldBePresented({[BASE_DETAILS.INTEGRATION_TESTS]: true})).toBe(false);
expect(lintingPromptShouldBePresented({[JAVASCRIPT_BASE_DETAILS.INTEGRATION_TESTS]: true})).toBe(false);
});

it('should show the prompt if the project is not tested', () => {
expect(lintingPromptShouldBePresented({
[BASE_DETAILS.INTEGRATION_TESTS]: false,
[BASE_DETAILS.UNIT_TESTS]: false
[JAVASCRIPT_BASE_DETAILS.INTEGRATION_TESTS]: false,
[JAVASCRIPT_BASE_DETAILS.UNIT_TESTS]: false
})).toBe(true);
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/prompts/index.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,11 +2,11 @@ import {PROJECT_TYPE_PLUGIN_PROMPT_ID} from '../project-type-plugin/prompt.js';
import {PACKAGE_BUNDLER_PROMPT_ID} from '../project-type/publishable/bundler/prompt.js';
import {UNIT_TESTING_PROMPT_ID} from '../testing/unit/prompt.js';
import {INTEGRATION_TESTING_PROMPT_ID} from '../testing/integration/prompt.js';
import {BASE_DETAILS_PROMPT_ID} from './questions.js';
import {JAVASCRIPT_BASE_DETAILS_PROMPT_ID} from './questions.js';
import {questionNames} from './question-names.js';

export const ids = {
BASE_DETAILS: BASE_DETAILS_PROMPT_ID,
JAVASCRIPT_BASE_DETAILS: JAVASCRIPT_BASE_DETAILS_PROMPT_ID,
PROJECT_TYPE_PLUGIN: PROJECT_TYPE_PLUGIN_PROMPT_ID,
PACKAGE_BUNDLER: PACKAGE_BUNDLER_PROMPT_ID,
UNIT_TESTING: UNIT_TESTING_PROMPT_ID,
Expand Down
4 changes: 2 additions & 2 deletions src/prompts/index.test.js
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import {describe, expect, it} from 'vitest';

import {BASE_DETAILS_PROMPT_ID} from './questions.js';
import {JAVASCRIPT_BASE_DETAILS_PROMPT_ID} from './questions.js';
import {PROJECT_TYPE_PLUGIN_PROMPT_ID} from '../project-type-plugin/prompt.js';
import {PACKAGE_BUNDLER_PROMPT_ID} from '../project-type/publishable/bundler/prompt.js';
import {UNIT_TESTING_PROMPT_ID} from '../testing/unit/prompt.js';
Expand All@@ -10,7 +10,7 @@ import {constants, ids, questionNames} from './index.js';
describe('prompt constants', () => {
it('should aggregate the prompt ids and grouped question names', () => {
expect(ids).toEqual({
BASE_DETAILS: BASE_DETAILS_PROMPT_ID,
JAVASCRIPT_BASE_DETAILS: JAVASCRIPT_BASE_DETAILS_PROMPT_ID,
PROJECT_TYPE_PLUGIN: PROJECT_TYPE_PLUGIN_PROMPT_ID,
PACKAGE_BUNDLER: PACKAGE_BUNDLER_PROMPT_ID,
UNIT_TESTING: UNIT_TESTING_PROMPT_ID,
Expand Down
2 changes: 1 addition & 1 deletion src/prompts/question-names.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
export const questionNames = {
BASE_DETAILS: {
JAVASCRIPT_BASE_DETAILS: {
UNIT_TESTS: 'unitTests',
INTEGRATION_TESTS: 'integrationTests',
NODE_VERSION_CATEGORY: 'nodeVersionCategory',
Expand Down
2 changes: 1 addition & 1 deletion src/prompts/question-names.test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ import {questionNames} from './question-names.js';
describe('question names', () => {
it('should group question names by prompt area', () => {
expect(questionNames).toEqual({
BASE_DETAILS: {
JAVASCRIPT_BASE_DETAILS: {
UNIT_TESTS: 'unitTests',
INTEGRATION_TESTS: 'integrationTests',
NODE_VERSION_CATEGORY: 'nodeVersionCategory',
Expand Down
6 changes: 3 additions & 3 deletions src/prompts/questions.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,7 +13,7 @@ import {
import {questionNames} from './question-names.js';
import {scope as validateScope} from './validators.js';

export const BASE_DETAILS_PROMPT_ID = 'BASE_DETAILS';
export const JAVASCRIPT_BASE_DETAILS_PROMPT_ID = 'JAVASCRIPT_BASE_DETAILS';

const {
AUTHOR_NAME,
Expand All@@ -30,7 +30,7 @@ const {
CONFIGURE_LINTING,
PACKAGE_MANAGER,
DIALECT
} = questionNames[BASE_DETAILS_PROMPT_ID];
} = questionNames[JAVASCRIPT_BASE_DETAILS_PROMPT_ID];

function authorQuestions({name, email, url}) {
return [
Expand DownExpand Up@@ -85,7 +85,7 @@ export async function gatherBaseDetailsInput(
[PACKAGE_MANAGER]: packageManager,
[DIALECT]: dialect
} = await prompt({
id: BASE_DETAILS_PROMPT_ID,
id: JAVASCRIPT_BASE_DETAILS_PROMPT_ID,
questions: [
{
name: DIALECT,
Expand Down
Loading