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

Commit

Permalink
feat(cli): added config handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Stanislawski committed Jul 19, 2017
1 parent d721f15 commit 00d0a40
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 12 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ Create a new project:
```sh
create-instantsearch-app [name-of-your-new-app]
```

### Using Yarn

With yarn you don't have an install step, just use:

```sh
yarn create instantsearch-app
```
56 changes: 45 additions & 11 deletions bin/create-instantsearch-app.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,52 @@
#! /usr/bin/env node

const shell = require('shelljs');
const path = require('path');
const process = require('process');
const program = require('commander');
const prompt = require('prompt');
const colors = require('colors');

const boilerplateFolder = path.join(__dirname, '../boilerplates');
const instantsearchBoilerplate = path.join(boilerplateFolder, 'instantsearch.js');
const version = require('../package.json').version;
const createProject = require('../lib/createProject.js');

const targetFolderName = process.argv[2] || 'instantsearch-project';
let opts = {};
let targetFolderName;

console.log(`Create your new instantsearch app: ${targetFolderName}`);
shell.cp('-r', instantsearchBoilerplate, targetFolderName);
console.log('Project successfully created 🚀');
program
.version(version)
.arguments('<destination_folder>')
.option('--app-id <appId>', 'The application ID')
.option('--api-key <apiKey>', 'The Algolia search API key')
.option('--index-name <indexName>', 'The main index of your search')
.action(function(dest, options) {
opts = options;
targetFolderName = dest;
})
.parse(process.argv);

// console.log(shell.ls('.').join());
// console.log(shell.ls(boilerplateFolder).join());
// console.log(targetFolderName);
if(!targetFolderName) {
console.log('The folder name for the new instantsearch project was not provided 😲'.red);
program.help();
}

console.log(`Creating your new instantsearch app: ${targetFolderName.bold}`.green);

let prompts = [
{name: 'appId', description: 'Application ID'.blue, required: true},
{name: 'apiKey', description: 'Search API key'.blue, required: true},
{name: 'indexName', description: 'Index name'.blue, required: true},
];

prompt.message = '';
prompt.override = opts;

prompt.start();
prompt.get(prompts, function(err, config) {
if(err) {
console.log('\nProject creation cancelled 😢'.red);
process.exit(0);
} else {
config.targetFolderName = targetFolderName;
createProject(config);
console.log('Project successfully created 🚀'.green.bold);
}
})
10 changes: 10 additions & 0 deletions lib/createProject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const shell = require('shelljs');
const path = require('path');

