mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
chore(all): monorepo release script
This commit is contained in:
82
.scripts/common.js
Normal file
82
.scripts/common.js
Normal file
@@ -0,0 +1,82 @@
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const execa = require('execa');
|
||||
const Listr = require('listr');
|
||||
const semver = require('semver');
|
||||
|
||||
const rootDir = path.join(__dirname, '../');
|
||||
|
||||
|
||||
function readPkg(project) {
|
||||
const packageJsonPath = path.join(rootDir, project, 'package.json');
|
||||
return JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
||||
}
|
||||
|
||||
function rootPath() {
|
||||
return rootDir;
|
||||
}
|
||||
|
||||
function projectPath(project) {
|
||||
return path.join(rootDir, project);
|
||||
}
|
||||
|
||||
async function checkGit() {
|
||||
const listr = new Listr([
|
||||
{
|
||||
title: 'Check npm version',
|
||||
skip: () => isVersionLower('6.0.0', process.version),
|
||||
task: () => execa.stdout('npm', ['version', '--json']).then(json => {
|
||||
const versions = JSON.parse(json);
|
||||
if (!satisfies(versions.npm, '>=2.15.8 <3.0.0 || >=3.10.1')) {
|
||||
throw new Error(`npm@${versions.npm} has known issues publishing when running Node.js 6. Please upgrade npm or downgrade Node and publish again. https://github.com/npm/npm/issues/5082`);
|
||||
}
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Check current branch',
|
||||
task: () => execa.stdout('git', ['symbolic-ref', '--short', 'HEAD']).then(branch => {
|
||||
if (branch !== 'master' && branch !== 'core') {
|
||||
throw new Error('Not on `master` or `core` branch');
|
||||
}
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Check local working tree',
|
||||
task: () => execa.stdout('git', ['status', '--porcelain']).then(status => {
|
||||
if (status !== '') {
|
||||
throw new Error('Unclean working tree. Commit or stash changes first.');
|
||||
}
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Check remote history',
|
||||
task: () => execa.stdout('git', ['rev-list', '--count', '--left-only', '@{u}...HEAD']).then(result => {
|
||||
if (result !== '0') {
|
||||
throw new Error('Remote history differs. Please pull changes.');
|
||||
}
|
||||
})
|
||||
}
|
||||
]);
|
||||
await listr.run();
|
||||
}
|
||||
|
||||
const satisfies = (version, range) => semver.satisfies(version, range);
|
||||
|
||||
const isValidVersion = input => Boolean(semver.valid(input));
|
||||
|
||||
const isVersionLower = (oldVersion, newVersion) => {
|
||||
if (!isValidVersion(newVersion)) {
|
||||
throw new Error('Version should be a valid semver version.');
|
||||
}
|
||||
|
||||
return semver.lt(newVersion, oldVersion);
|
||||
};
|
||||
|
||||
|
||||
module.exports = {
|
||||
isValidVersion,
|
||||
readPkg,
|
||||
rootPath,
|
||||
projectPath,
|
||||
checkGit,
|
||||
};
|
||||
@@ -7,20 +7,19 @@ const execa = require('execa');
|
||||
const inquirer = require('inquirer');
|
||||
const Listr = require('listr');
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const semver = require('semver');
|
||||
const common = require('./common');
|
||||
const path = require('path');
|
||||
|
||||
const rootDir = path.join(__dirname, '../');
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
await checkGit();
|
||||
await common.checkGit();
|
||||
|
||||
const version = await askVersion();
|
||||
await checkTagVersion(version);
|
||||
await prepareProject('core', version);
|
||||
await link('core', 'angular');
|
||||
await prepareProject('angular', version);
|
||||
await prepareProject('angular', version, ['@ionic/core']);
|
||||
|
||||
await generateChangeLog(version);
|
||||
process.exit(0);
|
||||
@@ -30,46 +29,6 @@ async function main() {
|
||||
}
|
||||
}
|
||||
|
||||
async function checkGit() {
|
||||
const listr = new Listr([
|
||||
{
|
||||
title: 'Check npm version',
|
||||
skip: () => isVersionLower('6.0.0', process.version),
|
||||
task: () => execa.stdout('npm', ['version', '--json']).then(json => {
|
||||
const versions = JSON.parse(json);
|
||||
if (!satisfies(versions.npm, '>=2.15.8 <3.0.0 || >=3.10.1')) {
|
||||
throw new Error(`npm@${versions.npm} has known issues publishing when running Node.js 6. Please upgrade npm or downgrade Node and publish again. https://github.com/npm/npm/issues/5082`);
|
||||
}
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Check current branch',
|
||||
task: () => execa.stdout('git', ['symbolic-ref', '--short', 'HEAD']).then(branch => {
|
||||
if (branch !== 'master' && branch !== 'core') {
|
||||
throw new Error('Not on `master` or `core` branch');
|
||||
}
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Check local working tree',
|
||||
task: () => execa.stdout('git', ['status', '--porcelain']).then(status => {
|
||||
if (status !== '') {
|
||||
throw new Error('Unclean working tree. Commit or stash changes first.');
|
||||
}
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Check remote history',
|
||||
task: () => execa.stdout('git', ['rev-list', '--count', '--left-only', '@{u}...HEAD']).then(result => {
|
||||
if (result !== '0') {
|
||||
throw new Error('Remote history differs. Please pull changes.');
|
||||
}
|
||||
})
|
||||
}
|
||||
]);
|
||||
await listr.run();
|
||||
}
|
||||
|
||||
async function checkTagVersion(version) {
|
||||
const listr = new Listr([
|
||||
{
|
||||
@@ -106,7 +65,7 @@ async function checkTagVersion(version) {
|
||||
|
||||
|
||||
async function askVersion() {
|
||||
const pkg = readPkg('core');
|
||||
const pkg = common.readPkg('core');
|
||||
const oldVersion = pkg.version;
|
||||
|
||||
const prompts = [
|
||||
@@ -158,15 +117,14 @@ async function askVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
async function prepareProject(project, version) {
|
||||
const projectRoot = path.join(rootDir, project);
|
||||
const pkg = readPkg(project);
|
||||
async function prepareProject(project, version, dependencies) {
|
||||
const projectRoot = common.projectPath(project);
|
||||
const pkg = common.readPkg(project);
|
||||
const oldVersion = pkg.version;
|
||||
|
||||
console.log(`\nPrepare to publish a new version of ${chalk.bold.magenta(pkg.name)} ${chalk.dim(`(${oldVersion})`)}\n`);
|
||||
console.log(`\nPrepare to publish a new version of ${chalk.bold.magenta(pkg.name)} ${chalk.dim(`(${oldVersion}) => (${version})`)}\n`);
|
||||
|
||||
|
||||
const listr = new Listr([
|
||||
const tasks = [
|
||||
{
|
||||
title: 'Validate version',
|
||||
task: () => {
|
||||
@@ -177,12 +135,28 @@ async function prepareProject(project, version) {
|
||||
},
|
||||
{
|
||||
title: 'Cleanup',
|
||||
task: () => fs.remove('node_modules')
|
||||
task: () => fs.remove(path.join(projectRoot, 'node_modules'))
|
||||
},
|
||||
{
|
||||
title: 'Install npm dependencies',
|
||||
task: () => execa('npm', ['install'], { cwd: projectRoot }),
|
||||
},
|
||||
}];
|
||||
|
||||
if (dependencies && dependencies.length > 0) {
|
||||
tasks.push(
|
||||
{
|
||||
title: 'Linking local dependencies',
|
||||
task: () => {
|
||||
return new Listr(dependencies.map(dep => ({
|
||||
title: dep,
|
||||
task: () => execa('npm', ['link', dep], { cwd: projectRoot }),
|
||||
})));
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
tasks.push(
|
||||
{
|
||||
title: 'Run lint',
|
||||
task: () => execa('npm', ['run', 'lint'], { cwd: projectRoot })
|
||||
@@ -196,15 +170,22 @@ async function prepareProject(project, version) {
|
||||
task: () => execa('npm', ['test'], { cwd: projectRoot })
|
||||
},
|
||||
{
|
||||
title: 'Set package.json version',
|
||||
title: 'Linking',
|
||||
task: () => execa('npm', ['link'], { cwd: projectRoot })
|
||||
},
|
||||
{
|
||||
title: `Updating ${project}/package.json version ${chalk.dim(`(${version})`)}`,
|
||||
task: () => execa('npm', ['version', version], { cwd: projectRoot }),
|
||||
},
|
||||
], { showSubtasks: false });
|
||||
);
|
||||
|
||||
const listr = new Listr(tasks, { showSubtasks: false });
|
||||
await listr.run();
|
||||
}
|
||||
|
||||
|
||||
async function generateChangeLog() {
|
||||
const rootDir = common.rootPath();
|
||||
const listr = new Listr([{
|
||||
title: 'Generate CHANGELOG',
|
||||
task: () => execa('npm', ['run', 'changelog'], { cwd: rootDir }),
|
||||
@@ -218,7 +199,7 @@ const PRERELEASE_VERSIONS = ['prepatch', 'preminor', 'premajor', 'prerelease'];
|
||||
|
||||
const isValidVersion = input => Boolean(semver.valid(input));
|
||||
|
||||
const isValidVersionInput = input => SEMVER_INCREMENTS.indexOf(input) !== -1 || isValidVersion(input);
|
||||
const isValidVersionInput = input => SEMVER_INCREMENTS.indexOf(input) !== -1 || common.isValidVersion(input);
|
||||
|
||||
const isPrereleaseVersion = version => PRERELEASE_VERSIONS.indexOf(version) !== -1 || Boolean(semver.prerelease(version));
|
||||
|
||||
@@ -231,23 +212,13 @@ function getNewVersion(oldVersion, input) {
|
||||
};
|
||||
|
||||
const isVersionGreater = (oldVersion, newVersion) => {
|
||||
if (!isValidVersion(newVersion)) {
|
||||
if (!common.isValidVersion(newVersion)) {
|
||||
throw new Error('Version should be a valid semver version.');
|
||||
}
|
||||
|
||||
return semver.gt(newVersion, oldVersion);
|
||||
};
|
||||
|
||||
const isVersionLower = (oldVersion, newVersion) => {
|
||||
if (!isValidVersion(newVersion)) {
|
||||
throw new Error('Version should be a valid semver version.');
|
||||
}
|
||||
|
||||
return semver.lt(newVersion, oldVersion);
|
||||
};
|
||||
|
||||
const satisfies = (version, range) => semver.satisfies(version, range);
|
||||
|
||||
|
||||
function prettyVersionDiff(oldVersion, inc) {
|
||||
const newVersion = getNewVersion(oldVersion, inc).split('.');
|
||||
@@ -270,11 +241,4 @@ function prettyVersionDiff(oldVersion, inc) {
|
||||
return output.join(chalk.reset.dim('.'));
|
||||
}
|
||||
|
||||
|
||||
function readPkg(project) {
|
||||
const packageJsonPath = path.join(rootDir, project, 'package.json');
|
||||
return JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
||||
}
|
||||
|
||||
|
||||
main();
|
||||
|
||||
@@ -4,42 +4,42 @@
|
||||
*/
|
||||
const chalk = require('chalk');
|
||||
const execa = require('execa');
|
||||
const inquirer = require('inquirer');
|
||||
const Listr = require('listr');
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const semver = require('semver');
|
||||
const common = require('./common');
|
||||
|
||||
const rootDir = path.join(__dirname, '../');
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
await publishProject('core');
|
||||
await publishProject('angular');
|
||||
const {version} = common.readPkg('core');
|
||||
|
||||
await publishGit();
|
||||
await common.checkGit();
|
||||
|
||||
await publishProject('core', version);
|
||||
await publishProject('angular', version);
|
||||
|
||||
await publishGit(version);
|
||||
process.exit(0);
|
||||
|
||||
} catch(err) {
|
||||
} catch (err) {
|
||||
console.log('\n', chalk.red(err), '\n');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
async function publishProject(project) {
|
||||
const projectRoot = path.join(rootDir, project);
|
||||
const pkg = readPkg(project);
|
||||
async function publishProject(project, version) {
|
||||
const projectRoot = common.projectPath(project);
|
||||
const listr = new Listr([{
|
||||
title: 'Publish ' + pkg.name,
|
||||
task: () => execa('npm', ['publish'].concat(opts.tag ? ['--tag', opts.tag] : []), { cwd: projectRoot })
|
||||
title: `Publish (latest) ${project} (v${version})`,
|
||||
task: () => execa('npm', ['publish'].concat(opts.tag ? ['--tag', 'latest'] : []), { cwd: projectRoot })
|
||||
}], { showSubtasks: false });
|
||||
await listr.run();
|
||||
}
|
||||
|
||||
async function publishGit() {
|
||||
async function publishGit(version) {
|
||||
const rootDir = common.rootPath();
|
||||
const listr = new Listr([{
|
||||
title: 'Tagging the latest commit',
|
||||
task: () => execa('git', ['tag', `v${opts.version}`], { cwd: rootDir })
|
||||
task: () => execa('git', ['tag', `v${version}`], { cwd: rootDir })
|
||||
},
|
||||
{
|
||||
title: 'Pushing to Github',
|
||||
@@ -48,9 +48,4 @@ async function publishGit() {
|
||||
await listr.run();
|
||||
}
|
||||
|
||||
function readPkg(project) {
|
||||
const packageJsonPath = path.join(rootDir, project, 'package.json');
|
||||
return JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
70
angular/package-lock.json
generated
70
angular/package-lock.json
generated
@@ -5,27 +5,27 @@
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@angular/common": {
|
||||
"version": "5.2.8",
|
||||
"resolved": "https://registry.npmjs.org/@angular/common/-/common-5.2.8.tgz",
|
||||
"integrity": "sha512-vHODEZPDtBU5b7a2GjtQYPYmCPRq5FQsJp696pebGMJEZdvN/Du43z8V7lWEdBBLGD+oNXX6rXGD9Pr4P/Bg9w==",
|
||||
"version": "5.2.9",
|
||||
"resolved": "https://registry.npmjs.org/@angular/common/-/common-5.2.9.tgz",
|
||||
"integrity": "sha512-g2hPcI0fnT4TV+Fd+1IohjuqBxPvxwyH9IzTn8PkU9X2M+F6cHCUvHxL1sWI2sF8pYcaHzVjq9WClym10X36Lg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"tslib": "1.9.0"
|
||||
}
|
||||
},
|
||||
"@angular/compiler": {
|
||||
"version": "5.2.8",
|
||||
"resolved": "https://registry.npmjs.org/@angular/compiler/-/compiler-5.2.8.tgz",
|
||||
"integrity": "sha512-xFqY7LDt/LGo6zaYzUwDRGq6Dm2Q9Z2R86ZNdy5wYRzMP+qLnwwENbU74YailKlt02WNtp83R1fdRDDlKI8N+Q==",
|
||||
"version": "5.2.9",
|
||||
"resolved": "https://registry.npmjs.org/@angular/compiler/-/compiler-5.2.9.tgz",
|
||||
"integrity": "sha512-mN+ofInk8y/tk2TCJZx8RrGdOKdrfunoCair7tfDy4XoQJE90waGfaYWo07hYU+UYwLhrg19m2Czy6rIDciUJA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"tslib": "1.9.0"
|
||||
}
|
||||
},
|
||||
"@angular/compiler-cli": {
|
||||
"version": "5.2.8",
|
||||
"resolved": "https://registry.npmjs.org/@angular/compiler-cli/-/compiler-cli-5.2.8.tgz",
|
||||
"integrity": "sha512-u0cUfpbU2VNmRfkSS/tlsAzF24/LdlXqv8RFFLReJhwZTv4mKl1DzSjvOf6kfALGHDqCdHsVWcx2YJ8f6CeCMg==",
|
||||
"version": "5.2.9",
|
||||
"resolved": "https://registry.npmjs.org/@angular/compiler-cli/-/compiler-cli-5.2.9.tgz",
|
||||
"integrity": "sha512-LAEpL/6PAev3zwTow/43Atzv9AtKLAiLoS285X3EV1f80yQpYAmFRrPUtDlrIZdhZHBBv7CxnyCVpOLU3T8ohw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"chokidar": "1.7.0",
|
||||
@@ -35,54 +35,54 @@
|
||||
}
|
||||
},
|
||||
"@angular/core": {
|
||||
"version": "5.2.8",
|
||||
"resolved": "https://registry.npmjs.org/@angular/core/-/core-5.2.8.tgz",
|
||||
"integrity": "sha512-exvh2OY+WDm90bgzZ89Asi2nZc2zrg/OWJuKMbxNfA6nxnyjCQ7uGRjTGr+MOynG+vd54J2Evtg2eDPdbcNg5A==",
|
||||
"version": "5.2.9",
|
||||
"resolved": "https://registry.npmjs.org/@angular/core/-/core-5.2.9.tgz",
|
||||
"integrity": "sha512-cvHBJGtasrIoARvbLFyHaOsiWKVwMNrrSTZLwrlyHP8oYzkDrE0qKGer6QCqyKt+51hF53cgWEffGzM/u/0wYg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"tslib": "1.9.0"
|
||||
}
|
||||
},
|
||||
"@angular/forms": {
|
||||
"version": "5.2.8",
|
||||
"resolved": "https://registry.npmjs.org/@angular/forms/-/forms-5.2.8.tgz",
|
||||
"integrity": "sha512-yxpFwZcek7259O1+4p1Zfd8FOEJs8lh6T8n2W7IBT8Q1pcAMBCYfMi/Xga69AbypFIy3P+V6DaJoq8ZZgpwefg==",
|
||||
"version": "5.2.9",
|
||||
"resolved": "https://registry.npmjs.org/@angular/forms/-/forms-5.2.9.tgz",
|
||||
"integrity": "sha512-zyIOiZV/FAm1iVZWTk3Joz6Jt096hbhfDbBUrssmuiTKi9dU6rWG+Z4b88zStqulKe3HFVZkgdixWlminG8nKA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"tslib": "1.9.0"
|
||||
}
|
||||
},
|
||||
"@angular/http": {
|
||||
"version": "5.2.8",
|
||||
"resolved": "https://registry.npmjs.org/@angular/http/-/http-5.2.8.tgz",
|
||||
"integrity": "sha512-vtrO7RLN9v7adVrs/neWStmrCH6+4gm1gYqUYfl6BIYnazACMleqIeAagTbTD08oMblx2dU17NRNbD+2qL8q5A==",
|
||||
"version": "5.2.9",
|
||||
"resolved": "https://registry.npmjs.org/@angular/http/-/http-5.2.9.tgz",
|
||||
"integrity": "sha512-DKjgIk+Dp0Xv1ieG8LawvUnL4dYZp1KroAq5cfKuO9EojP0zM3tUvBtw2vbPLsHYma7g7ZMjOoAbzVxtmTBZqw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"tslib": "1.9.0"
|
||||
}
|
||||
},
|
||||
"@angular/platform-browser": {
|
||||
"version": "5.2.8",
|
||||
"resolved": "https://registry.npmjs.org/@angular/platform-browser/-/platform-browser-5.2.8.tgz",
|
||||
"integrity": "sha512-f0tONG8+ZQOiv5/hLY76Sl1/BY6AR8Zt4buf2klz7zba5SxKLZwcsk6OfJC2PA0WtlJGiz7cSjbPr0B5sZKv8w==",
|
||||
"version": "5.2.9",
|
||||
"resolved": "https://registry.npmjs.org/@angular/platform-browser/-/platform-browser-5.2.9.tgz",
|
||||
"integrity": "sha512-P6iviRTuLsLRuqtZNOO0fd4cjTo8DWsDCecwntUlI08R3kH5qeqvqarTzlw/4oD+wBzZY6bfb89JyY+n5XbX3Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"tslib": "1.9.0"
|
||||
}
|
||||
},
|
||||
"@angular/platform-browser-dynamic": {
|
||||
"version": "5.2.8",
|
||||
"resolved": "https://registry.npmjs.org/@angular/platform-browser-dynamic/-/platform-browser-dynamic-5.2.8.tgz",
|
||||
"integrity": "sha512-FzHVZf5XMty0v+hnWOU5PsXexlebvW4+EhfGG85vWCM/M9y0bF3ZSmdqZoXfGO8/Px2JbcBx0r3+GKUgsCieMA==",
|
||||
"version": "5.2.9",
|
||||
"resolved": "https://registry.npmjs.org/@angular/platform-browser-dynamic/-/platform-browser-dynamic-5.2.9.tgz",
|
||||
"integrity": "sha512-8C3MtyguJKDTT8FcHIRDlBxswcIdpfugOf4S2t94pVedCr4h9w2da/lcfwJKUISw1aKjfA77Sl8TDUhoS8ymmQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"tslib": "1.9.0"
|
||||
}
|
||||
},
|
||||
"@angular/router": {
|
||||
"version": "5.2.8",
|
||||
"resolved": "https://registry.npmjs.org/@angular/router/-/router-5.2.8.tgz",
|
||||
"integrity": "sha512-v4k1eUpauO8z/q9kcjr+vDhLvvGw5MzctJJQRoObqLhckFGBmAoITfEFsbF1ejsd/nqa9i+ivxe+LB00evbFXw==",
|
||||
"version": "5.2.9",
|
||||
"resolved": "https://registry.npmjs.org/@angular/router/-/router-5.2.9.tgz",
|
||||
"integrity": "sha512-NtDbFK0EA1rfFc+5Dqd5mIv8E1Wcc5rDUnSty4cX2V+HxTEZvQ9DRdpO2Q0abWU5siXyqponuPHJzF08OVGyNA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"tslib": "1.9.0"
|
||||
@@ -600,7 +600,7 @@
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"nan": "2.9.2",
|
||||
"nan": "2.10.0",
|
||||
"node-pre-gyp": "0.6.39"
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -2216,9 +2216,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"nan": {
|
||||
"version": "2.9.2",
|
||||
"resolved": "https://registry.npmjs.org/nan/-/nan-2.9.2.tgz",
|
||||
"integrity": "sha512-ltW65co7f3PQWBDbqVvaU1WtFJUsNW7sWWm4HINhbMQIyVyzIeyZ8toX5TC5eeooE6piZoaEh4cZkueSKG3KYw==",
|
||||
"version": "2.10.0",
|
||||
"resolved": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz",
|
||||
"integrity": "sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
@@ -2633,9 +2633,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"source-map-support": {
|
||||
"version": "0.5.3",
|
||||
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.3.tgz",
|
||||
"integrity": "sha512-eKkTgWYeBOQqFGXRfKabMFdnWepo51vWqEdoeikaEPFiJC7MCU5j2h4+6Q8npkZTeLGbSyecZvRxiSoWl3rh+w==",
|
||||
"version": "0.5.4",
|
||||
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.4.tgz",
|
||||
"integrity": "sha512-PETSPG6BjY1AHs2t64vS2aqAgu6dMIMXJULWFBGbh2Gr8nVLbCFDo6i/RMMvviIQ2h1Z8+5gQhVKSn2je9nmdg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"source-map": "0.6.1"
|
||||
@@ -2729,7 +2729,7 @@
|
||||
"minimist": "1.2.0",
|
||||
"mkdirp": "0.5.1",
|
||||
"source-map": "0.6.1",
|
||||
"source-map-support": "0.5.3"
|
||||
"source-map-support": "0.5.4"
|
||||
}
|
||||
},
|
||||
"tslib": {
|
||||
|
||||
@@ -25,10 +25,7 @@
|
||||
"clean": "node scripts/clean.js",
|
||||
"clean-generated": "node ./scripts/clean-generated.js",
|
||||
"compile": "./node_modules/.bin/ngc",
|
||||
"deploy": "node scripts/deploy.js",
|
||||
"lint": "tslint --project .",
|
||||
"prepare.deploy": "node scripts/deploy.js --prepare",
|
||||
"set.version": "node scripts/set-version.js",
|
||||
"tsc": "tsc -p ."
|
||||
},
|
||||
"main": "./dist/index.js",
|
||||
@@ -46,7 +43,7 @@
|
||||
"@angular/platform-browser": "latest",
|
||||
"@angular/platform-browser-dynamic": "latest",
|
||||
"@angular/router": "latest",
|
||||
"@ionic/core": "^0.1.3",
|
||||
"@ionic/core": "latest",
|
||||
"chalk": "^2.3.2",
|
||||
"execa": "^0.9.0",
|
||||
"fs-extra": "^5.0.0",
|
||||
|
||||
396
angular/scripts/deploy.js
vendored
396
angular/scripts/deploy.js
vendored
@@ -1,396 +0,0 @@
|
||||
/**
|
||||
* Deploy script adopted from https://github.com/sindresorhus/np
|
||||
* MIT License (c) Sindre Sorhus (sindresorhus.com)
|
||||
*/
|
||||
const chalk = require('chalk');
|
||||
const execa = require('execa');
|
||||
const inquirer = require('inquirer');
|
||||
const Listr = require('listr');
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const semver = require('semver');
|
||||
|
||||
|
||||
const rootDir = path.join(__dirname, '../');
|
||||
const packageJsonPath = path.join(rootDir, 'package.json');
|
||||
|
||||
|
||||
function runTasks(opts) {
|
||||
const pkg = readPkg();
|
||||
|
||||
const tasks = [];
|
||||
let newVersion = getNewVersion(pkg.version, opts.version);
|
||||
|
||||
if (opts.prepare) {
|
||||
tasks.push(
|
||||
{
|
||||
title: 'Validate version',
|
||||
task: () => {
|
||||
if (!isValidVersionInput(opts.version)) {
|
||||
throw new Error(`Version should be either ${SEMVER_INCREMENTS.join(', ')}, or a valid semver version.`);
|
||||
}
|
||||
|
||||
if (!isVersionGreater(pkg.version, newVersion)) {
|
||||
throw new Error(`New version \`${newVersion}\` should be higher than current version \`${pkg.version}\``);
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (opts.publish) {
|
||||
tasks.push(
|
||||
{
|
||||
title: 'Check for pre-release version',
|
||||
task: () => {
|
||||
if (!pkg.private && isPrereleaseVersion(newVersion) && !opts.tag) {
|
||||
throw new Error('You must specify a dist-tag using --tag when publishing a pre-release version. This prevents accidentally tagging unstable versions as "latest". https://docs.npmjs.com/cli/dist-tag');
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
tasks.push(
|
||||
{
|
||||
title: 'Check npm version',
|
||||
skip: () => isVersionLower('6.0.0', process.version),
|
||||
task: () => execa.stdout('npm', ['version', '--json']).then(json => {
|
||||
const versions = JSON.parse(json);
|
||||
if (!satisfies(versions.npm, '>=2.15.8 <3.0.0 || >=3.10.1')) {
|
||||
throw new Error(`npm@${versions.npm} has known issues publishing when running Node.js 6. Please upgrade npm or downgrade Node and publish again. https://github.com/npm/npm/issues/5082`);
|
||||
}
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Check git tag existence',
|
||||
task: () => execa('git', ['fetch'])
|
||||
.then(() => {
|
||||
return execa.stdout('npm', ['config', 'get', 'tag-version-prefix']);
|
||||
})
|
||||
.then(
|
||||
output => {
|
||||
tagPrefix = output;
|
||||
},
|
||||
() => {}
|
||||
)
|
||||
.then(() => execa.stdout('git', ['rev-parse', '--quiet', '--verify', `refs/tags/${tagPrefix}${newVersion}`]))
|
||||
.then(
|
||||
output => {
|
||||
if (output) {
|
||||
throw new Error(`Git tag \`${tagPrefix}${newVersion}\` already exists.`);
|
||||
}
|
||||
},
|
||||
err => {
|
||||
// Command fails with code 1 and no output if the tag does not exist, even though `--quiet` is provided
|
||||
// https://github.com/sindresorhus/np/pull/73#discussion_r72385685
|
||||
if (err.stdout !== '' || err.stderr !== '') {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
{
|
||||
title: 'Check current branch',
|
||||
task: () => execa.stdout('git', ['symbolic-ref', '--short', 'HEAD']).then(branch => {
|
||||
if (branch !== 'master' && branch !== 'core') {
|
||||
throw new Error('Not on `master` or `core` branch');
|
||||
}
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Check local working tree',
|
||||
task: () => execa.stdout('git', ['status', '--porcelain']).then(status => {
|
||||
if (status !== '') {
|
||||
throw new Error('Unclean working tree. Commit or stash changes first.');
|
||||
}
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Check remote history',
|
||||
task: () => execa.stdout('git', ['rev-list', '--count', '--left-only', '@{u}...HEAD']).then(result => {
|
||||
if (result !== '0') {
|
||||
throw new Error('Remote history differs. Please pull changes.');
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
|
||||
if (opts.prepare) {
|
||||
tasks.push(
|
||||
{
|
||||
title: 'Cleanup',
|
||||
task: () => fs.remove('node_modules')
|
||||
},
|
||||
{
|
||||
title: 'Install npm dependencies',
|
||||
task: () => execa('npm', ['install'], { cwd: rootDir }),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
tasks.push(
|
||||
{
|
||||
title: 'Run lint',
|
||||
task: () => execa('npm', ['run', 'lint'], { cwd: rootDir })
|
||||
},
|
||||
{
|
||||
title: 'Build ' + pkg.name,
|
||||
task: () => execa('npm', ['run', 'build'], { cwd: rootDir })
|
||||
},
|
||||
{
|
||||
title: 'Run tests',
|
||||
task: () => execa('npm', ['test'], { cwd: rootDir })
|
||||
}
|
||||
);
|
||||
|
||||
if (opts.prepare){
|
||||
tasks.push(
|
||||
{
|
||||
title: 'Set package.json version',
|
||||
task: () => execa('npm', ['run', 'set.version', opts.version], { cwd: rootDir }),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (opts.publish) {
|
||||
tasks.push(
|
||||
{
|
||||
title: 'Publish ' + pkg.name,
|
||||
task: () => execa('npm', ['publish'].concat(opts.tag ? ['--tag', opts.tag] : []), { cwd: rootDir })
|
||||
},
|
||||
{
|
||||
title: 'Tagging the latest commit',
|
||||
task: () => execa('git', ['tag', `${pkg.name}-v${opts.version}`], { cwd: rootDir })
|
||||
},
|
||||
{
|
||||
title: 'Pushing to Github',
|
||||
task: () => execa('git', ['push', '--tags'], { cwd: rootDir })
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const listr = new Listr(tasks, { showSubtasks: false });
|
||||
|
||||
return listr.run()
|
||||
.then(() => {
|
||||
if (opts.prepare) {
|
||||
console.log(`\n ${pkg.name} ${newVersion} prepared, check the diffs and commit 🕵️\n`);
|
||||
} else if (opts.publish) {
|
||||
console.log(`\n ${pkg.name} ${newVersion} published!! 🎉\n`);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('\n', chalk.red(err), '\n');
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function prepareUI() {
|
||||
const pkg = readPkg();
|
||||
const oldVersion = pkg.version;
|
||||
|
||||
console.log(`\nPrepare to publish a new version of ${chalk.bold.magenta(pkg.name)} ${chalk.dim(`(${oldVersion})`)}\n`);
|
||||
|
||||
const prompts = [
|
||||
{
|
||||
type: 'list',
|
||||
name: 'version',
|
||||
message: 'Select semver increment or specify new version',
|
||||
pageSize: SEMVER_INCREMENTS.length + 2,
|
||||
choices: SEMVER_INCREMENTS
|
||||
.map(inc => ({
|
||||
name: `${inc} ${prettyVersionDiff(oldVersion, inc)}`,
|
||||
value: inc
|
||||
}))
|
||||
.concat([
|
||||
new inquirer.Separator(),
|
||||
{
|
||||
name: 'Other (specify)',
|
||||
value: null
|
||||
}
|
||||
]),
|
||||
filter: input => isValidVersionInput(input) ? getNewVersion(oldVersion, input) : input
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: 'version',
|
||||
message: 'Version',
|
||||
when: answers => !answers.version,
|
||||
filter: input => isValidVersionInput(input) ? getNewVersion(pkg.version, input) : input,
|
||||
validate: input => {
|
||||
if (!isValidVersionInput(input)) {
|
||||
return 'Please specify a valid semver, for example, `1.2.3`. See http://semver.org';
|
||||
} else if (!isVersionGreater(oldVersion, input)) {
|
||||
return `Version must be greater than ${oldVersion}`;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'confirm',
|
||||
message: answers => {
|
||||
return `Will bump from ${chalk.cyan(oldVersion)} to ${chalk.cyan(answers.version)}. Continue?`;
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
return inquirer
|
||||
.prompt(prompts)
|
||||
.then(answers => {
|
||||
if (answers.confirm){
|
||||
answers.prepare = true;
|
||||
answers.publish = false;
|
||||
runTasks(answers);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('\n', chalk.red(err), '\n');
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
function publishUI() {
|
||||
const pkg = readPkg();
|
||||
const version = pkg.version;
|
||||
|
||||
console.log(`\nPublish a new version of ${chalk.bold.magenta(pkg.name)} ${chalk.dim(`(${version})`)}\n`);
|
||||
|
||||
const prompts = [
|
||||
{
|
||||
type: 'list',
|
||||
name: 'tag',
|
||||
message: 'How should this pre-release version be tagged in npm?',
|
||||
when: answers => isPrereleaseVersion(version),
|
||||
choices: () => execa.stdout('npm', ['view', '--json', pkg.name, 'dist-tags'])
|
||||
.then(stdout => {
|
||||
const existingPrereleaseTags = Object.keys(JSON.parse(stdout))
|
||||
.filter(tag => tag !== 'latest');
|
||||
|
||||
if (existingPrereleaseTags.length === 0) {
|
||||
existingPrereleaseTags.push('next');
|
||||
}
|
||||
|
||||
return existingPrereleaseTags
|
||||
.concat([
|
||||
new inquirer.Separator(),
|
||||
{
|
||||
name: 'Other (specify)',
|
||||
value: null
|
||||
}
|
||||
]);
|
||||
})
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: 'tag',
|
||||
message: 'Tag',
|
||||
when: answers => !pkg.private && isPrereleaseVersion(version) && !answers.tag,
|
||||
validate: input => {
|
||||
if (input.length === 0) {
|
||||
return 'Please specify a tag, for example, `next`.';
|
||||
} else if (input.toLowerCase() === 'latest') {
|
||||
return 'It\'s not possible to publish pre-releases under the `latest` tag. Please specify something else, for example, `next`.';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'confirm',
|
||||
message: answers => {
|
||||
const tag = answers.tag;
|
||||
const tagPart = tag ? ` and tag this release in npm as ${tag}` : '';
|
||||
|
||||
return `Will publish ${chalk.cyan(version + tagPart)}. Continue?`;
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
return inquirer
|
||||
.prompt(prompts)
|
||||
.then(answers => {
|
||||
if (answers.confirm){
|
||||
answers.version = version;
|
||||
answers.prepare = false;
|
||||
answers.publish = true;
|
||||
runTasks(answers);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('\n', chalk.red(err), '\n');
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const SEMVER_INCREMENTS = ['patch', 'minor', 'major', 'prepatch', 'preminor', 'premajor', 'prerelease'];
|
||||
const PRERELEASE_VERSIONS = ['prepatch', 'preminor', 'premajor', 'prerelease'];
|
||||
|
||||
const isValidVersion = input => Boolean(semver.valid(input));
|
||||
|
||||
const isValidVersionInput = input => SEMVER_INCREMENTS.indexOf(input) !== -1 || isValidVersion(input);
|
||||
|
||||
const isPrereleaseVersion = version => PRERELEASE_VERSIONS.indexOf(version) !== -1 || Boolean(semver.prerelease(version));
|
||||
|
||||
function getNewVersion(oldVersion, input) {
|
||||
if (!isValidVersionInput(input)) {
|
||||
throw new Error(`Version should be either ${SEMVER_INCREMENTS.join(', ')} or a valid semver version.`);
|
||||
}
|
||||
|
||||
return SEMVER_INCREMENTS.indexOf(input) === -1 ? input : semver.inc(oldVersion, input);
|
||||
};
|
||||
|
||||
const isVersionGreater = (oldVersion, newVersion) => {
|
||||
if (!isValidVersion(newVersion)) {
|
||||
throw new Error('Version should be a valid semver version.');
|
||||
}
|
||||
|
||||
return semver.gt(newVersion, oldVersion);
|
||||
};
|
||||
|
||||
const isVersionLower = (oldVersion, newVersion) => {
|
||||
if (!isValidVersion(newVersion)) {
|
||||
throw new Error('Version should be a valid semver version.');
|
||||
}
|
||||
|
||||
return semver.lt(newVersion, oldVersion);
|
||||
};
|
||||
|
||||
const satisfies = (version, range) => semver.satisfies(version, range);
|
||||
|
||||
const readPkg = () => {
|
||||
return JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
||||
};
|
||||
|
||||
function prettyVersionDiff(oldVersion, inc) {
|
||||
const newVersion = getNewVersion(oldVersion, inc).split('.');
|
||||
oldVersion = oldVersion.split('.');
|
||||
let firstVersionChange = false;
|
||||
const output = [];
|
||||
|
||||
for (let i = 0; i < newVersion.length; i++) {
|
||||
if ((newVersion[i] !== oldVersion[i] && !firstVersionChange)) {
|
||||
output.push(`${chalk.dim.cyan(newVersion[i])}`);
|
||||
firstVersionChange = true;
|
||||
} else if (newVersion[i].indexOf('-') >= 1) {
|
||||
let preVersion = [];
|
||||
preVersion = newVersion[i].split('-');
|
||||
output.push(`${chalk.dim.cyan(`${preVersion[0]}-${preVersion[1]}`)}`);
|
||||
} else {
|
||||
output.push(chalk.reset.dim(newVersion[i]));
|
||||
}
|
||||
}
|
||||
return output.join(chalk.reset.dim('.'));
|
||||
}
|
||||
|
||||
const prepare = process.argv.slice(2).indexOf('--prepare') > -1;
|
||||
|
||||
if (prepare) {
|
||||
prepareUI();
|
||||
} else {
|
||||
publishUI();
|
||||
}
|
||||
19
angular/scripts/set-version.js
vendored
19
angular/scripts/set-version.js
vendored
@@ -1,19 +0,0 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const packageJsonPath = path.join(__dirname, '../package.json');
|
||||
const packageLockPath = path.join(__dirname, '../package-lock.json');
|
||||
|
||||
|
||||
function getVersion() {
|
||||
return process.argv[process.argv.length - 1];
|
||||
}
|
||||
|
||||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
||||
packageJson.version = getVersion();
|
||||
|
||||
const packageLock = JSON.parse(fs.readFileSync(packageLockPath, 'utf-8'));
|
||||
packageLock.version = packageJson.version;
|
||||
|
||||
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
|
||||
fs.writeFileSync(packageLockPath, JSON.stringify(packageLock, null, 2) + '\n');
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Attribute, ChangeDetectorRef, ComponentFactoryResolver, ComponentRef, Directive, EventEmitter, Injector, OnDestroy, OnInit, Output, ViewContainerRef, ElementRef } from '@angular/core';
|
||||
import { Attribute, ChangeDetectorRef, ComponentFactoryResolver, ComponentRef, Directive, ElementRef, EventEmitter, Injector, OnDestroy, OnInit, Output, ViewContainerRef } from '@angular/core';
|
||||
import { ActivatedRoute, ChildrenOutletContexts, PRIMARY_OUTLET } from '@angular/router';
|
||||
|
||||
@Directive({
|
||||
|
||||
@@ -54,13 +54,11 @@
|
||||
"build": "npm run clean && stencil build --docs",
|
||||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
|
||||
"clean": "node scripts/clean.js",
|
||||
"deploy": "node scripts/deploy.js",
|
||||
"dev": "sd concurrent \"stencil build --dev --watch --docs\" \"stencil-dev-server\"",
|
||||
"devapp": "sd concurrent \"stencil build --dev --watch --docs\" \"stencil-dev-server --broadcast\"",
|
||||
"e2e": "node ./scripts/e2e",
|
||||
"e2e-debug": "node --inspect --debug-brk ./scripts/e2e",
|
||||
"lint": "npm run tslint & npm run sass-lint",
|
||||
"prepare.deploy": "node scripts/deploy.js --prepare",
|
||||
"sass-lint": "sass-lint -v -q",
|
||||
"set.version": "node scripts/set-version.js",
|
||||
"snapshot": "node ./scripts/e2e --snapshot",
|
||||
|
||||
@@ -1,400 +0,0 @@
|
||||
/**
|
||||
* Deploy script adopted from https://github.com/sindresorhus/np
|
||||
* MIT License (c) Sindre Sorhus (sindresorhus.com)
|
||||
*/
|
||||
const chalk = require('chalk');
|
||||
const execa = require('execa');
|
||||
const inquirer = require('inquirer');
|
||||
const Listr = require('listr');
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const semver = require('semver');
|
||||
|
||||
|
||||
const rootDir = path.join(__dirname, '../');
|
||||
const packageJsonPath = path.join(rootDir, 'package.json');
|
||||
|
||||
|
||||
function runTasks(opts) {
|
||||
const pkg = readPkg();
|
||||
|
||||
const tasks = [];
|
||||
let newVersion = getNewVersion(pkg.version, opts.version);
|
||||
|
||||
if (opts.prepare) {
|
||||
tasks.push(
|
||||
{
|
||||
title: 'Validate version',
|
||||
task: () => {
|
||||
if (!isValidVersionInput(opts.version)) {
|
||||
throw new Error(`Version should be either ${SEMVER_INCREMENTS.join(', ')}, or a valid semver version.`);
|
||||
}
|
||||
|
||||
if (!isVersionGreater(pkg.version, newVersion)) {
|
||||
throw new Error(`New version \`${newVersion}\` should be higher than current version \`${pkg.version}\``);
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (opts.publish) {
|
||||
tasks.push(
|
||||
{
|
||||
title: 'Check for pre-release version',
|
||||
task: () => {
|
||||
if (!pkg.private && isPrereleaseVersion(newVersion) && !opts.tag) {
|
||||
throw new Error('You must specify a dist-tag using --tag when publishing a pre-release version. This prevents accidentally tagging unstable versions as "latest". https://docs.npmjs.com/cli/dist-tag');
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
tasks.push(
|
||||
{
|
||||
title: 'Check npm version',
|
||||
skip: () => isVersionLower('6.0.0', process.version),
|
||||
task: () => execa.stdout('npm', ['version', '--json']).then(json => {
|
||||
const versions = JSON.parse(json);
|
||||
if (!satisfies(versions.npm, '>=2.15.8 <3.0.0 || >=3.10.1')) {
|
||||
throw new Error(`npm@${versions.npm} has known issues publishing when running Node.js 6. Please upgrade npm or downgrade Node and publish again. https://github.com/npm/npm/issues/5082`);
|
||||
}
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Check git tag existence',
|
||||
task: () => execa('git', ['fetch'])
|
||||
.then(() => {
|
||||
return execa.stdout('npm', ['config', 'get', 'tag-version-prefix']);
|
||||
})
|
||||
.then(
|
||||
output => {
|
||||
tagPrefix = output;
|
||||
},
|
||||
() => {}
|
||||
)
|
||||
.then(() => execa.stdout('git', ['rev-parse', '--quiet', '--verify', `refs/tags/${tagPrefix}${newVersion}`]))
|
||||
.then(
|
||||
output => {
|
||||
if (output) {
|
||||
throw new Error(`Git tag \`${tagPrefix}${newVersion}\` already exists.`);
|
||||
}
|
||||
},
|
||||
err => {
|
||||
// Command fails with code 1 and no output if the tag does not exist, even though `--quiet` is provided
|
||||
// https://github.com/sindresorhus/np/pull/73#discussion_r72385685
|
||||
if (err.stdout !== '' || err.stderr !== '') {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
{
|
||||
title: 'Check current branch',
|
||||
task: () => execa.stdout('git', ['symbolic-ref', '--short', 'HEAD']).then(branch => {
|
||||
if (branch !== 'master' && branch !== 'core') {
|
||||
throw new Error('Not on `master` or `core` branch');
|
||||
}
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Check local working tree',
|
||||
task: () => execa.stdout('git', ['status', '--porcelain']).then(status => {
|
||||
if (status !== '') {
|
||||
throw new Error('Unclean working tree. Commit or stash changes first.');
|
||||
}
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Check remote history',
|
||||
task: () => execa.stdout('git', ['rev-list', '--count', '--left-only', '@{u}...HEAD']).then(result => {
|
||||
if (result !== '0') {
|
||||
throw new Error('Remote history differs. Please pull changes.');
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
|
||||
if (opts.prepare) {
|
||||
tasks.push(
|
||||
{
|
||||
title: 'Cleanup',
|
||||
task: () => fs.remove('node_modules')
|
||||
},
|
||||
{
|
||||
title: 'Install npm dependencies',
|
||||
task: () => execa('npm', ['install'], { cwd: rootDir }),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
tasks.push(
|
||||
{
|
||||
title: 'Run lint',
|
||||
task: () => execa('npm', ['run', 'lint'], { cwd: rootDir })
|
||||
},
|
||||
{
|
||||
title: 'Build ' + pkg.name,
|
||||
task: () => execa('npm', ['run', 'build'], { cwd: rootDir })
|
||||
},
|
||||
{
|
||||
title: 'Run tests',
|
||||
task: () => execa('npm', ['test'], { cwd: rootDir })
|
||||
}
|
||||
);
|
||||
|
||||
if (opts.prepare){
|
||||
tasks.push(
|
||||
{
|
||||
title: 'Set package.json version',
|
||||
task: () => execa('npm', ['run', 'set.version', opts.version], { cwd: rootDir }),
|
||||
},
|
||||
{
|
||||
title: 'Generate CHANGELOG',
|
||||
task: () => execa('npm', ['run', 'changelog'], { cwd: rootDir }),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (opts.publish) {
|
||||
tasks.push(
|
||||
{
|
||||
title: 'Publish ' + pkg.name,
|
||||
task: () => execa('npm', ['publish'].concat(opts.tag ? ['--tag', opts.tag] : []), { cwd: rootDir })
|
||||
},
|
||||
{
|
||||
title: 'Tagging the latest commit',
|
||||
task: () => execa('git', ['tag', `v${opts.version}`], { cwd: rootDir })
|
||||
},
|
||||
{
|
||||
title: 'Pushing to Github',
|
||||
task: () => execa('git', ['push', '--tags'], { cwd: rootDir })
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const listr = new Listr(tasks, { showSubtasks: false });
|
||||
|
||||
return listr.run()
|
||||
.then(() => {
|
||||
if (opts.prepare) {
|
||||
console.log(`\n ${pkg.name} ${newVersion} prepared, check the diffs and commit 🕵️\n`);
|
||||
} else if (opts.publish) {
|
||||
console.log(`\n ${pkg.name} ${newVersion} published!! 🎉\n`);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('\n', chalk.red(err), '\n');
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function prepareUI() {
|
||||
const pkg = readPkg();
|
||||
const oldVersion = pkg.version;
|
||||
|
||||
console.log(`\nPrepare to publish a new version of ${chalk.bold.magenta(pkg.name)} ${chalk.dim(`(${oldVersion})`)}\n`);
|
||||
|
||||
const prompts = [
|
||||
{
|
||||
type: 'list',
|
||||
name: 'version',
|
||||
message: 'Select semver increment or specify new version',
|
||||
pageSize: SEMVER_INCREMENTS.length + 2,
|
||||
choices: SEMVER_INCREMENTS
|
||||
.map(inc => ({
|
||||
name: `${inc} ${prettyVersionDiff(oldVersion, inc)}`,
|
||||
value: inc
|
||||
}))
|
||||
.concat([
|
||||
new inquirer.Separator(),
|
||||
{
|
||||
name: 'Other (specify)',
|
||||
value: null
|
||||
}
|
||||
]),
|
||||
filter: input => isValidVersionInput(input) ? getNewVersion(oldVersion, input) : input
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: 'version',
|
||||
message: 'Version',
|
||||
when: answers => !answers.version,
|
||||
filter: input => isValidVersionInput(input) ? getNewVersion(pkg.version, input) : input,
|
||||
validate: input => {
|
||||
if (!isValidVersionInput(input)) {
|
||||
return 'Please specify a valid semver, for example, `1.2.3`. See http://semver.org';
|
||||
} else if (!isVersionGreater(oldVersion, input)) {
|
||||
return `Version must be greater than ${oldVersion}`;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'confirm',
|
||||
message: answers => {
|
||||
return `Will bump from ${chalk.cyan(oldVersion)} to ${chalk.cyan(answers.version)}. Continue?`;
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
return inquirer
|
||||
.prompt(prompts)
|
||||
.then(answers => {
|
||||
if (answers.confirm){
|
||||
answers.prepare = true;
|
||||
answers.publish = false;
|
||||
runTasks(answers);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('\n', chalk.red(err), '\n');
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
function publishUI() {
|
||||
const pkg = readPkg();
|
||||
const version = pkg.version;
|
||||
|
||||
console.log(`\nPublish a new version of ${chalk.bold.magenta(pkg.name)} ${chalk.dim(`(${version})`)}\n`);
|
||||
|
||||
const prompts = [
|
||||
{
|
||||
type: 'list',
|
||||
name: 'tag',
|
||||
message: 'How should this pre-release version be tagged in npm?',
|
||||
when: answers => isPrereleaseVersion(version),
|
||||
choices: () => execa.stdout('npm', ['view', '--json', pkg.name, 'dist-tags'])
|
||||
.then(stdout => {
|
||||
const existingPrereleaseTags = Object.keys(JSON.parse(stdout))
|
||||
.filter(tag => tag !== 'latest');
|
||||
|
||||
if (existingPrereleaseTags.length === 0) {
|
||||
existingPrereleaseTags.push('next');
|
||||
}
|
||||
|
||||
return existingPrereleaseTags
|
||||
.concat([
|
||||
new inquirer.Separator(),
|
||||
{
|
||||
name: 'Other (specify)',
|
||||
value: null
|
||||
}
|
||||
]);
|
||||
})
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: 'tag',
|
||||
message: 'Tag',
|
||||
when: answers => !pkg.private && isPrereleaseVersion(version) && !answers.tag,
|
||||
validate: input => {
|
||||
if (input.length === 0) {
|
||||
return 'Please specify a tag, for example, `next`.';
|
||||
} else if (input.toLowerCase() === 'latest') {
|
||||
return 'It\'s not possible to publish pre-releases under the `latest` tag. Please specify something else, for example, `next`.';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'confirm',
|
||||
message: answers => {
|
||||
const tag = answers.tag;
|
||||
const tagPart = tag ? ` and tag this release in npm as ${tag}` : '';
|
||||
|
||||
return `Will publish ${chalk.cyan(version + tagPart)}. Continue?`;
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
return inquirer
|
||||
.prompt(prompts)
|
||||
.then(answers => {
|
||||
if (answers.confirm){
|
||||
answers.version = version;
|
||||
answers.prepare = false;
|
||||
answers.publish = true;
|
||||
runTasks(answers);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('\n', chalk.red(err), '\n');
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const SEMVER_INCREMENTS = ['patch', 'minor', 'major', 'prepatch', 'preminor', 'premajor', 'prerelease'];
|
||||
const PRERELEASE_VERSIONS = ['prepatch', 'preminor', 'premajor', 'prerelease'];
|
||||
|
||||
const isValidVersion = input => Boolean(semver.valid(input));
|
||||
|
||||
const isValidVersionInput = input => SEMVER_INCREMENTS.indexOf(input) !== -1 || isValidVersion(input);
|
||||
|
||||
const isPrereleaseVersion = version => PRERELEASE_VERSIONS.indexOf(version) !== -1 || Boolean(semver.prerelease(version));
|
||||
|
||||
function getNewVersion(oldVersion, input) {
|
||||
if (!isValidVersionInput(input)) {
|
||||
throw new Error(`Version should be either ${SEMVER_INCREMENTS.join(', ')} or a valid semver version.`);
|
||||
}
|
||||
|
||||
return SEMVER_INCREMENTS.indexOf(input) === -1 ? input : semver.inc(oldVersion, input);
|
||||
};
|
||||
|
||||
const isVersionGreater = (oldVersion, newVersion) => {
|
||||
if (!isValidVersion(newVersion)) {
|
||||
throw new Error('Version should be a valid semver version.');
|
||||
}
|
||||
|
||||
return semver.gt(newVersion, oldVersion);
|
||||
};
|
||||
|
||||
const isVersionLower = (oldVersion, newVersion) => {
|
||||
if (!isValidVersion(newVersion)) {
|
||||
throw new Error('Version should be a valid semver version.');
|
||||
}
|
||||
|
||||
return semver.lt(newVersion, oldVersion);
|
||||
};
|
||||
|
||||
const satisfies = (version, range) => semver.satisfies(version, range);
|
||||
|
||||
const readPkg = () => {
|
||||
return JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
||||
};
|
||||
|
||||
function prettyVersionDiff(oldVersion, inc) {
|
||||
const newVersion = getNewVersion(oldVersion, inc).split('.');
|
||||
oldVersion = oldVersion.split('.');
|
||||
let firstVersionChange = false;
|
||||
const output = [];
|
||||
|
||||
for (let i = 0; i < newVersion.length; i++) {
|
||||
if ((newVersion[i] !== oldVersion[i] && !firstVersionChange)) {
|
||||
output.push(`${chalk.dim.cyan(newVersion[i])}`);
|
||||
firstVersionChange = true;
|
||||
} else if (newVersion[i].indexOf('-') >= 1) {
|
||||
let preVersion = [];
|
||||
preVersion = newVersion[i].split('-');
|
||||
output.push(`${chalk.dim.cyan(`${preVersion[0]}-${preVersion[1]}`)}`);
|
||||
} else {
|
||||
output.push(chalk.reset.dim(newVersion[i]));
|
||||
}
|
||||
}
|
||||
return output.join(chalk.reset.dim('.'));
|
||||
}
|
||||
|
||||
const prepare = process.argv.slice(2).indexOf('--prepare') > -1;
|
||||
|
||||
if (prepare) {
|
||||
prepareUI();
|
||||
} else {
|
||||
publishUI();
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const semver = require('semver')
|
||||
|
||||
const pkgJsonPath = path.join(__dirname, '../package.json');
|
||||
const pkgLockPath = path.join(__dirname, '../package-lock.json');
|
||||
const readmePath = path.join(__dirname, '../README.md');
|
||||
|
||||
// get the version number from the last arg
|
||||
const newVersion = process.argv[2];
|
||||
semver.valid(newVersion);
|
||||
if (!newVersion) {
|
||||
throw new Error('invalid version number: ' + newVersion);
|
||||
}
|
||||
|
||||
// update the package.json
|
||||
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));
|
||||
pkgJson.version = newVersion;
|
||||
|
||||
// update the package-lock.json
|
||||
const pkgLock = JSON.parse(fs.readFileSync(pkgLockPath, 'utf-8'));
|
||||
pkgLock.version = pkgJson.version;
|
||||
|
||||
// update the readme script tag
|
||||
let readme = fs.readFileSync(readmePath, 'utf-8');
|
||||
const cdnUrl = 'https://unpkg.com/' + pkgJson.name + '@' + pkgJson.version + '/dist/ionic.js'
|
||||
readme = readme.replace(/https:\/\/unpkg.com(.*)ionic.js/, cdnUrl);
|
||||
|
||||
// save our changes
|
||||
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2) + '\n');
|
||||
fs.writeFileSync(pkgLockPath, JSON.stringify(pkgLock, null, 2) + '\n');
|
||||
fs.writeFileSync(readmePath, readme);
|
||||
1263
package-lock.json
generated
1263
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,8 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"prepare.deploy": "node .scripts/prepare.js",
|
||||
"deploy": "node .scripts/publish.js"
|
||||
"deploy": "node .scripts/publish.js",
|
||||
"changelog": "conventional-changelog -p angular -i core/CHANGELOG.md -k core -s"
|
||||
},
|
||||
"dependencies": {
|
||||
"chalk": "^2.3.2",
|
||||
@@ -14,5 +15,8 @@
|
||||
"inquirer": "^5.1.0",
|
||||
"listr": "^0.13.0",
|
||||
"semver": "^5.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"conventional-changelog-cli": "^1.3.16"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user