create-instantsearch-app 6.4.0 → 6.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-instantsearch-app",
3
- "version": "6.4.0",
3
+ "version": "6.4.2",
4
4
  "license": "MIT",
5
5
  "description": "⚡️ Build InstantSearch apps at the speed of thought",
6
6
  "keywords": [
@@ -52,5 +52,5 @@
52
52
  "jest-image-snapshot": "2.12.0",
53
53
  "walk-sync": "2.0.2"
54
54
  },
55
- "gitHead": "f224d502edb8cf119213cb9cd6e557dc03180521"
55
+ "gitHead": "c0a9fe132d2c64939763f64f7c265ed8ceb89ae2"
56
56
  }
@@ -1,4 +1,5 @@
1
1
  const path = require('path');
2
+
2
3
  const createInstantSearchAppFactory = require('../');
3
4
 
4
5
  let setupSpy;
@@ -1,4 +1,5 @@
1
1
  const path = require('path');
2
+
2
3
  const resolveTemplate = require('../resolve-template');
3
4
 
4
5
  describe('resolveTemplate', () => {
@@ -1,5 +1,6 @@
1
- const path = require('path');
2
1
  const fs = require('fs');
2
+ const path = require('path');
3
+
3
4
  const { checkAppName, checkAppPath } = require('../utils');
4
5
 
5
6
  function getOptions({ supportedTemplates }) {
package/src/api/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  const path = require('path');
2
- const checkConfig = require('./check-config');
3
- const resolveTemplate = require('./resolve-template');
2
+
4
3
  const buildTask = require('../tasks/common/build');
5
4
  const cleanTask = require('../tasks/common/clean');
6
5
  const { getAllTemplates } = require('../utils');
7
6
 
7
+ const checkConfig = require('./check-config');
8
+ const resolveTemplate = require('./resolve-template');
9
+
8
10
  const supportedTemplates = getAllTemplates();
9
11
 
10
12
  function noop() {}
@@ -1,5 +1,7 @@
1
1
  const path = require('path');
2
+
2
3
  const semver = require('semver');
4
+
3
5
  const { getAppTemplateConfig } = require('../utils');
4
6
 
5
7
  function getTemplateNameByLibraryVersion({
@@ -1,4 +1,5 @@
1
1
  const loadJsonFile = require('load-json-file');
2
+
2
3
  const getConfiguration = require('../getConfiguration');
3
4
 
4
5
  jest.mock('load-json-file');
@@ -1,4 +1,5 @@
1
1
  const algoliasearch = require('algoliasearch');
2
+
2
3
  const getInformationFromIndex = require('../getInformationFromIndex');
3
4
 
4
5
  jest.mock('algoliasearch', () => {
@@ -1,5 +1,5 @@
1
- const postProcessAnswers = require('../postProcessAnswers');
2
1
  const utils = require('../../utils');
2
+ const postProcessAnswers = require('../postProcessAnswers');
3
3
 
4
4
  jest.mock('../../utils', () => ({
5
5
  ...jest.requireActual('../../utils'),
@@ -1,5 +1,5 @@
1
- const algoliasearch = require('algoliasearch');
2
1
  const { createInMemoryCache } = require('@algolia/cache-in-memory');
2
+ const algoliasearch = require('algoliasearch');
3
3
 
4
4
  const clients = new Map();
5
5
  function getClient(appId, apiKey) {
package/src/cli/index.js CHANGED
@@ -1,12 +1,14 @@
1
1
  #!/usr/bin/env node
2
+ const os = require('os');
2
3
  const path = require('path');
3
4
  const process = require('process');
4
- const os = require('os');
5
+
6
+ const chalk = require('chalk');
5
7
  const program = require('commander');
6
8
  const inquirer = require('inquirer');
7
- const chalk = require('chalk');
8
9
  const semver = require('semver');
9
10
 
11
+ const { version } = require('../../package.json');
10
12
  const createInstantSearchApp = require('../api');
11
13
  const {
12
14
  checkAppPath,
@@ -17,13 +19,13 @@ const {
17
19
  getTemplatePath,
18
20
  splitArray,
19
21
  } = require('../utils');
22
+
23
+ const getAnswersDefaultValues = require('./getAnswersDefaultValues');
20
24
  const getAttributesFromIndex = require('./getAttributesFromIndex');
25
+ const getConfiguration = require('./getConfiguration');
21
26
  const getFacetsFromIndex = require('./getFacetsFromIndex');
22
- const getAnswersDefaultValues = require('./getAnswersDefaultValues');
23
27
  const isQuestionAsked = require('./isQuestionAsked');
24
- const getConfiguration = require('./getConfiguration');
25
28
  const postProcessAnswers = require('./postProcessAnswers');
26
- const { version } = require('../../package.json');
27
29
 
28
30
  let appPathFromArgument;
29
31
 
@@ -1,7 +1,7 @@
1
- const metalsmith = require('metalsmith');
2
1
  const inPlace = require('@metalsmith/in-place');
3
- const rename = require('metalsmith-rename');
4
2
  const remove = require('@metalsmith/remove');
3
+ const metalsmith = require('metalsmith');
4
+ const rename = require('metalsmith-rename');
5
5
 
6
6
  module.exports = function build(config) {
7
7
  return new Promise((resolve, reject) => {
@@ -1,4 +1,5 @@
1
1
  const util = require('util');
2
+
2
3
  const exec = util.promisify(require('child_process').exec);
3
4
  const chalk = require('chalk');
4
5
 
@@ -1,4 +1,5 @@
1
1
  const { execSync } = require('child_process');
2
+
2
3
  const chalk = require('chalk');
3
4
 
4
5
  module.exports = function install(config) {
@@ -1,4 +1,5 @@
1
1
  const { execSync } = require('child_process');
2
+
2
3
  const chalk = require('chalk');
3
4
 
4
5
  module.exports = function setup(config) {
@@ -1,6 +1,8 @@
1
- const process = require('process');
2
1
  const { execSync } = require('child_process');
2
+ const process = require('process');
3
+
3
4
  const chalk = require('chalk');
5
+
4
6
  const { isYarnAvailable } = require('../../utils');
5
7
 
6
8
  module.exports = function install(config) {
@@ -1,6 +1,8 @@
1
- const path = require('path');
2
1
  const { execSync } = require('child_process');
2
+ const path = require('path');
3
+
3
4
  const chalk = require('chalk');
5
+
4
6
  const { isYarnAvailable } = require('../../utils');
5
7
 
6
8
  module.exports = function teardown(config) {
@@ -0,0 +1,24 @@
1
+ const https = require('https');
2
+
3
+ const { fetchLibraryVersions } = require('../fetchLibraryVersions');
4
+
5
+ describe('fetchLibraryVersions', () => {
6
+ test('return versions for a library', async () => {
7
+ expect(await fetchLibraryVersions('react-instantsearch')).toEqual(
8
+ expect.arrayContaining([expect.any(String)])
9
+ );
10
+ });
11
+
12
+ test('return versions from cache if available', async () => {
13
+ const httpsSpy = jest.spyOn(https, 'get');
14
+
15
+ await fetchLibraryVersions('react-instantsearch-core');
16
+ expect(httpsSpy).toHaveBeenCalledTimes(1);
17
+
18
+ await fetchLibraryVersions('react-instantsearch-core');
19
+ expect(httpsSpy).toHaveBeenCalledTimes(1);
20
+
21
+ await fetchLibraryVersions('instantsearch.js');
22
+ expect(httpsSpy).toHaveBeenCalledTimes(2);
23
+ });
24
+ });
@@ -0,0 +1,37 @@
1
+ const https = require('https');
2
+
3
+ function fetchCachedLibraryVersions() {
4
+ const cache = new Map();
5
+ return function fetchLibraryVersions(libraryName) {
6
+ if (cache.has(libraryName)) {
7
+ return Promise.resolve(cache.get(libraryName));
8
+ }
9
+
10
+ return new Promise((resolve, reject) => {
11
+ https
12
+ .get(`https://registry.npmjs.org/${libraryName}`, (res) => {
13
+ let body = '';
14
+ res.on('data', (chunk) => {
15
+ body += chunk;
16
+ });
17
+
18
+ res.on('end', () => {
19
+ try {
20
+ const library = JSON.parse(body);
21
+ const versions = Object.keys(library.versions).reverse();
22
+
23
+ cache.set(libraryName, versions);
24
+ resolve(versions);
25
+ } catch (err) {
26
+ reject(err);
27
+ }
28
+ });
29
+ })
30
+ .on('error', reject);
31
+ });
32
+ };
33
+ }
34
+
35
+ module.exports = {
36
+ fetchLibraryVersions: fetchCachedLibraryVersions(),
37
+ };
@@ -1,22 +1,14 @@
1
+ const { execSync } = require('child_process');
1
2
  const fs = require('fs');
2
3
  const path = require('path');
3
- const { execSync } = require('child_process');
4
+
4
5
  const chalk = require('chalk');
5
6
  const semver = require('semver');
6
7
  const validateProjectName = require('validate-npm-package-name');
7
- const algoliasearch = require('algoliasearch');
8
8
 
9
+ const { fetchLibraryVersions } = require('./fetchLibraryVersions');
9
10
  const TEMPLATES_FOLDER = path.join(__dirname, '../templates');
10
11
 
11
- const algoliaConfig = {
12
- appId: 'OFCNCOG2CU',
13
- apiKey: 'f54e21fa3a2a0160595bb058179bfb1e',
14
- indexName: 'npm-search',
15
- };
16
-
17
- const client = algoliasearch(algoliaConfig.appId, algoliaConfig.apiKey);
18
- const index = client.initIndex(algoliaConfig.indexName);
19
-
20
12
  function checkAppName(appName) {
21
13
  const validationResult = validateProjectName(appName);
22
14
 
@@ -129,14 +121,6 @@ function getTemplatePath(templateName) {
129
121
  return templateName;
130
122
  }
131
123
 
132
- async function fetchLibraryVersions(libraryName) {
133
- const library = await index.getObject(libraryName, {
134
- attributesToRetrieve: ['versions'],
135
- });
136
-
137
- return Object.keys(library.versions).reverse();
138
- }
139
-
140
124
  function getLibraryVersion({ libraryName, supportedVersion = '' }) {
141
125
  return async (getVersion) => {
142
126
  const versions = await fetchLibraryVersions(libraryName);