chore(packages): move the packages to root

This commit is contained in:
Brandy Carney
2018-03-12 16:02:25 -04:00
parent 097f1a2cd3
commit d37623a2ca
1255 changed files with 38 additions and 38 deletions

View File

@ -1,16 +0,0 @@
# npm link local development
`npm link` doesn't work as expected due to the `devDependency` on `@angular/core`. This is the work around...
npm run build.link ../ionic-conference-app
When the command above is ran from the `packages/angular` directory, it will build `@ionic/angular` and copy the `dist` directory to the correct location of another local project. In the example above, the end result is that it copies the `dist` directory to `../ionic-conference-app/node_modules/@ionic/angular/dist`. The path given should be relative to the root of this mono repo.
# Deploy
1. `npm run prepare.deploy`
2. Review/update changelog
3. Commit updates using the package name and version number as the commit message.
4. `npm run deploy`
5. :tada:

View File

@ -1,54 +0,0 @@
const path = require('path');
const cwd = process.cwd();
const glob = require('glob');
const rimRaf = require('rimraf');
const distDir = path.join(cwd, 'dist');
const distGeneratedNodeModules = path.join(distDir, 'node_modules');
function rimRafAsync(dir) {
return new Promise((resolve, reject) => {
rimRaf(dir, {}, err => {
if (err) {
return reject(err);
}
resolve();
})
});
}
function doGlob(globString) {
return new Promise((resolve, reject) => {
glob(globString, (err, matches) => {
if (err) {
return reject(err);
}
resolve(matches);
})
});
}
function getCodegenedFilesToDelete() {
const ngFactoryGlob = path.join(distDir, '**', '*ngfactory*');
const ngSummaryGlob = path.join(distDir, '**', '*ngsummary*');
const promises = [];
promises.push(doGlob(ngFactoryGlob));
promises.push(doGlob(ngSummaryGlob));
return Promise.all(promises).then(listOfGlobResults => {
const deleteFilePromises = [];
listOfGlobResults.forEach(fileMatches => {
fileMatches.forEach(filePath => {
deleteFilePromises.push(rimRafAsync(filePath));
})
})
return Promise.all(deleteFilePromises);
});
}
const taskPromises = [];
taskPromises.push(getCodegenedFilesToDelete());
taskPromises.push(rimRafAsync(distGeneratedNodeModules));
return Promise.all(taskPromises);

View File

@ -1,12 +0,0 @@
const fs = require('fs-extra');
const path = require('path');
const cleanDirs = [
'dist'
];
cleanDirs.forEach(dir => {
const cleanDir = path.join(__dirname, '../', dir);
fs.removeSync(cleanDir);
});

View File

@ -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();
}

View File

@ -1,31 +0,0 @@
const fs = require('fs-extra');
const path = require('path');
let prjDir = process.argv[2];
if (!prjDir) {
throw new Error('local path required as last argument to "npm run build.link" command');
}
prjDir = path.join(__dirname, '../../../', prjDir);
const prjIonicAngular = path.join(prjDir, 'node_modules/@ionic/angular');
const ionicAngularDir = path.join(__dirname, '..');
const ionicAngularDist = path.join(ionicAngularDir, 'dist');
const ionicAngularPkgJsonPath = path.join(ionicAngularDir, 'package.json');
const ionicAngularPkgJson = require(ionicAngularPkgJsonPath);
// make sure this local project exists
fs.emptyDirSync(prjIonicAngular);
ionicAngularPkgJson.files.push('package.json');
ionicAngularPkgJson.files.forEach(f => {
const src = path.join(ionicAngularDir, f);
const dest = path.join(prjIonicAngular, f);
console.log('copying:', src, 'to', dest);
fs.copySync(src, dest);
});
const prjReadme = path.join(prjIonicAngular, 'README.md');
fs.writeFileSync(prjReadme, '@ionic/angular copied from ' + ionicAngularDir);

View File

@ -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');