Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

refactor(index): rewrite answer parsing #541

Merged
merged 20 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
introduce --no-interactive, mostly for test
  • Loading branch information
Haroenv committed Nov 29, 2021
commit ecdbbc7596de33cf3e87b5748aae7c4cf0e18808
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ $ create-instantsearch-app --help
--library-version <libraryVersion> The version of the library
--config <config> The configuration file to get the options from
--no-installation Ignore dependency installation
--no-interactive Do not ask any interactive questions
-h, --help output usage information
```

Expand Down
40 changes: 9 additions & 31 deletions e2e/installs.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
const fs = require('fs');
const { execSync } = require('child_process');
const { getEarliestLibraryVersion } = require('../src/utils');

describe('Installation', () => {
let temporaryDirectory;
let appPath;
let configFilePath;
const appName = 'test-app';

beforeAll(() => {
Expand All @@ -20,45 +18,22 @@ describe('Installation', () => {
execSync(`rm -rf "${temporaryDirectory}"`);
});

beforeEach(async () => {
beforeEach(() => {
appPath = `${temporaryDirectory}/${appName}`;
execSync(`mkdir ${appPath}`);

const templateConfig = require('../src/templates/InstantSearch.js/.template.js');

const config = {
template: 'InstantSearch.js',
// We fetch the earliest supported version in order to not change
// the test output every time we release a new version of a library.
libraryVersion: await getEarliestLibraryVersion({
libraryName: templateConfig.libraryName,
supportedVersion: templateConfig.supportedVersion,
}),
appId: 'appId',
apiKey: 'apiKey',
indexName: 'indexName',
searchPlaceholder: 'Search placeholder',
attributesToDisplay: ['attribute1', 'attribute2'],
attributesForFaceting: ['facet1', 'facet2'],
organization: 'algolia',
};

configFilePath = `${temporaryDirectory}/config.json`;

fs.writeFileSync(configFilePath, JSON.stringify(config));
});

afterEach(() => {
execSync(`rm -rf "${appPath}"`);
execSync(`rm -f "${configFilePath}"`);
});

describe('Dependencies', () => {
test('get skipped with the `no-installation` flag', () => {
execSync(
`yarn start ${appPath} \
--name ${appName} \
--config ${configFilePath} \
--template "InstantSearch.js" \
--no-interactive \
--no-installation`,
{ stdio: 'ignore' }
);
Expand All @@ -72,7 +47,8 @@ describe('Installation', () => {
execSync(
`yarn start ${appPath} \
--name ${appName} \
--config ${configFilePath} \
--template "InstantSearch.js" \
--no-interactive \
--no-installation`,
{ stdio: 'ignore' }
);
Expand All @@ -87,7 +63,8 @@ describe('Installation', () => {
execSync(
`yarn start ${appPath} \
--name ${appName} \
--config ${configFilePath} \
--template "InstantSearch.js" \
--no-interactive \
--no-installation`,
{ stdio: 'ignore' }
);
Expand All @@ -107,7 +84,8 @@ describe('Installation', () => {
execSync(
`yarn start ${appPath}/file \
--name ${appName} \
--config ${configFilePath} \
--template "InstantSearch.js" \
--no-interactive \
--no-installation`,
{ stdio: 'ignore' }
);
Expand Down
13 changes: 11 additions & 2 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ program
.option('--library-version <version>', 'The version of the library')
.option('--config <config>', 'The configuration file to get the options from')
.option('--no-installation', 'Ignore dependency installation')
.option('--no-interactive', 'Ask no interactive questions')
.action(dest => {
appPathFromArgument = dest;
})
Expand Down Expand Up @@ -240,7 +241,11 @@ const getQuestions = ({ appName }) => ({
},
when(answers) {
try {
return !answers.config && !checkAppPath(answers.appPath);
return (
answers.interactive &&
!answers.config &&
!checkAppPath(answers.appPath)
);
} catch (err) {
return true;
}
Expand All @@ -265,7 +270,11 @@ const getQuestions = ({ appName }) => ({
},
when(answers) {
try {
return !answers.config && !checkAppName(answers.appName);
return (
answers.interactive &&
!answers.config &&
!checkAppName(answers.appName)
);
} catch (err) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/isQuestionAsked.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = function isQuestionAsked({ question, args }) {
// if there's a config, ask no questions, even if it would be invalid
if (args.config) {
if (args.config || !args.interactive) {
return true;
}

Expand Down