Commit 9dc7597e authored by Philipp Nowinski's avatar Philipp Nowinski
Browse files

[FEATURE] migrate releaseExtension task to new structure

parent 29115188
'use strict';
const inquirer = require('inquirer'),
yargs = require('yargs').argv,
chalk = require('chalk'),
fs = require('fs'),
replace = require('replace-in-file'),
settings = require('../../gulp/settings'),
basePath = settings.getConfig().directories.basePath;
if (typeof yargs.ext === 'undefined') {
console.error(chalk.red('Please specify the extension you want to release!'))
} else if (!fs.existsSync(`${basePath}${yargs.ext}`)) {
console.error(chalk.red(`Could not find extension in ${yargs.ext}!`))
} else {
inquirer.prompt([
{
type: 'confirm',
name: 'major',
message: 'Does the user need to apply changes to the code base or configuration after installing your update?'
},
{
type: 'confirm',
name: 'feature',
message: 'Did you develop new features?',
when: answers => !answers.major
}
]).then(answers => {
try {
let pathToComposer = `${process.cwd()}/${basePath}/${yargs.ext}/composer.json`,
pathToExtEmconf = `${process.cwd()}/${basePath}/${yargs.ext}/ext_emconf.php`,
composerFile = require(pathToComposer),
currentVersion = composerFile.version,
nextVersionNumber = getNextVersionNumber(answers, currentVersion);
updateComposerJson(currentVersion, nextVersionNumber, pathToComposer).then(() => {
updateExtEmconf(currentVersion, nextVersionNumber, pathToExtEmconf)
});
} catch (error) {
console.error(chalk.red('Could not open file!'))
}
});
}
function getNextVersionNumber(answers, currentVersion) {
let numbers = currentVersion.split('.');
if (answers.major) {
numbers[0] = parseInt(numbers[0]) + 1;
numbers[1] = 0;
numbers[2] = 0;
} else if (answers.feature) {
numbers[1] = parseInt(numbers[1]) + 1;
numbers[2] = 0;
} else {
numbers[2] = parseInt(numbers[2]) + 1;
}
return `${numbers[0]}.${numbers[1]}.${numbers[2]}`;
}
function updateComposerJson(currentVersion, newVersion, path) {
return replace({
files: path,
from: `"version": "${currentVersion}"`,
to: `"version": "${newVersion}"`
});
}
function updateExtEmconf(currentVersion, newVersion, path) {
return replace({
files: path,
from: `'version' => '${currentVersion}'`,
to: `'version' => '${newVersion}'`
});
}
......@@ -25,6 +25,7 @@ class Settings {
server: () => {return require('./tasks/server')},
images: () => {return require('./tasks/images')},
open: () => {return require('./tasks/open')},
releaseExtension: () => {return require('./tasks/releaseExtension')},
default: () => {return require('./tasks/default')}
};
}
......
const Task = require('../task');
const yargs = require('yargs').argv;
const inquirer = require('inquirer');
const fs = require('fs');
const replace = require('replace-in-file');
/**
* Opens a defined URL in the default browser
*/
module.exports = class Open extends Task {
/**
* Runner function
*/
async run() {
if (typeof yargs.ext === 'undefined') {
this._logger.error('Please specify the extension you want to release!');
} else if (!fs.existsSync(`${this._config.directories.basePath}${yargs.ext}`)) {
this._logger.error(`Could not find extension in ${yargs.ext}!`);
} else {
const answers = await inquirer.prompt([
{
type: 'confirm',
name: 'major',
message: 'Does the user need to apply changes to the code base or configuration after installing your update?'
},
{
type: 'confirm',
name: 'feature',
message: 'Did you develop new features?',
when: answers => !answers.major
}
]);
try {
let pathToComposer = `${process.cwd()}/${this._config.directories.basePath}/${yargs.ext}/composer.json`,
pathToExtEmconf = `${process.cwd()}/${this._config.directories.basePath}/${yargs.ext}/ext_emconf.php`,
composerFile = require(pathToComposer),
currentVersion = composerFile.version,
nextVersionNumber = this._getNextVersionNumber(answers, currentVersion);
this._updateComposerJson(currentVersion, nextVersionNumber, pathToComposer).then(() => {
this._updateExtEmconf(currentVersion, nextVersionNumber, pathToExtEmconf)
});
} catch (error) {
this._logger.error('Could not open file!');
}
}
}
/**
* Determines the next version number
*
* @param {Object} answers The answers to the questions from inquirer
* @param {String} currentVersion The curent version number
*/
_getNextVersionNumber(answers, currentVersion) {
let numbers = currentVersion.split('.');
if (answers.major) {
numbers[0] = parseInt(numbers[0]) + 1;
numbers[1] = 0;
numbers[2] = 0;
} else if (answers.feature) {
numbers[1] = parseInt(numbers[1]) + 1;
numbers[2] = 0;
} else {
numbers[2] = parseInt(numbers[2]) + 1;
}
return `${numbers[0]}.${numbers[1]}.${numbers[2]}`;
}
/**
* Updates the version number in composer.json
*
* @param {String} currentVersion The current version
* @param {String} newVersion The new version
* @param {String} path The path to the composer.json file
*/
_updateComposerJson(currentVersion, newVersion, path) {
return replace({
files: path,
from: `"version": "${currentVersion}"`,
to: `"version": "${newVersion}"`
});
}
/**
* Updates the version number in ext_emconf.php
*
* @param {String} currentVersion The current version
* @param {String} newVersion The new version
* @param {String} path The path to the ext_emconf.php file
*/
_updateExtEmconf(currentVersion, newVersion, path) {
return replace({
files: path,
from: `'version' => '${currentVersion}'`,
to: `'version' => '${newVersion}'`
});
}
}
......@@ -3218,9 +3218,9 @@
"integrity": "sha512-7I/xceXfKyUJmSAn/jw8ve/9DyOP7XxufNYLI9Px7CmsKgEUaZLUTax6nZxGQtaoiZCjpu6cHPj20xC/vqRReQ=="
},
"chardet": {
"version": "0.4.2",
"resolved": "https://registry.npmjs.org/chardet/-/chardet-0.4.2.tgz",
"integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I="
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/chardet/-/chardet-0.5.0.tgz",
"integrity": "sha512-9ZTaoBaePSCFvNlNGrsyI8ZVACP2svUtq0DkM7t4K2ClAa96sqOIRjAzDTc8zXzFt1cZR46rRzLTiHFSJ+Qw0g=="
},
"chokidar": {
"version": "1.7.0",
......@@ -4822,6 +4822,11 @@
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz",
"integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg="
},
"chardet": {
"version": "0.4.2",
"resolved": "https://registry.npmjs.org/chardet/-/chardet-0.4.2.tgz",
"integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I="
},
"cross-spawn": {
"version": "6.0.5",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz",
......@@ -4842,6 +4847,16 @@
"ms": "2.0.0"
}
},
"external-editor": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.2.0.tgz",
"integrity": "sha512-bSn6gvGxKt+b7+6TKEv1ZycHleA7aHhRHyAqJyp5pbUFuYYNIzpZnQDk7AsYckyWdEnTeAnay0aCy2aV6iTk9A==",
"requires": {
"chardet": "^0.4.0",
"iconv-lite": "^0.4.17",
"tmp": "^0.0.33"
}
},
"fast-deep-equal": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz",
......@@ -4852,11 +4867,53 @@
"resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz",
"integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg=="
},
"inquirer": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/inquirer/-/inquirer-5.2.0.tgz",
"integrity": "sha512-E9BmnJbAKLPGonz0HeWHtbKf+EeSP93paWO3ZYoUpq/aowXvYGjjCSuashhXPpzbArIjBbji39THkxTz9ZeEUQ==",
"requires": {
"ansi-escapes": "^3.0.0",
"chalk": "^2.0.0",
"cli-cursor": "^2.1.0",
"cli-width": "^2.0.0",
"external-editor": "^2.1.0",
"figures": "^2.0.0",
"lodash": "^4.3.0",
"mute-stream": "0.0.7",
"run-async": "^2.2.0",
"rxjs": "^5.5.2",
"string-width": "^2.1.0",
"strip-ansi": "^4.0.0",
"through": "^2.3.6"
}
},
"is-fullwidth-code-point": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
"integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8="
},
"json-schema-traverse": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="
},
"rxjs": {
"version": "5.5.11",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-5.5.11.tgz",
"integrity": "sha512-3bjO7UwWfA2CV7lmwYMBzj4fQ6Cq+ftHc2MvUe+WMS7wcdJ1LosDWmdjPQanYp2dBRj572p7PeU81JUxHKOcBA==",
"requires": {
"symbol-observable": "1.0.1"
}
},
"string-width": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
"integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==",
"requires": {
"is-fullwidth-code-point": "^2.0.0",
"strip-ansi": "^4.0.0"
}
},
"strip-ansi": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz",
......@@ -5189,12 +5246,12 @@
}
},
"external-editor": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.2.0.tgz",
"integrity": "sha512-bSn6gvGxKt+b7+6TKEv1ZycHleA7aHhRHyAqJyp5pbUFuYYNIzpZnQDk7AsYckyWdEnTeAnay0aCy2aV6iTk9A==",
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.0.1.tgz",
"integrity": "sha512-e1neqvSt5pSwQcFnYc6yfGuJD2Q4336cdbHs5VeUO0zTkqPbrHMyw2q1r47fpfLWbvIG8H8A6YO3sck7upTV6Q==",
"requires": {
"chardet": "^0.4.0",
"iconv-lite": "^0.4.17",
"chardet": "^0.5.0",
"iconv-lite": "^0.4.22",
"tmp": "^0.0.33"
}
},
......@@ -6907,20 +6964,20 @@
}
},
"inquirer": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/inquirer/-/inquirer-5.2.0.tgz",
"integrity": "sha512-E9BmnJbAKLPGonz0HeWHtbKf+EeSP93paWO3ZYoUpq/aowXvYGjjCSuashhXPpzbArIjBbji39THkxTz9ZeEUQ==",
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/inquirer/-/inquirer-6.2.0.tgz",
"integrity": "sha512-QIEQG4YyQ2UYZGDC4srMZ7BjHOmNk1lR2JQj5UknBapklm6WHA+VVH7N+sUdX3A7NeCfGF8o4X1S3Ao7nAcIeg==",
"requires": {
"ansi-escapes": "^3.0.0",
"chalk": "^2.0.0",
"cli-cursor": "^2.1.0",
"cli-width": "^2.0.0",
"external-editor": "^2.1.0",
"external-editor": "^3.0.0",
"figures": "^2.0.0",
"lodash": "^4.3.0",
"lodash": "^4.17.10",
"mute-stream": "0.0.7",
"run-async": "^2.2.0",
"rxjs": "^5.5.2",
"rxjs": "^6.1.0",
"string-width": "^2.1.0",
"strip-ansi": "^4.0.0",
"through": "^2.3.6"
......@@ -9997,6 +10054,16 @@
"resolved": "https://registry.npmjs.org/replace-ext/-/replace-ext-1.0.0.tgz",
"integrity": "sha1-3mMSg3P8v3w8z6TeWkgMRaZ5WOs="
},
"replace-in-file": {
"version": "3.4.2",
"resolved": "https://registry.npmjs.org/replace-in-file/-/replace-in-file-3.4.2.tgz",
"integrity": "sha512-wb2EU5MBBqUty+b1xSIqa0IKs5M2/a+4Ldw8KM5Gpe1btv16K0eii6nMxyNhAmRZhCEPrge0ss5Ij9f7vJEYcw==",
"requires": {
"chalk": "^2.4.1",
"glob": "^7.1.2",
"yargs": "^12.0.1"
}
},
"request": {
"version": "2.87.0",
"resolved": "https://registry.npmjs.org/request/-/request-2.87.0.tgz",
......@@ -10132,11 +10199,11 @@
"integrity": "sha1-pfE/957zt0D+MKqAP7CfmIBdR4I="
},
"rxjs": {
"version": "5.5.11",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-5.5.11.tgz",
"integrity": "sha512-3bjO7UwWfA2CV7lmwYMBzj4fQ6Cq+ftHc2MvUe+WMS7wcdJ1LosDWmdjPQanYp2dBRj572p7PeU81JUxHKOcBA==",
"version": "6.2.2",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.2.2.tgz",
"integrity": "sha512-0MI8+mkKAXZUF9vMrEoPnaoHkfzBPP4IGwUYRJhIRJF6/w3uByO1e91bEHn8zd43RdkTMKiooYKmwz7RH6zfOQ==",
"requires": {
"symbol-observable": "1.0.1"
"tslib": "^1.9.0"
}
},
"safe-buffer": {
......@@ -13998,6 +14065,11 @@
}
}
},
"tslib": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz",
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="
},
"tty-browserify": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.1.tgz",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment