diff --git a/.eslintignore b/.eslintignore index 100bac21a..0cbd6cbda 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,2 @@ **/node_modules/** -/templates +/src/templates diff --git a/index.js b/index.js index 8fbde0876..7d73580bb 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,3 @@ -const createInstantSearchApp = require('./packages/create-instantsearch-app'); +const createInstantSearchApp = require('./src/api'); module.exports = createInstantSearchApp; diff --git a/package.json b/package.json index ffd9dfb83..ef08f6d11 100644 --- a/package.json +++ b/package.json @@ -7,11 +7,11 @@ "author": "Algolia ", "main": "index.js", "bin": { - "create-instantsearch-app": "packages/cli/index.js" + "create-instantsearch-app": "src/cli/index.js" }, "scripts": { - "start": "node packages/cli/index.js", - "test": "jest ./packages", + "start": "node src/cli/index.js", + "test": "jest ./src", "test:e2e:templates": "jest './scripts/e2e-templates.test.js'", "test:e2e": "jest './scripts/e2e-*'", "lint": "eslint .", @@ -23,8 +23,7 @@ }, "files": [ "index.js", - "packages", - "templates" + "src" ], "engines": { "node": ">= 8" @@ -37,6 +36,7 @@ "jstransformer-handlebars": "^1.1.0", "latest-semver": "^1.0.0", "load-json-file": "^5.0.0", + "lodash.camelcase": "^4.3.0", "metalsmith": "^2.3.0", "metalsmith-ignore": "^0.1.2", "metalsmith-in-place": "^4.1.1", @@ -62,7 +62,7 @@ "jest": { "testPathIgnorePatterns": [ "/node_modules/", - "/templates/" + "/src/templates/" ] } } diff --git a/packages/cli/index.js b/packages/cli/index.js deleted file mode 100755 index fb098591e..000000000 --- a/packages/cli/index.js +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env node -const cli = require('./cli'); - -module.exports = cli; diff --git a/packages/cli/utils.js b/packages/cli/utils.js deleted file mode 100644 index b407196b1..000000000 --- a/packages/cli/utils.js +++ /dev/null @@ -1,121 +0,0 @@ -const algoliasearch = require('algoliasearch'); -const latestSemver = require('latest-semver'); -const loadJsonFile = require('load-json-file'); - -const { - getAppTemplateConfig, - fetchLibraryVersions, - getTemplatePath, -} = require('../shared/utils'); - -function camelCase(string) { - return string.replace(/-([a-z])/g, str => str[1].toUpperCase()); -} - -function getOptionsFromArguments(rawArgs) { - let argIndex = 0; - - return rawArgs.reduce((allArgs, currentArg) => { - argIndex++; - - if (!currentArg.startsWith('--') || currentArg.startsWith('--no-')) { - return allArgs; - } - - const argumentName = camelCase(currentArg.split('--')[1]); - const argumentValue = rawArgs[argIndex]; - - return { - ...allArgs, - [argumentName]: argumentValue, - }; - }, {}); -} - -async function getAttributesFromAnswers({ - appId, - apiKey, - indexName, - algoliasearchFn = algoliasearch, -} = {}) { - const client = algoliasearchFn(appId, apiKey); - const defaultAttributes = ['title', 'name', 'description']; - let attributes = []; - - try { - const { hits } = await client.search({ indexName, hitsPerPage: 1 }); - const [firstHit] = hits; - const highlightedAttributes = Object.keys(firstHit._highlightResult); - attributes = [ - ...new Set([ - ...defaultAttributes.map( - attribute => highlightedAttributes.includes(attribute) && attribute - ), - ...highlightedAttributes, - ]), - ]; - } catch (err) { - attributes = defaultAttributes; - } - - return attributes; -} - -function isQuestionAsked({ question, args }) { - if (args.config) { - return false; - } - - for (const optionName in args) { - if (question.name === optionName) { - // Skip if the arg in the command is valid - if (question.validate && question.validate(args[optionName])) { - return false; - } - } else if (!question.validate) { - // Skip if the question is optional and not given in the command - return false; - } - } - - return true; -} - -async function getConfiguration({ - options = {}, - answers = {}, - loadJsonFileFn = loadJsonFile, -} = {}) { - const config = options.config - ? await loadJsonFileFn(options.config) // From configuration file given as an argument - : { ...options, ...answers }; // From the arguments and the prompt - - if (!config.template) { - throw new Error('The template is required in the config.'); - } - - const templatePath = getTemplatePath(config.template); - let { libraryVersion } = config; - - if (!libraryVersion) { - const templateConfig = getAppTemplateConfig(templatePath); - - libraryVersion = await fetchLibraryVersions( - templateConfig.libraryName - ).then(latestSemver); - } - - return { - ...config, - libraryVersion, - template: templatePath, - }; -} - -module.exports = { - camelCase, - getOptionsFromArguments, - getAttributesFromAnswers, - isQuestionAsked, - getConfiguration, -}; diff --git a/packages/cli/utils.test.js b/packages/cli/utils.test.js deleted file mode 100644 index 28d4a0166..000000000 --- a/packages/cli/utils.test.js +++ /dev/null @@ -1,254 +0,0 @@ -const path = require('path'); -const utils = require('./utils'); - -describe('getOptionsFromArguments', () => { - test('with a single option', () => { - expect( - utils.getOptionsFromArguments('cmd --appId APP_ID'.split(' ')) - ).toEqual({ - appId: 'APP_ID', - }); - }); - - test('with multiple options', () => { - expect( - utils.getOptionsFromArguments([ - 'cmd', - '--appId', - 'APP_ID', - '--apiKey', - 'API_KEY', - '--indexName', - 'INDEX_NAME', - '--template', - 'Vue InstantSearch', - ]) - ).toEqual({ - appId: 'APP_ID', - apiKey: 'API_KEY', - indexName: 'INDEX_NAME', - template: 'Vue InstantSearch', - }); - }); - - test('with different commands', () => { - expect( - utils.getOptionsFromArguments(['yarn', 'start', '--appId', 'APP_ID']) - ).toEqual({ - appId: 'APP_ID', - }); - - expect( - utils.getOptionsFromArguments(['node', 'index', '--appId', 'APP_ID']) - ).toEqual({ - appId: 'APP_ID', - }); - - expect( - utils.getOptionsFromArguments([ - 'npm', - 'init', - 'instantsearch-app', - '--appId', - 'APP_ID', - ]) - ).toEqual({ - appId: 'APP_ID', - }); - - expect( - utils.getOptionsFromArguments([ - 'yarn', - 'create', - 'instantsearch-app', - '--appId', - 'APP_ID', - ]) - ).toEqual({ - appId: 'APP_ID', - }); - - expect( - utils.getOptionsFromArguments([ - 'create-instantsearch-app', - '--appId', - 'APP_ID', - ]) - ).toEqual({ - appId: 'APP_ID', - }); - }); -}); - -describe('getAttributesFromAnswers', () => { - const algoliasearchSuccessFn = () => ({ - search: jest.fn(() => ({ - hits: [ - { - _highlightResult: { - brand: 'brand', - description: 'description', - name: 'name', - title: 'title', - }, - }, - ], - })), - }); - - const algoliasearchFailureFn = () => ({ - search: jest.fn(() => { - throw new Error(); - }), - }); - - test('with search success should fetch attributes', async () => { - const attributes = await utils.getAttributesFromAnswers({ - appId: 'appId', - apiKey: 'apiKey', - indexName: 'indexName', - algoliasearchFn: algoliasearchSuccessFn, - }); - - expect(attributes).toEqual(['title', 'name', 'description', 'brand']); - }); - - test('with search failure should return default attributes', async () => { - const attributes = await utils.getAttributesFromAnswers({ - appId: 'appId', - apiKey: 'apiKey', - indexName: 'indexName', - algoliasearchFn: algoliasearchFailureFn, - }); - - expect(attributes).toEqual(['title', 'name', 'description']); - }); -}); - -test('isQuestionAsked', () => { - expect( - utils.isQuestionAsked({ - question: { name: 'appId', validate: input => Boolean(input) }, - args: { appId: undefined }, - }) - ).toBe(true); - - expect( - utils.isQuestionAsked({ - question: { name: 'appId', validate: input => Boolean(input) }, - args: { appId: 'APP_ID' }, - }) - ).toBe(false); - - expect( - utils.isQuestionAsked({ - question: { - name: 'template', - validate: input => input !== 'InstantSearch.js', - }, - args: { template: 'InstantSearch.js' }, - }) - ).toBe(true); - - expect( - utils.isQuestionAsked({ - question: { - name: 'template', - validate: input => input === 'InstantSearch.js', - }, - args: { template: 'InstantSearch.js' }, - }) - ).toBe(false); - - expect( - utils.isQuestionAsked({ - question: { - name: 'mainAttribute', - }, - args: { indexName: 'INDEX_NAME' }, - }) - ).toBe(false); -}); - -describe('camelCase', () => { - test('with a single word', () => { - expect(utils.camelCase('test')).toBe('test'); - }); - - test('with a caret-separated word', () => { - expect(utils.camelCase('app-id')).toBe('appId'); - }); - - test('with a twice-caret-separated word', () => { - expect(utils.camelCase('instant-search-js')).toBe('instantSearchJs'); - }); -}); - -describe('getConfiguration', () => { - test('without template throws', async () => { - expect.assertions(1); - - try { - await utils.getConfiguration({}); - } catch (err) { - expect(err.message).toBe('The template is required in the config.'); - } - }); - - test('with template transforms to its relative path', async () => { - const configuration = await utils.getConfiguration({ - answers: { template: 'InstantSearch.js' }, - }); - - expect(configuration).toEqual( - expect.objectContaining({ - template: path.resolve('templates/InstantSearch.js'), - }) - ); - }); - - test('with options from arguments and prompt merge', async () => { - const configuration = await utils.getConfiguration({ - options: { - name: 'my-app', - }, - answers: { - template: 'InstantSearch.js', - libraryVersion: '1.0.0', - }, - }); - - expect(configuration).toEqual( - expect.objectContaining({ - name: 'my-app', - libraryVersion: '1.0.0', - }) - ); - }); - - test('with config file overrides all options', async () => { - const loadJsonFileFn = jest.fn(x => Promise.resolve(x)); - const ignoredOptions = { - libraryVersion: '2.0.0', - }; - const options = { - config: { - template: 'InstantSearch.js', - libraryVersion: '1.0.0', - }, - ...ignoredOptions, - }; - const answers = { - ignoredKey: 'ignoredValue', - }; - - const configuration = await utils.getConfiguration({ - options, - answers, - loadJsonFileFn, - }); - - expect(configuration).toEqual(expect.not.objectContaining(ignoredOptions)); - expect(configuration).toEqual(expect.not.objectContaining(answers)); - }); -}); diff --git a/packages/create-instantsearch-app/index.js b/packages/create-instantsearch-app/index.js deleted file mode 100644 index b189f0a2c..000000000 --- a/packages/create-instantsearch-app/index.js +++ /dev/null @@ -1,3 +0,0 @@ -const createInstantSearchApp = require('./createInstantSearchApp'); - -module.exports = createInstantSearchApp; diff --git a/scripts/e2e-templates.test.js b/scripts/e2e-templates.test.js index 93fdde63e..9d274991c 100644 --- a/scripts/e2e-templates.test.js +++ b/scripts/e2e-templates.test.js @@ -6,7 +6,7 @@ const { toMatchImageSnapshot } = require('jest-image-snapshot'); expect.extend({ toMatchImageSnapshot }); -const templatesFolder = path.join(__dirname, '../templates'); +const templatesFolder = path.join(__dirname, '../src/templates'); const templates = fs .readdirSync(templatesFolder) .map(name => path.join(templatesFolder, name)) diff --git a/scripts/release-templates.js b/scripts/release-templates.js index 94cb64676..6c7e32178 100644 --- a/scripts/release-templates.js +++ b/scripts/release-templates.js @@ -15,7 +15,7 @@ const path = require('path'); const { execSync } = require('child_process'); const chalk = require('chalk'); const latestSemver = require('latest-semver'); -const { fetchLibraryVersions } = require('../packages/shared/utils'); +const { fetchLibraryVersions } = require('../src/utils'); const createInstantSearchApp = require('../'); @@ -44,7 +44,7 @@ async function build() { { stdio: 'ignore' } ); - const templatesFolder = path.join(__dirname, '../templates'); + const templatesFolder = path.join(__dirname, '../src/templates'); const templates = fs .readdirSync(templatesFolder) .map(name => path.join(templatesFolder, name)) diff --git a/packages/create-instantsearch-app/__snapshots__/createInstantSearchApp.test.js.snap b/src/api/__tests__/__snapshots__/index.test.js.snap similarity index 100% rename from packages/create-instantsearch-app/__snapshots__/createInstantSearchApp.test.js.snap rename to src/api/__tests__/__snapshots__/index.test.js.snap diff --git a/packages/create-instantsearch-app/createInstantSearchApp.test.js b/src/api/__tests__/index.test.js similarity index 96% rename from packages/create-instantsearch-app/createInstantSearchApp.test.js rename to src/api/__tests__/index.test.js index dd6919d87..842855e39 100644 --- a/packages/create-instantsearch-app/createInstantSearchApp.test.js +++ b/src/api/__tests__/index.test.js @@ -1,5 +1,5 @@ const path = require('path'); -const createInstantSearchAppFactory = require('./createInstantSearchApp'); +const createInstantSearchAppFactory = require('../'); let setupSpy; let buildSpy; @@ -57,7 +57,7 @@ describe('Options', () => { test('with correct template path does not throw', () => { expect(() => { createInstantSearchApp('/tmp/test-app', { - template: path.resolve('./templates/InstantSearch.js'), + template: path.resolve('src/templates/InstantSearch.js'), }); }).not.toThrow(); }); @@ -96,7 +96,7 @@ describe('Tasks', () => { expect(buildSpy).toHaveBeenCalledWith({ path: '/tmp/test-app', name: 'test-app', - template: path.resolve('./templates/InstantSearch.js'), + template: path.resolve('src/templates/InstantSearch.js'), installation: true, libraryVersion: '2.0.0', silent: false, diff --git a/packages/create-instantsearch-app/createInstantSearchApp.js b/src/api/index.js old mode 100755 new mode 100644 similarity index 94% rename from packages/create-instantsearch-app/createInstantSearchApp.js rename to src/api/index.js index 9f36c8014..97acfc8f4 --- a/packages/create-instantsearch-app/createInstantSearchApp.js +++ b/src/api/index.js @@ -3,11 +3,7 @@ const path = require('path'); const buildTask = require('../tasks/common/build'); const cleanTask = require('../tasks/common/clean'); -const { - checkAppName, - checkAppPath, - getAllTemplates, -} = require('../shared/utils'); +const { checkAppName, checkAppPath, getAllTemplates } = require('../utils'); const allTemplates = getAllTemplates(); @@ -63,7 +59,7 @@ function createInstantSearchApp(appPath, options = {}, tasks = {}) { const config = { ...options, template: allTemplates.includes(options.template) - ? path.resolve('templates', options.template) + ? path.resolve('src/templates', options.template) : options.template, name: options.name || path.basename(appPath), installation: options.installation !== false, diff --git a/src/cli/__tests__/getAttributesFromIndex.test.js b/src/cli/__tests__/getAttributesFromIndex.test.js new file mode 100644 index 000000000..787b0b506 --- /dev/null +++ b/src/cli/__tests__/getAttributesFromIndex.test.js @@ -0,0 +1,48 @@ +const getAttributesFromIndex = require('../getAttributesFromIndex'); + +const algoliasearchSuccessFn = () => ({ + initIndex: () => ({ + search: jest.fn(() => ({ + hits: [ + { + _highlightResult: { + brand: 'brand', + description: 'description', + name: 'name', + title: 'title', + }, + }, + ], + })), + }), +}); + +const algoliasearchFailureFn = () => ({ + initIndex: () => ({ + search: jest.fn(() => { + throw new Error(); + }), + }), +}); + +test('with search success should fetch attributes', async () => { + const attributes = await getAttributesFromIndex({ + appId: 'appId', + apiKey: 'apiKey', + indexName: 'indexName', + algoliasearchFn: algoliasearchSuccessFn, + }); + + expect(attributes).toEqual(['title', 'name', 'description', 'brand']); +}); + +test('with search failure should return default attributes', async () => { + const attributes = await getAttributesFromIndex({ + appId: 'appId', + apiKey: 'apiKey', + indexName: 'indexName', + algoliasearchFn: algoliasearchFailureFn, + }); + + expect(attributes).toEqual(['title', 'name', 'description']); +}); diff --git a/src/cli/__tests__/getConfiguration.test.js b/src/cli/__tests__/getConfiguration.test.js new file mode 100644 index 000000000..d38c9fd94 --- /dev/null +++ b/src/cli/__tests__/getConfiguration.test.js @@ -0,0 +1,69 @@ +const path = require('path'); +const getConfiguration = require('../getConfiguration'); + +test('without template throws', async () => { + expect.assertions(1); + + try { + await getConfiguration({}); + } catch (err) { + expect(err.message).toBe('The template is required in the config.'); + } +}); + +test('with template transforms to its relative path', async () => { + const configuration = await getConfiguration({ + answers: { template: 'InstantSearch.js' }, + }); + + expect(configuration).toEqual( + expect.objectContaining({ + template: path.resolve('src/templates/InstantSearch.js'), + }) + ); +}); + +test('with options from arguments and prompt merge', async () => { + const configuration = await getConfiguration({ + options: { + name: 'my-app', + }, + answers: { + template: 'InstantSearch.js', + libraryVersion: '1.0.0', + }, + }); + + expect(configuration).toEqual( + expect.objectContaining({ + name: 'my-app', + libraryVersion: '1.0.0', + }) + ); +}); + +test('with config file overrides all options', async () => { + const loadJsonFileFn = jest.fn(x => Promise.resolve(x)); + const ignoredOptions = { + libraryVersion: '2.0.0', + }; + const options = { + config: { + template: 'InstantSearch.js', + libraryVersion: '1.0.0', + }, + ...ignoredOptions, + }; + const answers = { + ignoredKey: 'ignoredValue', + }; + + const configuration = await getConfiguration({ + options, + answers, + loadJsonFileFn, + }); + + expect(configuration).toEqual(expect.not.objectContaining(ignoredOptions)); + expect(configuration).toEqual(expect.not.objectContaining(answers)); +}); diff --git a/src/cli/__tests__/getOptionsFromArguments.test.js b/src/cli/__tests__/getOptionsFromArguments.test.js new file mode 100644 index 000000000..8604e4eed --- /dev/null +++ b/src/cli/__tests__/getOptionsFromArguments.test.js @@ -0,0 +1,72 @@ +const getOptionsFromArguments = require('../getOptionsFromArguments'); + +test('with a single option', () => { + expect(getOptionsFromArguments('cmd --appId APP_ID'.split(' '))).toEqual({ + appId: 'APP_ID', + }); +}); + +test('with multiple options', () => { + expect( + getOptionsFromArguments([ + 'cmd', + '--appId', + 'APP_ID', + '--apiKey', + 'API_KEY', + '--indexName', + 'INDEX_NAME', + '--template', + 'Vue InstantSearch', + ]) + ).toEqual({ + appId: 'APP_ID', + apiKey: 'API_KEY', + indexName: 'INDEX_NAME', + template: 'Vue InstantSearch', + }); +}); + +test('with different commands', () => { + expect( + getOptionsFromArguments(['yarn', 'start', '--appId', 'APP_ID']) + ).toEqual({ + appId: 'APP_ID', + }); + + expect( + getOptionsFromArguments(['node', 'index', '--appId', 'APP_ID']) + ).toEqual({ + appId: 'APP_ID', + }); + + expect( + getOptionsFromArguments([ + 'npm', + 'init', + 'instantsearch-app', + '--appId', + 'APP_ID', + ]) + ).toEqual({ + appId: 'APP_ID', + }); + + expect( + getOptionsFromArguments([ + 'yarn', + 'create', + 'instantsearch-app', + '--appId', + 'APP_ID', + ]) + ).toEqual({ + appId: 'APP_ID', + }); + + expect( + getOptionsFromArguments(['create-instantsearch-app', '--appId', 'APP_ID']) + ).toEqual({ + appId: 'APP_ID', + }); +}); diff --git a/src/cli/__tests__/isQuestionAsked.test.js b/src/cli/__tests__/isQuestionAsked.test.js new file mode 100644 index 000000000..e7c002c52 --- /dev/null +++ b/src/cli/__tests__/isQuestionAsked.test.js @@ -0,0 +1,54 @@ +const isQuestionAsked = require('../isQuestionAsked'); + +test('with appId undefined should ask', () => { + expect( + isQuestionAsked({ + question: { name: 'appId', validate: input => Boolean(input) }, + args: { appId: undefined }, + }) + ).toBe(true); +}); + +test('with appId defined should not ask', () => { + expect( + isQuestionAsked({ + question: { name: 'appId', validate: input => Boolean(input) }, + args: { appId: 'APP_ID' }, + }) + ).toBe(false); +}); + +test('with unvalid template should ask', () => { + expect( + isQuestionAsked({ + question: { + name: 'template', + validate: () => false, + }, + args: { template: 'Unvalid' }, + }) + ).toBe(true); +}); + +test('with valid template should not ask', () => { + expect( + isQuestionAsked({ + question: { + name: 'template', + validate: () => true, + }, + args: { template: 'InstantSearch.js' }, + }) + ).toBe(false); +}); + +test('with indexName should ask mainAttribute', () => { + expect( + isQuestionAsked({ + question: { + name: 'mainAttribute', + }, + args: { indexName: 'INDEX_NAME' }, + }) + ).toBe(false); +}); diff --git a/src/cli/getAttributesFromIndex.js b/src/cli/getAttributesFromIndex.js new file mode 100644 index 000000000..31ccffe1e --- /dev/null +++ b/src/cli/getAttributesFromIndex.js @@ -0,0 +1,33 @@ +const algoliasearch = require('algoliasearch'); + +module.exports = async function getAttributesFromIndex({ + appId, + apiKey, + indexName, + algoliasearchFn = algoliasearch, +} = {}) { + const client = algoliasearchFn(appId, apiKey); + const index = client.initIndex(indexName); + const defaultAttributes = ['title', 'name', 'description']; + let attributes = []; + + try { + const { hits } = await index.search({ hitsPerPage: 1 }); + const [firstHit] = hits; + const highlightedAttributes = Object.keys(firstHit._highlightResult); + attributes = [ + ...new Set([ + ...defaultAttributes + .map( + attribute => highlightedAttributes.includes(attribute) && attribute + ) + .filter(Boolean), + ...highlightedAttributes, + ]), + ]; + } catch (err) { + attributes = defaultAttributes; + } + + return attributes; +}; diff --git a/src/cli/getConfiguration.js b/src/cli/getConfiguration.js new file mode 100644 index 000000000..a576f16da --- /dev/null +++ b/src/cli/getConfiguration.js @@ -0,0 +1,39 @@ +const latestSemver = require('latest-semver'); +const loadJsonFile = require('load-json-file'); + +const { + getAppTemplateConfig, + fetchLibraryVersions, + getTemplatePath, +} = require('../utils'); + +module.exports = async function getConfiguration({ + options = {}, + answers = {}, + loadJsonFileFn = loadJsonFile, +} = {}) { + const config = options.config + ? await loadJsonFileFn(options.config) // From configuration file given as an argument + : { ...options, ...answers }; // From the arguments and the prompt + + if (!config.template) { + throw new Error('The template is required in the config.'); + } + + const templatePath = getTemplatePath(config.template); + let { libraryVersion } = config; + + if (!libraryVersion) { + const templateConfig = getAppTemplateConfig(templatePath); + + libraryVersion = await fetchLibraryVersions( + templateConfig.libraryName + ).then(latestSemver); + } + + return { + ...config, + libraryVersion, + template: templatePath, + }; +}; diff --git a/src/cli/getOptionsFromArguments.js b/src/cli/getOptionsFromArguments.js new file mode 100644 index 000000000..07804d5b9 --- /dev/null +++ b/src/cli/getOptionsFromArguments.js @@ -0,0 +1,21 @@ +const camelCase = require('lodash.camelcase'); + +module.exports = function getOptionsFromArguments(rawArgs) { + let argIndex = 0; + + return rawArgs.reduce((allArgs, currentArg) => { + argIndex++; + + if (!currentArg.startsWith('--') || currentArg.startsWith('--no-')) { + return allArgs; + } + + const argumentName = camelCase(currentArg.split('--')[1]); + const argumentValue = rawArgs[argIndex]; + + return { + ...allArgs, + [argumentName]: argumentValue, + }; + }, {}); +}; diff --git a/packages/cli/cli.js b/src/cli/index.js old mode 100644 new mode 100755 similarity index 88% rename from packages/cli/cli.js rename to src/cli/index.js index 733d29272..c5dfe0542 --- a/packages/cli/cli.js +++ b/src/cli/index.js @@ -1,3 +1,4 @@ +#!/usr/bin/env node const path = require('path'); const process = require('process'); const program = require('commander'); @@ -5,7 +6,7 @@ const inquirer = require('inquirer'); const chalk = require('chalk'); const latestSemver = require('latest-semver'); -const createInstantSearchApp = require('../create-instantsearch-app'); +const createInstantSearchApp = require('../api'); const { checkAppPath, checkAppName, @@ -13,13 +14,11 @@ const { fetchLibraryVersions, getAllTemplates, getTemplatePath, -} = require('../shared/utils'); -const { - getOptionsFromArguments, - getAttributesFromAnswers, - isQuestionAsked, - getConfiguration, -} = require('./utils'); +} = require('../utils'); +const getOptionsFromArguments = require('./getOptionsFromArguments'); +const getAttributesFromIndex = require('./getAttributesFromIndex'); +const isQuestionAsked = require('./isQuestionAsked'); +const getConfiguration = require('./getConfiguration'); const { version } = require('../../package.json'); let appPath; @@ -165,8 +164,16 @@ const questions = [ { type: 'list', name: 'mainAttribute', - message: 'Attribute to display', - choices: async answers => await getAttributesFromAnswers(answers), + message: 'Attribute to highlight', + choices: async answers => [ + { + name: 'None', + value: undefined, + }, + new inquirer.Separator(), + new inquirer.Separator('From your index'), + ...(await getAttributesFromIndex(answers)), + ], when: ({ appId, apiKey, indexName }) => appId && apiKey && indexName, }, ].filter(question => isQuestionAsked({ question, args: optionsFromArguments })); diff --git a/src/cli/isQuestionAsked.js b/src/cli/isQuestionAsked.js new file mode 100644 index 000000000..57c480b67 --- /dev/null +++ b/src/cli/isQuestionAsked.js @@ -0,0 +1,22 @@ +module.exports = function isQuestionAsked({ question, args }) { + if (args.config) { + return false; + } + + for (const optionName in args) { + if (question.name === optionName) { + // Skip if the arg in the command is valid + if ( + !question.validate || + (question.validate && question.validate(args[optionName])) + ) { + return false; + } + } else if (!question.validate) { + // Skip if the question is optional and not given in the command + return false; + } + } + + return true; +}; diff --git a/packages/tasks/common/build.js b/src/tasks/common/build.js similarity index 100% rename from packages/tasks/common/build.js rename to src/tasks/common/build.js diff --git a/packages/tasks/common/clean.js b/src/tasks/common/clean.js similarity index 100% rename from packages/tasks/common/clean.js rename to src/tasks/common/clean.js diff --git a/packages/tasks/node/install.js b/src/tasks/node/install.js similarity index 95% rename from packages/tasks/node/install.js rename to src/tasks/node/install.js index 8c6004112..9bcffb89f 100644 --- a/packages/tasks/node/install.js +++ b/src/tasks/node/install.js @@ -1,7 +1,7 @@ const process = require('process'); const { execSync } = require('child_process'); const chalk = require('chalk'); -const { isYarnAvailable } = require('../../shared/utils'); +const { isYarnAvailable } = require('../../utils'); module.exports = function install(config) { const logger = config.silent ? { log() {}, error() {} } : console; diff --git a/packages/tasks/node/teardown.js b/src/tasks/node/teardown.js similarity index 95% rename from packages/tasks/node/teardown.js rename to src/tasks/node/teardown.js index 30e242b5b..12bd5f4e6 100644 --- a/packages/tasks/node/teardown.js +++ b/src/tasks/node/teardown.js @@ -1,6 +1,6 @@ const path = require('path'); const chalk = require('chalk'); -const { isYarnAvailable } = require('../../shared/utils'); +const { isYarnAvailable } = require('../../utils'); module.exports = function teardown(config) { if (!config.silent) { diff --git a/templates/Angular InstantSearch/.gitignore.template b/src/templates/Angular InstantSearch/.gitignore.template similarity index 100% rename from templates/Angular InstantSearch/.gitignore.template rename to src/templates/Angular InstantSearch/.gitignore.template diff --git a/templates/Angular InstantSearch/.template.js b/src/templates/Angular InstantSearch/.template.js similarity index 67% rename from templates/Angular InstantSearch/.template.js rename to src/templates/Angular InstantSearch/.template.js index d79a6c590..84112021a 100644 --- a/templates/Angular InstantSearch/.template.js +++ b/src/templates/Angular InstantSearch/.template.js @@ -1,5 +1,5 @@ -const install = require('../../packages/tasks/node/install'); -const teardown = require('../../packages/tasks/node/teardown'); +const install = require('../../tasks/node/install'); +const teardown = require('../../tasks/node/teardown'); module.exports = { libraryName: 'angular-instantsearch', diff --git a/templates/Angular InstantSearch/README.md b/src/templates/Angular InstantSearch/README.md similarity index 100% rename from templates/Angular InstantSearch/README.md rename to src/templates/Angular InstantSearch/README.md diff --git a/templates/Angular InstantSearch/angular.json b/src/templates/Angular InstantSearch/angular.json similarity index 100% rename from templates/Angular InstantSearch/angular.json rename to src/templates/Angular InstantSearch/angular.json diff --git a/templates/Angular InstantSearch/e2e/protractor.conf.js b/src/templates/Angular InstantSearch/e2e/protractor.conf.js similarity index 100% rename from templates/Angular InstantSearch/e2e/protractor.conf.js rename to src/templates/Angular InstantSearch/e2e/protractor.conf.js diff --git a/templates/Angular InstantSearch/e2e/src/app.e2e-spec.ts b/src/templates/Angular InstantSearch/e2e/src/app.e2e-spec.ts similarity index 100% rename from templates/Angular InstantSearch/e2e/src/app.e2e-spec.ts rename to src/templates/Angular InstantSearch/e2e/src/app.e2e-spec.ts diff --git a/templates/Angular InstantSearch/e2e/src/app.po.ts b/src/templates/Angular InstantSearch/e2e/src/app.po.ts similarity index 100% rename from templates/Angular InstantSearch/e2e/src/app.po.ts rename to src/templates/Angular InstantSearch/e2e/src/app.po.ts diff --git a/templates/Angular InstantSearch/e2e/tsconfig.e2e.json b/src/templates/Angular InstantSearch/e2e/tsconfig.e2e.json similarity index 100% rename from templates/Angular InstantSearch/e2e/tsconfig.e2e.json rename to src/templates/Angular InstantSearch/e2e/tsconfig.e2e.json diff --git a/templates/Angular InstantSearch/package.json b/src/templates/Angular InstantSearch/package.json similarity index 100% rename from templates/Angular InstantSearch/package.json rename to src/templates/Angular InstantSearch/package.json diff --git a/templates/Angular InstantSearch/src/app/app.component.css b/src/templates/Angular InstantSearch/src/app/app.component.css similarity index 100% rename from templates/Angular InstantSearch/src/app/app.component.css rename to src/templates/Angular InstantSearch/src/app/app.component.css diff --git a/templates/Angular InstantSearch/src/app/app.component.html.hbs b/src/templates/Angular InstantSearch/src/app/app.component.html.hbs similarity index 100% rename from templates/Angular InstantSearch/src/app/app.component.html.hbs rename to src/templates/Angular InstantSearch/src/app/app.component.html.hbs diff --git a/templates/Angular InstantSearch/src/app/app.component.spec.ts b/src/templates/Angular InstantSearch/src/app/app.component.spec.ts similarity index 100% rename from templates/Angular InstantSearch/src/app/app.component.spec.ts rename to src/templates/Angular InstantSearch/src/app/app.component.spec.ts diff --git a/templates/Angular InstantSearch/src/app/app.component.ts b/src/templates/Angular InstantSearch/src/app/app.component.ts similarity index 100% rename from templates/Angular InstantSearch/src/app/app.component.ts rename to src/templates/Angular InstantSearch/src/app/app.component.ts diff --git a/templates/Angular InstantSearch/src/app/app.module.ts b/src/templates/Angular InstantSearch/src/app/app.module.ts similarity index 100% rename from templates/Angular InstantSearch/src/app/app.module.ts rename to src/templates/Angular InstantSearch/src/app/app.module.ts diff --git a/templates/Angular InstantSearch/src/assets/.gitkeep b/src/templates/Angular InstantSearch/src/assets/.gitkeep similarity index 100% rename from templates/Angular InstantSearch/src/assets/.gitkeep rename to src/templates/Angular InstantSearch/src/assets/.gitkeep diff --git a/templates/Angular InstantSearch/src/browserslist b/src/templates/Angular InstantSearch/src/browserslist similarity index 100% rename from templates/Angular InstantSearch/src/browserslist rename to src/templates/Angular InstantSearch/src/browserslist diff --git a/templates/Angular InstantSearch/src/environments/environment.prod.ts b/src/templates/Angular InstantSearch/src/environments/environment.prod.ts similarity index 100% rename from templates/Angular InstantSearch/src/environments/environment.prod.ts rename to src/templates/Angular InstantSearch/src/environments/environment.prod.ts diff --git a/templates/Angular InstantSearch/src/environments/environment.ts b/src/templates/Angular InstantSearch/src/environments/environment.ts similarity index 100% rename from templates/Angular InstantSearch/src/environments/environment.ts rename to src/templates/Angular InstantSearch/src/environments/environment.ts diff --git a/templates/Angular InstantSearch/src/favicon.png b/src/templates/Angular InstantSearch/src/favicon.png similarity index 100% rename from templates/Angular InstantSearch/src/favicon.png rename to src/templates/Angular InstantSearch/src/favicon.png diff --git a/templates/Angular InstantSearch/src/index.html b/src/templates/Angular InstantSearch/src/index.html similarity index 100% rename from templates/Angular InstantSearch/src/index.html rename to src/templates/Angular InstantSearch/src/index.html diff --git a/templates/Angular InstantSearch/src/karma.conf.js b/src/templates/Angular InstantSearch/src/karma.conf.js similarity index 100% rename from templates/Angular InstantSearch/src/karma.conf.js rename to src/templates/Angular InstantSearch/src/karma.conf.js diff --git a/templates/Angular InstantSearch/src/main.ts b/src/templates/Angular InstantSearch/src/main.ts similarity index 100% rename from templates/Angular InstantSearch/src/main.ts rename to src/templates/Angular InstantSearch/src/main.ts diff --git a/templates/Angular InstantSearch/src/manifest.json b/src/templates/Angular InstantSearch/src/manifest.json similarity index 100% rename from templates/Angular InstantSearch/src/manifest.json rename to src/templates/Angular InstantSearch/src/manifest.json diff --git a/templates/Angular InstantSearch/src/polyfills.ts b/src/templates/Angular InstantSearch/src/polyfills.ts similarity index 100% rename from templates/Angular InstantSearch/src/polyfills.ts rename to src/templates/Angular InstantSearch/src/polyfills.ts diff --git a/templates/Angular InstantSearch/src/styles.css b/src/templates/Angular InstantSearch/src/styles.css similarity index 100% rename from templates/Angular InstantSearch/src/styles.css rename to src/templates/Angular InstantSearch/src/styles.css diff --git a/templates/Angular InstantSearch/src/test.ts b/src/templates/Angular InstantSearch/src/test.ts similarity index 100% rename from templates/Angular InstantSearch/src/test.ts rename to src/templates/Angular InstantSearch/src/test.ts diff --git a/templates/Angular InstantSearch/src/tsconfig.app.json b/src/templates/Angular InstantSearch/src/tsconfig.app.json similarity index 100% rename from templates/Angular InstantSearch/src/tsconfig.app.json rename to src/templates/Angular InstantSearch/src/tsconfig.app.json diff --git a/templates/Angular InstantSearch/src/tsconfig.spec.json b/src/templates/Angular InstantSearch/src/tsconfig.spec.json similarity index 100% rename from templates/Angular InstantSearch/src/tsconfig.spec.json rename to src/templates/Angular InstantSearch/src/tsconfig.spec.json diff --git a/templates/Angular InstantSearch/src/tslint.json b/src/templates/Angular InstantSearch/src/tslint.json similarity index 100% rename from templates/Angular InstantSearch/src/tslint.json rename to src/templates/Angular InstantSearch/src/tslint.json diff --git a/templates/Angular InstantSearch/tsconfig.json b/src/templates/Angular InstantSearch/tsconfig.json similarity index 100% rename from templates/Angular InstantSearch/tsconfig.json rename to src/templates/Angular InstantSearch/tsconfig.json diff --git a/templates/Angular InstantSearch/tslint.json b/src/templates/Angular InstantSearch/tslint.json similarity index 100% rename from templates/Angular InstantSearch/tslint.json rename to src/templates/Angular InstantSearch/tslint.json diff --git a/templates/InstantSearch.js/.editorconfig b/src/templates/InstantSearch.js/.editorconfig similarity index 100% rename from templates/InstantSearch.js/.editorconfig rename to src/templates/InstantSearch.js/.editorconfig diff --git a/templates/InstantSearch.js/.eslintignore b/src/templates/InstantSearch.js/.eslintignore similarity index 100% rename from templates/InstantSearch.js/.eslintignore rename to src/templates/InstantSearch.js/.eslintignore diff --git a/templates/InstantSearch.js/.eslintrc.js b/src/templates/InstantSearch.js/.eslintrc.js similarity index 100% rename from templates/InstantSearch.js/.eslintrc.js rename to src/templates/InstantSearch.js/.eslintrc.js diff --git a/templates/InstantSearch.js/.gitignore.template b/src/templates/InstantSearch.js/.gitignore.template similarity index 100% rename from templates/InstantSearch.js/.gitignore.template rename to src/templates/InstantSearch.js/.gitignore.template diff --git a/templates/InstantSearch.js/.prettierrc b/src/templates/InstantSearch.js/.prettierrc similarity index 100% rename from templates/InstantSearch.js/.prettierrc rename to src/templates/InstantSearch.js/.prettierrc diff --git a/templates/InstantSearch.js/.template.js b/src/templates/InstantSearch.js/.template.js similarity index 66% rename from templates/InstantSearch.js/.template.js rename to src/templates/InstantSearch.js/.template.js index 2404902a8..2536d5dae 100644 --- a/templates/InstantSearch.js/.template.js +++ b/src/templates/InstantSearch.js/.template.js @@ -1,5 +1,5 @@ -const install = require('../../packages/tasks/node/install'); -const teardown = require('../../packages/tasks/node/teardown'); +const install = require('../../tasks/node/install'); +const teardown = require('../../tasks/node/teardown'); module.exports = { libraryName: 'instantsearch.js', diff --git a/templates/InstantSearch.js/README.md b/src/templates/InstantSearch.js/README.md similarity index 100% rename from templates/InstantSearch.js/README.md rename to src/templates/InstantSearch.js/README.md diff --git a/templates/InstantSearch.js/favicon.png b/src/templates/InstantSearch.js/favicon.png similarity index 100% rename from templates/InstantSearch.js/favicon.png rename to src/templates/InstantSearch.js/favicon.png diff --git a/templates/InstantSearch.js/index.html.hbs b/src/templates/InstantSearch.js/index.html.hbs similarity index 100% rename from templates/InstantSearch.js/index.html.hbs rename to src/templates/InstantSearch.js/index.html.hbs diff --git a/templates/InstantSearch.js/manifest.webmanifest b/src/templates/InstantSearch.js/manifest.webmanifest similarity index 100% rename from templates/InstantSearch.js/manifest.webmanifest rename to src/templates/InstantSearch.js/manifest.webmanifest diff --git a/templates/InstantSearch.js/package.json b/src/templates/InstantSearch.js/package.json similarity index 100% rename from templates/InstantSearch.js/package.json rename to src/templates/InstantSearch.js/package.json diff --git a/templates/InstantSearch.js/src/app.css b/src/templates/InstantSearch.js/src/app.css similarity index 100% rename from templates/InstantSearch.js/src/app.css rename to src/templates/InstantSearch.js/src/app.css diff --git a/templates/InstantSearch.js/src/app.js.hbs b/src/templates/InstantSearch.js/src/app.js.hbs similarity index 100% rename from templates/InstantSearch.js/src/app.js.hbs rename to src/templates/InstantSearch.js/src/app.js.hbs diff --git a/templates/InstantSearch.js/src/index.css b/src/templates/InstantSearch.js/src/index.css similarity index 100% rename from templates/InstantSearch.js/src/index.css rename to src/templates/InstantSearch.js/src/index.css diff --git a/templates/React InstantSearch Native/.babelrc.template b/src/templates/React InstantSearch Native/.babelrc.template similarity index 100% rename from templates/React InstantSearch Native/.babelrc.template rename to src/templates/React InstantSearch Native/.babelrc.template diff --git a/templates/React InstantSearch Native/.editorconfig b/src/templates/React InstantSearch Native/.editorconfig similarity index 100% rename from templates/React InstantSearch Native/.editorconfig rename to src/templates/React InstantSearch Native/.editorconfig diff --git a/templates/React InstantSearch Native/.eslintrc.js b/src/templates/React InstantSearch Native/.eslintrc.js similarity index 100% rename from templates/React InstantSearch Native/.eslintrc.js rename to src/templates/React InstantSearch Native/.eslintrc.js diff --git a/templates/React InstantSearch Native/.gitignore.template b/src/templates/React InstantSearch Native/.gitignore.template similarity index 100% rename from templates/React InstantSearch Native/.gitignore.template rename to src/templates/React InstantSearch Native/.gitignore.template diff --git a/templates/React InstantSearch Native/.prettierrc b/src/templates/React InstantSearch Native/.prettierrc similarity index 100% rename from templates/React InstantSearch Native/.prettierrc rename to src/templates/React InstantSearch Native/.prettierrc diff --git a/templates/React InstantSearch Native/.template.js b/src/templates/React InstantSearch Native/.template.js similarity index 84% rename from templates/React InstantSearch Native/.template.js rename to src/templates/React InstantSearch Native/.template.js index 376d8e696..2f2f2ec54 100644 --- a/templates/React InstantSearch Native/.template.js +++ b/src/templates/React InstantSearch Native/.template.js @@ -1,6 +1,6 @@ const chalk = require('chalk'); -const install = require('../../packages/tasks/node/install'); -const teardown = require('../../packages/tasks/node/teardown'); +const install = require('../../tasks/node/install'); +const teardown = require('../../tasks/node/teardown'); module.exports = { libraryName: 'react-instantsearch-native', diff --git a/templates/React InstantSearch Native/.watchmanconfig b/src/templates/React InstantSearch Native/.watchmanconfig similarity index 100% rename from templates/React InstantSearch Native/.watchmanconfig rename to src/templates/React InstantSearch Native/.watchmanconfig diff --git a/templates/React InstantSearch Native/App.js.hbs b/src/templates/React InstantSearch Native/App.js.hbs similarity index 100% rename from templates/React InstantSearch Native/App.js.hbs rename to src/templates/React InstantSearch Native/App.js.hbs diff --git a/templates/React InstantSearch Native/README.md b/src/templates/React InstantSearch Native/README.md similarity index 100% rename from templates/React InstantSearch Native/README.md rename to src/templates/React InstantSearch Native/README.md diff --git a/templates/React InstantSearch Native/app.json b/src/templates/React InstantSearch Native/app.json similarity index 100% rename from templates/React InstantSearch Native/app.json rename to src/templates/React InstantSearch Native/app.json diff --git a/templates/React InstantSearch Native/package.json b/src/templates/React InstantSearch Native/package.json similarity index 100% rename from templates/React InstantSearch Native/package.json rename to src/templates/React InstantSearch Native/package.json diff --git a/templates/React InstantSearch Native/src/Highlight.js b/src/templates/React InstantSearch Native/src/Highlight.js similarity index 100% rename from templates/React InstantSearch Native/src/Highlight.js rename to src/templates/React InstantSearch Native/src/Highlight.js diff --git a/templates/React InstantSearch Native/src/InfiniteHits.js.hbs b/src/templates/React InstantSearch Native/src/InfiniteHits.js.hbs similarity index 100% rename from templates/React InstantSearch Native/src/InfiniteHits.js.hbs rename to src/templates/React InstantSearch Native/src/InfiniteHits.js.hbs diff --git a/templates/React InstantSearch Native/src/SearchBox.js.hbs b/src/templates/React InstantSearch Native/src/SearchBox.js.hbs similarity index 100% rename from templates/React InstantSearch Native/src/SearchBox.js.hbs rename to src/templates/React InstantSearch Native/src/SearchBox.js.hbs diff --git a/templates/React InstantSearch/.editorconfig b/src/templates/React InstantSearch/.editorconfig similarity index 100% rename from templates/React InstantSearch/.editorconfig rename to src/templates/React InstantSearch/.editorconfig diff --git a/templates/React InstantSearch/.eslintrc.js b/src/templates/React InstantSearch/.eslintrc.js similarity index 100% rename from templates/React InstantSearch/.eslintrc.js rename to src/templates/React InstantSearch/.eslintrc.js diff --git a/templates/React InstantSearch/.gitignore.template b/src/templates/React InstantSearch/.gitignore.template similarity index 100% rename from templates/React InstantSearch/.gitignore.template rename to src/templates/React InstantSearch/.gitignore.template diff --git a/templates/React InstantSearch/.prettierrc b/src/templates/React InstantSearch/.prettierrc similarity index 100% rename from templates/React InstantSearch/.prettierrc rename to src/templates/React InstantSearch/.prettierrc diff --git a/templates/React InstantSearch/.template.js b/src/templates/React InstantSearch/.template.js similarity index 66% rename from templates/React InstantSearch/.template.js rename to src/templates/React InstantSearch/.template.js index 189b5dae6..34128a56e 100644 --- a/templates/React InstantSearch/.template.js +++ b/src/templates/React InstantSearch/.template.js @@ -1,5 +1,5 @@ -const install = require('../../packages/tasks/node/install'); -const teardown = require('../../packages/tasks/node/teardown'); +const install = require('../../tasks/node/install'); +const teardown = require('../../tasks/node/teardown'); module.exports = { libraryName: 'react-instantsearch', diff --git a/templates/React InstantSearch/README.md b/src/templates/React InstantSearch/README.md similarity index 100% rename from templates/React InstantSearch/README.md rename to src/templates/React InstantSearch/README.md diff --git a/templates/React InstantSearch/package.json b/src/templates/React InstantSearch/package.json similarity index 100% rename from templates/React InstantSearch/package.json rename to src/templates/React InstantSearch/package.json diff --git a/templates/React InstantSearch/public/favicon.png b/src/templates/React InstantSearch/public/favicon.png similarity index 100% rename from templates/React InstantSearch/public/favicon.png rename to src/templates/React InstantSearch/public/favicon.png diff --git a/templates/React InstantSearch/public/index.html b/src/templates/React InstantSearch/public/index.html similarity index 100% rename from templates/React InstantSearch/public/index.html rename to src/templates/React InstantSearch/public/index.html diff --git a/templates/React InstantSearch/public/manifest.json b/src/templates/React InstantSearch/public/manifest.json similarity index 100% rename from templates/React InstantSearch/public/manifest.json rename to src/templates/React InstantSearch/public/manifest.json diff --git a/templates/React InstantSearch/src/App.css b/src/templates/React InstantSearch/src/App.css similarity index 100% rename from templates/React InstantSearch/src/App.css rename to src/templates/React InstantSearch/src/App.css diff --git a/templates/React InstantSearch/src/App.js.hbs b/src/templates/React InstantSearch/src/App.js.hbs similarity index 100% rename from templates/React InstantSearch/src/App.js.hbs rename to src/templates/React InstantSearch/src/App.js.hbs diff --git a/templates/React InstantSearch/src/index.css b/src/templates/React InstantSearch/src/index.css similarity index 100% rename from templates/React InstantSearch/src/index.css rename to src/templates/React InstantSearch/src/index.css diff --git a/templates/React InstantSearch/src/index.js b/src/templates/React InstantSearch/src/index.js similarity index 100% rename from templates/React InstantSearch/src/index.js rename to src/templates/React InstantSearch/src/index.js diff --git a/templates/Vue InstantSearch/.babelrc.template b/src/templates/Vue InstantSearch/.babelrc.template similarity index 100% rename from templates/Vue InstantSearch/.babelrc.template rename to src/templates/Vue InstantSearch/.babelrc.template diff --git a/templates/Vue InstantSearch/.editorconfig b/src/templates/Vue InstantSearch/.editorconfig similarity index 100% rename from templates/Vue InstantSearch/.editorconfig rename to src/templates/Vue InstantSearch/.editorconfig diff --git a/templates/Vue InstantSearch/.eslintrc.js b/src/templates/Vue InstantSearch/.eslintrc.js similarity index 100% rename from templates/Vue InstantSearch/.eslintrc.js rename to src/templates/Vue InstantSearch/.eslintrc.js diff --git a/templates/Vue InstantSearch/.gitignore.template b/src/templates/Vue InstantSearch/.gitignore.template similarity index 100% rename from templates/Vue InstantSearch/.gitignore.template rename to src/templates/Vue InstantSearch/.gitignore.template diff --git a/templates/Vue InstantSearch/.template.js b/src/templates/Vue InstantSearch/.template.js similarity index 66% rename from templates/Vue InstantSearch/.template.js rename to src/templates/Vue InstantSearch/.template.js index bc9224a98..35998b3a0 100644 --- a/templates/Vue InstantSearch/.template.js +++ b/src/templates/Vue InstantSearch/.template.js @@ -1,5 +1,5 @@ -const install = require('../../packages/tasks/node/install'); -const teardown = require('../../packages/tasks/node/teardown'); +const install = require('../../tasks/node/install'); +const teardown = require('../../tasks/node/teardown'); module.exports = { libraryName: 'vue-instantsearch', diff --git a/templates/Vue InstantSearch/README.md b/src/templates/Vue InstantSearch/README.md similarity index 100% rename from templates/Vue InstantSearch/README.md rename to src/templates/Vue InstantSearch/README.md diff --git a/templates/Vue InstantSearch/favicon.png b/src/templates/Vue InstantSearch/favicon.png similarity index 100% rename from templates/Vue InstantSearch/favicon.png rename to src/templates/Vue InstantSearch/favicon.png diff --git a/templates/Vue InstantSearch/index.html b/src/templates/Vue InstantSearch/index.html similarity index 100% rename from templates/Vue InstantSearch/index.html rename to src/templates/Vue InstantSearch/index.html diff --git a/templates/Vue InstantSearch/manifest.json b/src/templates/Vue InstantSearch/manifest.json similarity index 100% rename from templates/Vue InstantSearch/manifest.json rename to src/templates/Vue InstantSearch/manifest.json diff --git a/templates/Vue InstantSearch/package.json b/src/templates/Vue InstantSearch/package.json similarity index 100% rename from templates/Vue InstantSearch/package.json rename to src/templates/Vue InstantSearch/package.json diff --git a/templates/Vue InstantSearch/src/App.vue b/src/templates/Vue InstantSearch/src/App.vue similarity index 100% rename from templates/Vue InstantSearch/src/App.vue rename to src/templates/Vue InstantSearch/src/App.vue diff --git a/templates/Vue InstantSearch/src/main.js b/src/templates/Vue InstantSearch/src/main.js similarity index 100% rename from templates/Vue InstantSearch/src/main.js rename to src/templates/Vue InstantSearch/src/main.js diff --git a/templates/Vue InstantSearch/webpack.config.js b/src/templates/Vue InstantSearch/webpack.config.js similarity index 100% rename from templates/Vue InstantSearch/webpack.config.js rename to src/templates/Vue InstantSearch/webpack.config.js diff --git a/packages/shared/__snapshots__/utils.test.js.snap b/src/utils/__tests__/__snapshots__/index.test.js.snap similarity index 100% rename from packages/shared/__snapshots__/utils.test.js.snap rename to src/utils/__tests__/__snapshots__/index.test.js.snap diff --git a/packages/shared/utils.test.js b/src/utils/__tests__/index.test.js similarity index 98% rename from packages/shared/utils.test.js rename to src/utils/__tests__/index.test.js index 3a45c301e..9844abe07 100644 --- a/packages/shared/utils.test.js +++ b/src/utils/__tests__/index.test.js @@ -8,7 +8,7 @@ jest.mock('fs', () => ({ readdirSync: mockReaddirSync, })); -const utils = require('./utils'); +const utils = require('../'); describe('checkAppName', () => { test('does not throw when valid', () => { diff --git a/packages/shared/utils.js b/src/utils/index.js similarity index 97% rename from packages/shared/utils.js rename to src/utils/index.js index 7345baa56..d97433d81 100644 --- a/packages/shared/utils.js +++ b/src/utils/index.js @@ -5,7 +5,7 @@ const chalk = require('chalk'); const validateProjectName = require('validate-npm-package-name'); const algoliasearch = require('algoliasearch'); -const TEMPLATES_FOLDER = path.join(__dirname, '../../templates'); +const TEMPLATES_FOLDER = path.join(__dirname, '../templates'); const algoliaConfig = { appId: 'OFCNCOG2CU', diff --git a/yarn.lock b/yarn.lock index 0bbf95dfc..ccc6923a2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3754,6 +3754,10 @@ lodash._reinterpolate@~3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d" +lodash.camelcase@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6" + lodash.sortby@^4.7.0: version "4.7.0" resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"