module.exports = function createProject(config) {
const boilerplateFolder = path.join(__dirname, '../boilerplates');
const instantsearchBoilerplate = path.join(boilerplateFolder, 'instantsearch.js');

console.log(config);
shell.cp('-r', instantsearchBoilerplate, config.targetFolderName);
};
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"create-instantsearch-app": "bin/create-instantsearch-app.js"
},
"dependencies": {
"colors": "^1.1.2",
"commander": "^2.11.0",
"prompt": "^1.0.0",
"shelljs": "^0.7.8"
},
"repository": {
Expand Down
122 changes: 121 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
# yarn lockfile v1


async@~0.9.0:
version "0.9.2"
resolved "https://registry.yarnpkg.com/async/-/async-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d"

async@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/async/-/async-1.0.0.tgz#f8fc04ca3a13784ade9e1641af98578cfbd647a9"

balanced-match@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
Expand All @@ -13,15 +21,39 @@ brace-expansion@^1.1.7:
balanced-match "^1.0.0"
concat-map "0.0.1"

[email protected]:
version "1.0.3"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b"

colors@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.1.2.tgz#168a4701756b6a7f51a12ce0c97bfa28c084ed63"

commander@^2.11.0:
version "2.11.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.11.0.tgz#157152fd1e7a6c8d98a5b715cf376df928004563"

[email protected]:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"

[email protected]:
version "1.0.3"
resolved "https://registry.yarnpkg.com/cycle/-/cycle-1.0.3.tgz#21e80b2be8580f98b468f379430662b046c34ad2"

deep-equal@~0.2.1:
version "0.2.2"
resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-0.2.2.tgz#84b745896f34c684e98f2ce0e42abaf43bba017d"

[email protected]:
version "0.1.8"
resolved "https://registry.yarnpkg.com/eyes/-/eyes-0.1.8.tgz#62cf120234c683785d902348a800ef3e0cc20bc0"

fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"

glob@^7.0.0:
glob@^7.0.0, glob@^7.0.5:
version "7.1.2"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
dependencies:
Expand All @@ -32,6 +64,10 @@ glob@^7.0.0:
once "^1.3.0"
path-is-absolute "^1.0.0"

[email protected]:
version "0.3.5"
resolved "https://registry.yarnpkg.com/i/-/i-0.3.5.tgz#1d2b854158ec8169113c6cb7f6b6801e99e211d5"

inflight@^1.0.4:
version "1.0.6"
resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
Expand All @@ -47,12 +83,34 @@ interpret@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.0.3.tgz#cbc35c62eeee73f19ab7b10a801511401afc0f90"

[email protected]:
version "0.1.2"
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"

minimatch@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
dependencies:
brace-expansion "^1.1.7"

[email protected]:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"

[email protected]:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
dependencies:
minimist "0.0.8"

mute-stream@~0.0.4:
version "0.0.7"
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"

[email protected]:
version "1.0.1"
resolved "https://registry.yarnpkg.com/ncp/-/ncp-1.0.1.tgz#d15367e5cb87432ba117d2bf80fdf45aecfb4246"

once@^1.3.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
Expand All @@ -67,6 +125,31 @@ path-parse@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.5.tgz#3c1adf871ea9cd6c9431b6ea2bd74a0ff055c4c1"

[email protected]:
version "0.3.1"
resolved "https://registry.yarnpkg.com/pkginfo/-/pkginfo-0.3.1.tgz#5b29f6a81f70717142e09e765bbeab97b4f81e21"

[email protected]:
version "0.4.0"
resolved "https://registry.yarnpkg.com/pkginfo/-/pkginfo-0.4.0.tgz#349dbb7ffd38081fcadc0853df687f0c7744cd65"

prompt@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/prompt/-/prompt-1.0.0.tgz#8e57123c396ab988897fb327fd3aedc3e735e4fe"
dependencies:
colors "^1.1.2"
pkginfo "0.x.x"
read "1.0.x"
revalidator "0.1.x"
utile "0.3.x"
winston "2.1.x"

[email protected]:
version "1.0.7"
resolved "https://registry.yarnpkg.com/read/-/read-1.0.7.tgz#b3da19bd052431a97671d44a42634adf710b40c4"
dependencies:
mute-stream "~0.0.4"

rechoir@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384"
Expand All @@ -79,6 +162,16 @@ resolve@^1.1.6:
dependencies:
path-parse "^1.0.5"

[email protected]:
version "0.1.8"
resolved "https://registry.yarnpkg.com/revalidator/-/revalidator-0.1.8.tgz#fece61bfa0c1b52a206bd6b18198184bdd523a3b"

[email protected]:
version "2.6.1"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.1.tgz#c2338ec643df7a1b7fe5c54fa86f57428a55f33d"
dependencies:
glob "^7.0.5"

shelljs@^0.7.8:
version "0.7.8"
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.7.8.tgz#decbcf874b0d1e5fb72e14b164a9683048e9acb3"
Expand All @@ -87,6 +180,33 @@ shelljs@^0.7.8:
interpret "^1.0.0"
rechoir "^0.6.2"

[email protected]:
version "0.0.10"
resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.10.tgz#547c70b347e8d32b4e108ea1a2a159e5fdde19c0"

[email protected]:
version "0.3.0"
resolved "https://registry.yarnpkg.com/utile/-/utile-0.3.0.tgz#1352c340eb820e4d8ddba039a4fbfaa32ed4ef3a"
dependencies:
async "~0.9.0"
deep-equal "~0.2.1"
i "0.3.x"
mkdirp "0.x.x"
ncp "1.0.x"
rimraf "2.x.x"

[email protected]:
version "2.1.1"
resolved "https://registry.yarnpkg.com/winston/-/winston-2.1.1.tgz#3c9349d196207fd1bdff9d4bc43ef72510e3a12e"
dependencies:
async "~1.0.0"
colors "1.0.x"
cycle "1.0.x"
eyes "0.1.x"
isstream "0.1.x"
pkginfo "0.3.x"
stack-trace "0.0.x"

wrappy@1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"

0 comments on commit 00d0a40

Please sign in to comment.