From bf1314e96f4bc7a493562947c75e060a82a1adea Mon Sep 17 00:00:00 2001 From: Filippo Calabrese Date: Mon, 8 Apr 2019 17:30:05 +0200 Subject: [PATCH] travis configuration file creation --- README.md | 2 ++ extra/.travis.yml | 15 +++++++++++++++ index.js | 35 +++++++++++++++++++++++++++++++++++ package-lock.json | 2 +- 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 extra/.travis.yml diff --git a/README.md b/README.md index 58b83b4..4646004 100644 --- a/README.md +++ b/README.md @@ -42,3 +42,5 @@ Gabriele Venturi (https://github.com/gventuri) Gianni Valdambrini (https://github.com/gvaldambrini) Roberto Di Lillo (https://github.com/koop4) + +Filippo Calabrese (https://github.com/filippocalabrese) diff --git a/extra/.travis.yml b/extra/.travis.yml new file mode 100644 index 0000000..2b67f85 --- /dev/null +++ b/extra/.travis.yml @@ -0,0 +1,15 @@ +language: node_js + +node_js: + - '10' + +cache: + npm: true + directories: + - '.eslintcache' + - 'node_modules' + +script: +- npm install +- npm install --save-dev jest +- npm run test diff --git a/index.js b/index.js index 0cfd2d7..2c98b4b 100755 --- a/index.js +++ b/index.js @@ -33,6 +33,7 @@ AVAILABLE COMMAND: init initialize the cli config change the default settings of the cli. you need to initialize the cli before add creates a new component using the provided name. default path: '${DEFAULT_PATH}' + travis create a standard .travis.yml configuration file for your project OPTIONS -path override default path. @@ -53,6 +54,7 @@ AUTHORS CONTRIBUTORS Gianni Vandalbrini (https://github.com/gvaldambrini) Roberto Di Lillo (https://github.com/koop4) + Filippo Calabrese (https://github.com/filippocalabrese) `; const WRONG_PATH_MSG = `The path provided is wrong`; const PROJ_INIT = `The project has been initialized`; @@ -89,6 +91,15 @@ class Commands { } } + static initTravis() { + const data = fs.readFileSync(__dirname+"/extra/.travis.yml", "utf-8"); + fs.writeFile(__dirname+"/.travis.yml", data, err => { + if (err) { + console.log(`Cannot create travis init file`); + } + }); + } + config() { const questions = [ { @@ -103,6 +114,13 @@ class Commands { name: "storybook", message: "Do you want to enable the support for Storybook?", default: true + }, + { + type: "confirm", + name: "travis", + message: + "Are you using Travis CI for your software development pipeline?", + default: true } ]; @@ -112,7 +130,11 @@ class Commands { ".react-templates/config.json", JSON.stringify(answers) ); + + handleTravis(answers.travis); + } catch (err) { + console.log(err); warnAndExit(`You need to initialize the cli before you configure it.`); } }); @@ -167,6 +189,15 @@ const warnAndExit = error => { process.exit(-1); }; +const handleTravis = (flag) => { + if(flag){ + Commands.initTravis(); + } + else{ + fs.unlink(".travis.yml", ()=>{console.log('removed travis configuration file');}); + } +} + const main = () => { const commands = new Commands(); @@ -181,6 +212,10 @@ const main = () => { commands.add(name, opt.path); }); + program.command("travis").action(() => { + Commands.initTravis(); + }); + program.command("init").action(() => { commands.init(); }); diff --git a/package-lock.json b/package-lock.json index 20c4682..8a0c171 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "create-react-component-cli", - "version": "1.2.3", + "version": "1.3.0", "lockfileVersion": 1, "requires": true, "dependencies": {