From db524da50e485184c7a40d77e002f35b05026057 Mon Sep 17 00:00:00 2001 From: Adriano Rosa Date: Thu, 23 Jul 2020 18:01:33 -0300 Subject: [PATCH] add npm release script --- .gitignore | 3 +++ box.json | 9 ++++++- composer.json | 1 + package.json | 23 +++++++++++++++++ scripts/release.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 package.json create mode 100644 scripts/release.js diff --git a/.gitignore b/.gitignore index 82d7a81..0ef34ec 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,10 @@ *.phar *.lock +package-lock.json +/node_modules/ /vendor/ _build/ /html + diff --git a/box.json b/box.json index 6f6533f..b45ce45 100644 --- a/box.json +++ b/box.json @@ -15,11 +15,18 @@ "in": "vendor" }, { - "exclude": ["tests", "_build"], + "exclude": [ + "tests", + "_build", + "scripts", + "node_modules" + ], "in": "./" } ], "blacklist": [ + "package.json", + "package-lock.json", "api.php", "box.json", "config.yaml", diff --git a/composer.json b/composer.json index 8821dd5..22d9892 100644 --- a/composer.json +++ b/composer.json @@ -1,4 +1,5 @@ { + "version": "0.0.0", "name": "adrianorosa/compare-system-versions", "description": "System versions compare", "type": "project", diff --git a/package.json b/package.json new file mode 100644 index 0000000..ce2885d --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "compare-system-versions", + "version": "0.0.0", + "description": "Compare System Versions", + "dependencies": {}, + "devDependencies": { + "release-task": "^1.0.0" + }, + "scripts": { + "release": "node ./scripts/release.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/adrianorsouza/compare-system-versions.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/adrianorsouza/compare-system-versions/issues" + }, + "homepage": "https://github.com/adrianorsouza/compare-system-versions#readme" +} diff --git a/scripts/release.js b/scripts/release.js new file mode 100644 index 0000000..1377dc1 --- /dev/null +++ b/scripts/release.js @@ -0,0 +1,61 @@ +/** ======================================================================== + * Project : compare-system-versions + * Description : release + * Author : Adriano Rosa + * Date : 2020-07-23 17:16 + * ======================================================================== + * Copyright 2020 Adriano Rosa + * ======================================================================== */ + +const util = require('util'); +const exec = util.promisify(require('child_process').exec); +const releaseTask = require('release-task'); +const { writeLog } = require('release-task/src/helpers'); + +// create a new instance of releaseTask +const tasks = new releaseTask({ + bumpFiles: ['composer.json', 'package.json'], + commitFiles: ['composer.json', 'package.json', 'CHANGELOG.md'], + config: { + indentSize: 2 + } +}); + + +const push = async () => { + writeLog('TASK push'); + const {stdout, stderr} = exec('git push -u origin master --tags 2>&1'); + if (stderr) throw new Error(`TASK push result an error ${stderr}`); + return `TASK push has been completed.\n\n${stdout}`; +}; + + +// async function compilePHAR(version, options) { +const compilePHAR = async (version, options) => { + writeLog('TASK compilePHAR'); + const { stdout, stderr } = await exec('box compile'); + + if (stderr) { + throw new Error(`An error occurred ${stderr}`); + } + + if (stdout) { + return `Compile phar using box DONE!\n\n${stdout}` + } +} + + +// Create a custom task named push +tasks.addTask('push', push, { + checked: false, + value: 'push', + name: 'Push new releases', +}); + +tasks.addTask('compilePHAR', compilePHAR, { + checked: true, + value: 'compilePHAR', + name: 'Compile phar using box', +}); + +tasks.init();