From 29ee448bd978bc6f127be57866181efc780da0c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Thu, 14 Jun 2018 14:59:18 +0200 Subject: [PATCH 1/5] refactor: Setup new architeture --- packages/cli/index.js | 4 ---- packages/create-instantsearch-app/index.js | 3 --- .../createInstantSearchApp.test.js.snap | 0 .../api/__tests__/index.test.js | 0 .../createInstantSearchApp.js => src/api/index.js | 3 +++ {packages/cli => src/cli/__tests__}/utils.test.js | 0 packages/cli/cli.js => src/cli/index.js | 1 + {packages => src}/cli/utils.js | 0 {packages => src}/tasks/common/build.js | 0 {packages => src}/tasks/common/clean.js | 0 {packages => src}/tasks/node/install.js | 0 {packages => src}/tasks/node/teardown.js | 0 .../Angular InstantSearch/.gitignore.template | 0 .../templates}/Angular InstantSearch/.template.js | 0 .../templates}/Angular InstantSearch/README.md | 0 .../templates}/Angular InstantSearch/angular.json | 0 .../Angular InstantSearch/e2e/protractor.conf.js | 0 .../Angular InstantSearch/e2e/src/app.e2e-spec.ts | 0 .../Angular InstantSearch/e2e/src/app.po.ts | 0 .../Angular InstantSearch/e2e/tsconfig.e2e.json | 0 .../templates}/Angular InstantSearch/package.json | 0 .../Angular InstantSearch/src/app/app.component.css | 0 .../src/app/app.component.html.hbs | 0 .../src/app/app.component.spec.ts | 0 .../Angular InstantSearch/src/app/app.component.ts | 0 .../Angular InstantSearch/src/app/app.module.ts | 0 .../Angular InstantSearch/src/assets/.gitkeep | 0 .../Angular InstantSearch/src/browserslist | 0 .../src/environments/environment.prod.ts | 0 .../src/environments/environment.ts | 0 .../Angular InstantSearch/src/favicon.png | Bin .../templates}/Angular InstantSearch/src/index.html | 0 .../Angular InstantSearch/src/karma.conf.js | 0 .../templates}/Angular InstantSearch/src/main.ts | 0 .../Angular InstantSearch/src/manifest.json | 0 .../Angular InstantSearch/src/polyfills.ts | 0 .../templates}/Angular InstantSearch/src/styles.css | 0 .../templates}/Angular InstantSearch/src/test.ts | 0 .../Angular InstantSearch/src/tsconfig.app.json | 0 .../Angular InstantSearch/src/tsconfig.spec.json | 0 .../Angular InstantSearch/src/tslint.json | 0 .../templates}/Angular InstantSearch/tsconfig.json | 0 .../templates}/Angular InstantSearch/tslint.json | 0 .../templates}/InstantSearch.js/.editorconfig | 0 .../templates}/InstantSearch.js/.eslintignore | 0 .../templates}/InstantSearch.js/.eslintrc.js | 0 .../templates}/InstantSearch.js/.gitignore.template | 0 .../templates}/InstantSearch.js/.prettierrc | 0 .../templates}/InstantSearch.js/.template.js | 0 .../templates}/InstantSearch.js/README.md | 0 .../templates}/InstantSearch.js/favicon.png | Bin .../templates}/InstantSearch.js/index.html.hbs | 0 .../InstantSearch.js/manifest.webmanifest | 0 .../templates}/InstantSearch.js/package.json | 0 .../templates}/InstantSearch.js/src/app.css | 0 .../templates}/InstantSearch.js/src/app.js.hbs | 0 .../templates}/InstantSearch.js/src/index.css | 0 .../templates}/React InstantSearch/.editorconfig | 0 .../templates}/React InstantSearch/.eslintrc.js | 0 .../React InstantSearch/.gitignore.template | 0 .../templates}/React InstantSearch/.prettierrc | 0 .../templates}/React InstantSearch/.template.js | 0 .../templates}/React InstantSearch/README.md | 0 .../templates}/React InstantSearch/package.json | 0 .../React InstantSearch/public/favicon.png | Bin .../React InstantSearch/public/index.html | 0 .../React InstantSearch/public/manifest.json | 0 .../templates}/React InstantSearch/src/App.css | 0 .../templates}/React InstantSearch/src/App.js.hbs | 0 .../templates}/React InstantSearch/src/index.css | 0 .../templates}/React InstantSearch/src/index.js | 0 .../templates}/Vue InstantSearch/.babelrc.template | 0 .../templates}/Vue InstantSearch/.editorconfig | 0 .../templates}/Vue InstantSearch/.eslintrc.js | 0 .../Vue InstantSearch/.gitignore.template | 0 .../templates}/Vue InstantSearch/.template.js | 0 .../templates}/Vue InstantSearch/README.md | 0 .../templates}/Vue InstantSearch/favicon.png | Bin .../templates}/Vue InstantSearch/index.html | 0 .../templates}/Vue InstantSearch/manifest.json | 0 .../templates}/Vue InstantSearch/package.json | 0 .../templates}/Vue InstantSearch/src/App.vue | 0 .../templates}/Vue InstantSearch/src/main.js | 0 .../templates}/Vue InstantSearch/webpack.config.js | 0 .../utils}/__snapshots__/utils.test.js.snap | 0 .../utils/__tests__/index.test.js | 0 packages/shared/utils.js => src/utils/index.js | 0 87 files changed, 4 insertions(+), 7 deletions(-) delete mode 100755 packages/cli/index.js delete mode 100644 packages/create-instantsearch-app/index.js rename {packages/create-instantsearch-app => src/api}/__snapshots__/createInstantSearchApp.test.js.snap (100%) rename packages/create-instantsearch-app/createInstantSearchApp.test.js => src/api/__tests__/index.test.js (100%) rename packages/create-instantsearch-app/createInstantSearchApp.js => src/api/index.js (96%) mode change 100755 => 100644 rename {packages/cli => src/cli/__tests__}/utils.test.js (100%) rename packages/cli/cli.js => src/cli/index.js (99%) mode change 100644 => 100755 rename {packages => src}/cli/utils.js (100%) rename {packages => src}/tasks/common/build.js (100%) rename {packages => src}/tasks/common/clean.js (100%) rename {packages => src}/tasks/node/install.js (100%) rename {packages => src}/tasks/node/teardown.js (100%) rename {templates => src/templates}/Angular InstantSearch/.gitignore.template (100%) rename {templates => src/templates}/Angular InstantSearch/.template.js (100%) rename {templates => src/templates}/Angular InstantSearch/README.md (100%) rename {templates => src/templates}/Angular InstantSearch/angular.json (100%) rename {templates => src/templates}/Angular InstantSearch/e2e/protractor.conf.js (100%) rename {templates => src/templates}/Angular InstantSearch/e2e/src/app.e2e-spec.ts (100%) rename {templates => src/templates}/Angular InstantSearch/e2e/src/app.po.ts (100%) rename {templates => src/templates}/Angular InstantSearch/e2e/tsconfig.e2e.json (100%) rename {templates => src/templates}/Angular InstantSearch/package.json (100%) rename {templates => src/templates}/Angular InstantSearch/src/app/app.component.css (100%) rename {templates => src/templates}/Angular InstantSearch/src/app/app.component.html.hbs (100%) rename {templates => src/templates}/Angular InstantSearch/src/app/app.component.spec.ts (100%) rename {templates => src/templates}/Angular InstantSearch/src/app/app.component.ts (100%) rename {templates => src/templates}/Angular InstantSearch/src/app/app.module.ts (100%) rename {templates => src/templates}/Angular InstantSearch/src/assets/.gitkeep (100%) rename {templates => src/templates}/Angular InstantSearch/src/browserslist (100%) rename {templates => src/templates}/Angular InstantSearch/src/environments/environment.prod.ts (100%) rename {templates => src/templates}/Angular InstantSearch/src/environments/environment.ts (100%) rename {templates => src/templates}/Angular InstantSearch/src/favicon.png (100%) rename {templates => src/templates}/Angular InstantSearch/src/index.html (100%) rename {templates => src/templates}/Angular InstantSearch/src/karma.conf.js (100%) rename {templates => src/templates}/Angular InstantSearch/src/main.ts (100%) rename {templates => src/templates}/Angular InstantSearch/src/manifest.json (100%) rename {templates => src/templates}/Angular InstantSearch/src/polyfills.ts (100%) rename {templates => src/templates}/Angular InstantSearch/src/styles.css (100%) rename {templates => src/templates}/Angular InstantSearch/src/test.ts (100%) rename {templates => src/templates}/Angular InstantSearch/src/tsconfig.app.json (100%) rename {templates => src/templates}/Angular InstantSearch/src/tsconfig.spec.json (100%) rename {templates => src/templates}/Angular InstantSearch/src/tslint.json (100%) rename {templates => src/templates}/Angular InstantSearch/tsconfig.json (100%) rename {templates => src/templates}/Angular InstantSearch/tslint.json (100%) rename {templates => src/templates}/InstantSearch.js/.editorconfig (100%) rename {templates => src/templates}/InstantSearch.js/.eslintignore (100%) rename {templates => src/templates}/InstantSearch.js/.eslintrc.js (100%) rename {templates => src/templates}/InstantSearch.js/.gitignore.template (100%) rename {templates => src/templates}/InstantSearch.js/.prettierrc (100%) rename {templates => src/templates}/InstantSearch.js/.template.js (100%) rename {templates => src/templates}/InstantSearch.js/README.md (100%) rename {templates => src/templates}/InstantSearch.js/favicon.png (100%) rename {templates => src/templates}/InstantSearch.js/index.html.hbs (100%) rename {templates => src/templates}/InstantSearch.js/manifest.webmanifest (100%) rename {templates => src/templates}/InstantSearch.js/package.json (100%) rename {templates => src/templates}/InstantSearch.js/src/app.css (100%) rename {templates => src/templates}/InstantSearch.js/src/app.js.hbs (100%) rename {templates => src/templates}/InstantSearch.js/src/index.css (100%) rename {templates => src/templates}/React InstantSearch/.editorconfig (100%) rename {templates => src/templates}/React InstantSearch/.eslintrc.js (100%) rename {templates => src/templates}/React InstantSearch/.gitignore.template (100%) rename {templates => src/templates}/React InstantSearch/.prettierrc (100%) rename {templates => src/templates}/React InstantSearch/.template.js (100%) rename {templates => src/templates}/React InstantSearch/README.md (100%) rename {templates => src/templates}/React InstantSearch/package.json (100%) rename {templates => src/templates}/React InstantSearch/public/favicon.png (100%) rename {templates => src/templates}/React InstantSearch/public/index.html (100%) rename {templates => src/templates}/React InstantSearch/public/manifest.json (100%) rename {templates => src/templates}/React InstantSearch/src/App.css (100%) rename {templates => src/templates}/React InstantSearch/src/App.js.hbs (100%) rename {templates => src/templates}/React InstantSearch/src/index.css (100%) rename {templates => src/templates}/React InstantSearch/src/index.js (100%) rename {templates => src/templates}/Vue InstantSearch/.babelrc.template (100%) rename {templates => src/templates}/Vue InstantSearch/.editorconfig (100%) rename {templates => src/templates}/Vue InstantSearch/.eslintrc.js (100%) rename {templates => src/templates}/Vue InstantSearch/.gitignore.template (100%) rename {templates => src/templates}/Vue InstantSearch/.template.js (100%) rename {templates => src/templates}/Vue InstantSearch/README.md (100%) rename {templates => src/templates}/Vue InstantSearch/favicon.png (100%) rename {templates => src/templates}/Vue InstantSearch/index.html (100%) rename {templates => src/templates}/Vue InstantSearch/manifest.json (100%) rename {templates => src/templates}/Vue InstantSearch/package.json (100%) rename {templates => src/templates}/Vue InstantSearch/src/App.vue (100%) rename {templates => src/templates}/Vue InstantSearch/src/main.js (100%) rename {templates => src/templates}/Vue InstantSearch/webpack.config.js (100%) rename {packages/shared => src/utils}/__snapshots__/utils.test.js.snap (100%) rename packages/shared/utils.test.js => src/utils/__tests__/index.test.js (100%) rename packages/shared/utils.js => src/utils/index.js (100%) 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/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/packages/create-instantsearch-app/__snapshots__/createInstantSearchApp.test.js.snap b/src/api/__snapshots__/createInstantSearchApp.test.js.snap similarity index 100% rename from packages/create-instantsearch-app/__snapshots__/createInstantSearchApp.test.js.snap rename to src/api/__snapshots__/createInstantSearchApp.test.js.snap diff --git a/packages/create-instantsearch-app/createInstantSearchApp.test.js b/src/api/__tests__/index.test.js similarity index 100% rename from packages/create-instantsearch-app/createInstantSearchApp.test.js rename to src/api/__tests__/index.test.js diff --git a/packages/create-instantsearch-app/createInstantSearchApp.js b/src/api/index.js old mode 100755 new mode 100644 similarity index 96% rename from packages/create-instantsearch-app/createInstantSearchApp.js rename to src/api/index.js index 9f36c8014..89aff468f --- a/packages/create-instantsearch-app/createInstantSearchApp.js +++ b/src/api/index.js @@ -85,6 +85,7 @@ function createInstantSearchApp(appPath, options = {}, tasks = {}) { try { await setup(config); } catch (err) { + console.error(err); return; } @@ -95,11 +96,13 @@ function createInstantSearchApp(appPath, options = {}, tasks = {}) { try { await install(config); } catch (err) { + console.error(err); await clean(config); return; } } } catch (err) { + console.error(err); return; } diff --git a/packages/cli/utils.test.js b/src/cli/__tests__/utils.test.js similarity index 100% rename from packages/cli/utils.test.js rename to src/cli/__tests__/utils.test.js diff --git a/packages/cli/cli.js b/src/cli/index.js old mode 100644 new mode 100755 similarity index 99% rename from packages/cli/cli.js rename to src/cli/index.js index 733d29272..8c66a0e6d --- 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'); diff --git a/packages/cli/utils.js b/src/cli/utils.js similarity index 100% rename from packages/cli/utils.js rename to src/cli/utils.js 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 100% rename from packages/tasks/node/install.js rename to src/tasks/node/install.js diff --git a/packages/tasks/node/teardown.js b/src/tasks/node/teardown.js similarity index 100% rename from packages/tasks/node/teardown.js rename to src/tasks/node/teardown.js 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 100% rename from templates/Angular InstantSearch/.template.js rename to src/templates/Angular InstantSearch/.template.js 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 100% rename from templates/InstantSearch.js/.template.js rename to src/templates/InstantSearch.js/.template.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/.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 100% rename from templates/React InstantSearch/.template.js rename to src/templates/React InstantSearch/.template.js 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 100% rename from templates/Vue InstantSearch/.template.js rename to src/templates/Vue InstantSearch/.template.js 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/__snapshots__/utils.test.js.snap similarity index 100% rename from packages/shared/__snapshots__/utils.test.js.snap rename to src/utils/__snapshots__/utils.test.js.snap diff --git a/packages/shared/utils.test.js b/src/utils/__tests__/index.test.js similarity index 100% rename from packages/shared/utils.test.js rename to src/utils/__tests__/index.test.js diff --git a/packages/shared/utils.js b/src/utils/index.js similarity index 100% rename from packages/shared/utils.js rename to src/utils/index.js From 7cc0c5dadf49702a034bddf172cbf81c7e3db831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Thu, 14 Jun 2018 15:47:10 +0200 Subject: [PATCH 2/5] refactor: Update new architecture --- .eslintignore | 2 +- index.js | 2 +- package.json | 11 +++++------ scripts/e2e-templates.test.js | 2 +- scripts/release-templates.js | 4 ++-- .../__snapshots__/index.test.js.snap} | 0 src/api/__tests__/index.test.js | 6 +++--- src/api/index.js | 11 ++--------- src/cli/__tests__/utils.test.js | 4 ++-- src/cli/index.js | 4 ++-- src/cli/utils.js | 13 ++++++++----- src/tasks/node/install.js | 2 +- src/tasks/node/teardown.js | 2 +- src/templates/Angular InstantSearch/.template.js | 4 ++-- src/templates/InstantSearch.js/.template.js | 4 ++-- .../React InstantSearch Native/.babelrc.template | 0 .../React InstantSearch Native/.editorconfig | 0 .../React InstantSearch Native/.eslintrc.js | 0 .../React InstantSearch Native/.gitignore.template | 0 .../React InstantSearch Native/.prettierrc | 0 .../React InstantSearch Native/.template.js | 0 .../React InstantSearch Native/.watchmanconfig | 0 .../React InstantSearch Native/App.js.hbs | 0 .../templates}/React InstantSearch Native/README.md | 0 .../templates}/React InstantSearch Native/app.json | 0 .../React InstantSearch Native/package.json | 0 .../React InstantSearch Native/src/Highlight.js | 0 .../src/InfiniteHits.js.hbs | 0 .../React InstantSearch Native/src/SearchBox.js.hbs | 0 src/templates/React InstantSearch/.template.js | 4 ++-- src/templates/Vue InstantSearch/.template.js | 4 ++-- .../__snapshots__/index.test.js.snap} | 0 src/utils/__tests__/index.test.js | 2 +- src/utils/index.js | 2 +- 34 files changed, 39 insertions(+), 44 deletions(-) rename src/api/{__snapshots__/createInstantSearchApp.test.js.snap => __tests__/__snapshots__/index.test.js.snap} (100%) rename {templates => src/templates}/React InstantSearch Native/.babelrc.template (100%) rename {templates => src/templates}/React InstantSearch Native/.editorconfig (100%) rename {templates => src/templates}/React InstantSearch Native/.eslintrc.js (100%) rename {templates => src/templates}/React InstantSearch Native/.gitignore.template (100%) rename {templates => src/templates}/React InstantSearch Native/.prettierrc (100%) rename {templates => src/templates}/React InstantSearch Native/.template.js (100%) rename {templates => src/templates}/React InstantSearch Native/.watchmanconfig (100%) rename {templates => src/templates}/React InstantSearch Native/App.js.hbs (100%) rename {templates => src/templates}/React InstantSearch Native/README.md (100%) rename {templates => src/templates}/React InstantSearch Native/app.json (100%) rename {templates => src/templates}/React InstantSearch Native/package.json (100%) rename {templates => src/templates}/React InstantSearch Native/src/Highlight.js (100%) rename {templates => src/templates}/React InstantSearch Native/src/InfiniteHits.js.hbs (100%) rename {templates => src/templates}/React InstantSearch Native/src/SearchBox.js.hbs (100%) rename src/utils/{__snapshots__/utils.test.js.snap => __tests__/__snapshots__/index.test.js.snap} (100%) 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..8f9592b4f 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" @@ -62,7 +61,7 @@ "jest": { "testPathIgnorePatterns": [ "/node_modules/", - "/templates/" + "/src/templates/" ] } } 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/src/api/__snapshots__/createInstantSearchApp.test.js.snap b/src/api/__tests__/__snapshots__/index.test.js.snap similarity index 100% rename from src/api/__snapshots__/createInstantSearchApp.test.js.snap rename to src/api/__tests__/__snapshots__/index.test.js.snap diff --git a/src/api/__tests__/index.test.js b/src/api/__tests__/index.test.js index dd6919d87..842855e39 100644 --- a/src/api/__tests__/index.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/src/api/index.js b/src/api/index.js index 89aff468f..97acfc8f4 100644 --- a/src/api/index.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, @@ -85,7 +81,6 @@ function createInstantSearchApp(appPath, options = {}, tasks = {}) { try { await setup(config); } catch (err) { - console.error(err); return; } @@ -96,13 +91,11 @@ function createInstantSearchApp(appPath, options = {}, tasks = {}) { try { await install(config); } catch (err) { - console.error(err); await clean(config); return; } } } catch (err) { - console.error(err); return; } diff --git a/src/cli/__tests__/utils.test.js b/src/cli/__tests__/utils.test.js index 28d4a0166..a972bf3c3 100644 --- a/src/cli/__tests__/utils.test.js +++ b/src/cli/__tests__/utils.test.js @@ -1,5 +1,5 @@ const path = require('path'); -const utils = require('./utils'); +const utils = require('../utils'); describe('getOptionsFromArguments', () => { test('with a single option', () => { @@ -202,7 +202,7 @@ describe('getConfiguration', () => { expect(configuration).toEqual( expect.objectContaining({ - template: path.resolve('templates/InstantSearch.js'), + template: path.resolve('src/templates/InstantSearch.js'), }) ); }); diff --git a/src/cli/index.js b/src/cli/index.js index 8c66a0e6d..ad9b48642 100755 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -6,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, @@ -14,7 +14,7 @@ const { fetchLibraryVersions, getAllTemplates, getTemplatePath, -} = require('../shared/utils'); +} = require('../utils'); const { getOptionsFromArguments, getAttributesFromAnswers, diff --git a/src/cli/utils.js b/src/cli/utils.js index b407196b1..c07d98051 100644 --- a/src/cli/utils.js +++ b/src/cli/utils.js @@ -6,7 +6,7 @@ const { getAppTemplateConfig, fetchLibraryVersions, getTemplatePath, -} = require('../shared/utils'); +} = require('../utils'); function camelCase(string) { return string.replace(/-([a-z])/g, str => str[1].toUpperCase()); @@ -39,18 +39,21 @@ async function getAttributesFromAnswers({ algoliasearchFn = algoliasearch, } = {}) { const client = algoliasearchFn(appId, apiKey); + const index = client.initIndex(indexName); const defaultAttributes = ['title', 'name', 'description']; let attributes = []; try { - const { hits } = await client.search({ indexName, hitsPerPage: 1 }); + 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 - ), + ...defaultAttributes + .map( + attribute => highlightedAttributes.includes(attribute) && attribute + ) + .filter(Boolean), ...highlightedAttributes, ]), ]; diff --git a/src/tasks/node/install.js b/src/tasks/node/install.js index 8c6004112..9bcffb89f 100644 --- a/src/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/src/tasks/node/teardown.js b/src/tasks/node/teardown.js index 30e242b5b..12bd5f4e6 100644 --- a/src/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/src/templates/Angular InstantSearch/.template.js b/src/templates/Angular InstantSearch/.template.js index d79a6c590..84112021a 100644 --- a/src/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/src/templates/InstantSearch.js/.template.js b/src/templates/InstantSearch.js/.template.js index 2404902a8..2536d5dae 100644 --- a/src/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/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 100% rename from templates/React InstantSearch Native/.template.js rename to src/templates/React InstantSearch Native/.template.js 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/src/templates/React InstantSearch/.template.js b/src/templates/React InstantSearch/.template.js index 189b5dae6..34128a56e 100644 --- a/src/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/src/templates/Vue InstantSearch/.template.js b/src/templates/Vue InstantSearch/.template.js index bc9224a98..35998b3a0 100644 --- a/src/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/src/utils/__snapshots__/utils.test.js.snap b/src/utils/__tests__/__snapshots__/index.test.js.snap similarity index 100% rename from src/utils/__snapshots__/utils.test.js.snap rename to src/utils/__tests__/__snapshots__/index.test.js.snap diff --git a/src/utils/__tests__/index.test.js b/src/utils/__tests__/index.test.js index 3a45c301e..9844abe07 100644 --- a/src/utils/__tests__/index.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/src/utils/index.js b/src/utils/index.js index 7345baa56..d97433d81 100644 --- a/src/utils/index.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', From 3abd901efbbb5845daef8cc2d86cc4a999bf79c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Thu, 14 Jun 2018 15:47:39 +0200 Subject: [PATCH 3/5] feat(cli): Update `mainAttribute` display --- src/cli/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cli/index.js b/src/cli/index.js index ad9b48642..251047bb7 100755 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -166,8 +166,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 getAttributesFromAnswers(answers)), + ], when: ({ appId, apiKey, indexName }) => appId && apiKey && indexName, }, ].filter(question => isQuestionAsked({ question, args: optionsFromArguments })); From f51ea6bd6e952594f6589d5f4df00ff1c7e4b313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Thu, 14 Jun 2018 16:33:12 +0200 Subject: [PATCH 4/5] refactor(cli): Refactor CLI utils --- package.json | 1 + .../__tests__/getAttributesFromIndex.test.js | 48 ++++ src/cli/__tests__/getConfiguration.test.js | 69 +++++ .../__tests__/getOptionsFromArguments.test.js | 72 +++++ src/cli/__tests__/isQuestionAsked.test.js | 54 ++++ src/cli/__tests__/utils.test.js | 254 ------------------ src/cli/getAttributesFromIndex.js | 33 +++ src/cli/getConfiguration.js | 39 +++ src/cli/getOptionsFromArguments.js | 21 ++ src/cli/index.js | 12 +- src/cli/isQuestionAsked.js | 22 ++ src/cli/utils.js | 124 --------- yarn.lock | 4 + 13 files changed, 368 insertions(+), 385 deletions(-) create mode 100644 src/cli/__tests__/getAttributesFromIndex.test.js create mode 100644 src/cli/__tests__/getConfiguration.test.js create mode 100644 src/cli/__tests__/getOptionsFromArguments.test.js create mode 100644 src/cli/__tests__/isQuestionAsked.test.js delete mode 100644 src/cli/__tests__/utils.test.js create mode 100644 src/cli/getAttributesFromIndex.js create mode 100644 src/cli/getConfiguration.js create mode 100644 src/cli/getOptionsFromArguments.js create mode 100644 src/cli/isQuestionAsked.js delete mode 100644 src/cli/utils.js diff --git a/package.json b/package.json index 8f9592b4f..ef08f6d11 100644 --- a/package.json +++ b/package.json @@ -36,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", 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/__tests__/utils.test.js b/src/cli/__tests__/utils.test.js deleted file mode 100644 index a972bf3c3..000000000 --- a/src/cli/__tests__/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('src/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/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/src/cli/index.js b/src/cli/index.js index 251047bb7..c5dfe0542 100755 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -15,12 +15,10 @@ const { getAllTemplates, getTemplatePath, } = require('../utils'); -const { - getOptionsFromArguments, - getAttributesFromAnswers, - isQuestionAsked, - getConfiguration, -} = 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; @@ -174,7 +172,7 @@ const questions = [ }, new inquirer.Separator(), new inquirer.Separator('From your index'), - ...(await getAttributesFromAnswers(answers)), + ...(await getAttributesFromIndex(answers)), ], when: ({ appId, apiKey, indexName }) => appId && apiKey && indexName, }, 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/src/cli/utils.js b/src/cli/utils.js deleted file mode 100644 index c07d98051..000000000 --- a/src/cli/utils.js +++ /dev/null @@ -1,124 +0,0 @@ -const algoliasearch = require('algoliasearch'); -const latestSemver = require('latest-semver'); -const loadJsonFile = require('load-json-file'); - -const { - getAppTemplateConfig, - fetchLibraryVersions, - getTemplatePath, -} = require('../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 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; -} - -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/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" From d264be2e3c301a8074869a4a3d8c37ecb66477a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Fri, 15 Jun 2018 10:25:31 +0200 Subject: [PATCH 5/5] fix(templates): Update task imports --- src/templates/React InstantSearch Native/.template.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/templates/React InstantSearch Native/.template.js b/src/templates/React InstantSearch Native/.template.js index 376d8e696..2f2f2ec54 100644 --- a/src/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',