Skip to content

Commit

Permalink
Merge pull request #24 from ionic-team/master
Browse files Browse the repository at this point in the history
pull `master`
  • Loading branch information
abennouna authored Jan 15, 2019
2 parents cd80b99 + 3dac7bb commit 8d88990
Show file tree
Hide file tree
Showing 38 changed files with 644 additions and 355 deletions.
125 changes: 119 additions & 6 deletions .scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function readPkg(project) {
function writePkg(project, pkg) {
const packageJsonPath = packagePath(project);
const text = JSON.stringify(pkg, null, 2);
return fs.writeFileSync(packageJsonPath, text);
return fs.writeFileSync(packageJsonPath, `${text}\n`);
}

function packagePath(project) {
Expand Down Expand Up @@ -133,6 +133,113 @@ function preparePackage(tasks, package, version) {
}


function prepareDevPackage(tasks, package, version) {
const projectRoot = projectPath(package);
const pkg = readPkg(package);

const projectTasks = [];

if (package !== 'docs') {
if (package !== 'core') {
projectTasks.push({
title: `${pkg.name}: npm link @ionic/core`,
task: () => execa('npm', ['link', '@ionic/core'], { cwd: projectRoot })
});
}

projectTasks.push({
title: `${pkg.name}: update ionic/core dep to ${version}`,
task: () => {
updateDependency(pkg, "@ionic/core", version);
writePkg(package, pkg);
}
});

projectTasks.push({
title: `${pkg.name}: build`,
task: () => execa('npm', ['run', 'build'], { cwd: projectRoot })
});

if (package === 'core') {
projectTasks.push({
title: `${pkg.name}: npm link`,
task: () => execa('npm', ['link'], { cwd: projectRoot })
});
}
}

// Add project tasks
tasks.push({
title: `Prepare dev build: ${tc.bold(pkg.name)}`,
task: () => new Listr(projectTasks)
});
}

function updatePackageVersions(tasks, packages, version) {
packages.forEach(package => {
updatePackageVersion(tasks, package, version);

tasks.push(
{
title: `${package} update @ionic/core dependency, if present ${tc.dim(`(${version})`)}`,
task: async () => {
if (package !== 'core') {
const pkg = readPkg(package);
updateDependency(pkg, '@ionic/core', version);
writePkg(package, pkg);
}
},
}
)
});
}


function updatePackageVersion(tasks, package, version) {
const projectRoot = projectPath(package);

tasks.push(
{
title: `${package}: update package.json ${tc.dim(`(${version})`)}`,
task: async () => {
await execa('npm', ['version', version], { cwd: projectRoot });
}
}
);
}

function publishPackages(tasks, packages, version, tag = 'latest') {
// first verify version
packages.forEach(package => {
if (package === 'core') {
return;
}

tasks.push({
title: `${package}: check version (must match: ${version})`,
task: () => {
const pkg = readPkg(package);

if (version !== pkg.version) {
throw new Error(`${pkg.name} version ${pkg.version} must match ${version}`);
}
}
});
});

// next publish
packages.forEach(package => {
const projectRoot = projectPath(package);

tasks.push({
title: `${package}: publish to ${tag} tag`,
task: async () => {
await execa('npm', ['publish', '--tag', tag], { cwd: projectRoot });
},
});
});
}

function updateDependency(pkg, dependency, version) {
if (pkg.dependencies && pkg.dependencies[dependency]) {
pkg.dependencies[dependency] = version;
Expand All @@ -151,13 +258,19 @@ function isVersionGreater(oldVersion, newVersion) {


module.exports = {
checkGit,
isValidVersion,
isVersionGreater,
packages,
packagePath,
prepareDevPackage,
preparePackage,
projectPath,
publishPackages,
readPkg,
writePkg,
rootDir,
projectPath,
checkGit,
packages,
preparePackage
updateDependency,
updatePackageVersion,
updatePackageVersions,
writePkg,
};
17 changes: 1 addition & 16 deletions .scripts/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const tc = require('turbocolor');
const execa = require('execa');
const inquirer = require('inquirer');
const Listr = require('listr');
const fs = require('fs-extra');
const semver = require('semver');
const common = require('./common');
const path = require('path');
Expand Down Expand Up @@ -108,7 +107,7 @@ async function preparePackages(packages, version) {

// add update package.json of each project
packages.forEach(package => {
updatePackageVersion(tasks, package, version);
common.updatePackageVersion(tasks, package, version);
});

// generate changelog
Expand Down Expand Up @@ -155,20 +154,6 @@ function validateGit(tasks, version) {
);
}

function updatePackageVersion(tasks, package, version) {
const projectRoot = common.projectPath(package);
const pkg = common.readPkg(package);

tasks.push(
{
title: `${pkg.name}: update package.json ${tc.dim(`(${version})`)}`,
task: async () => {
await execa('npm', ['version', version], { cwd: projectRoot });
}
}
);
}


function generateChangeLog(tasks) {
tasks.push({
Expand Down
102 changes: 102 additions & 0 deletions .scripts/release-dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
const tc = require('turbocolor');
const semver = require('semver');
const execa = require('execa');
const inquirer = require('inquirer');
const Listr = require('listr');
const fs = require('fs-extra');

const common = require('./common');

const DIST_TAG = 'dev';

async function main() {
const { packages } = common;

const orgPkg = packages.map(package => {
const packageJsonPath = common.packagePath(package);
return {
filePath: packageJsonPath,
packageContent: fs.readFileSync(packageJsonPath, 'utf-8')
}
});

try {
const originalVersion = common.readPkg('core').version;
const devVersion = await getDevVersion(originalVersion);

const confirm = await askDevVersion(devVersion);
if (!confirm) {
console.log(``);
return;
}

const tasks = [];

await setPackageVersionChanges(packages, devVersion);

packages.forEach(package => {
common.prepareDevPackage(tasks, package, devVersion);
});
common.publishPackages(tasks, packages, devVersion, DIST_TAG);

const listr = new Listr(tasks);
await listr.run();

console.log(`\nionic ${devVersion} published!! 🎉\n`);

} catch (err) {
console.log('\n', tc.red(err), '\n');
process.exit(1);
}

orgPkg.forEach(pkg => {
fs.writeFileSync(pkg.filePath, pkg.packageContent);
});
}

async function askDevVersion(devVersion) {

const prompts = [
{
type: 'confirm',
name: 'confirm',
value: true,
message: () => {
return `Publish the dev build ${tc.cyan(devVersion)}?`;
}
}
];

const { confirm } = await inquirer.prompt(prompts);
return confirm;
}

async function setPackageVersionChanges(packages, version) {
await Promise.all(packages.map(async package => {
if (package !== 'core') {
const pkg = common.readPkg(package);
common.updateDependency(pkg, '@ionic/core', version);
common.writePkg(package, pkg);
}
const projectRoot = common.projectPath(package);
await execa('npm', ['version', version], { cwd: projectRoot });
}));
}

async function getDevVersion(originalVersion) {
const { stdout: sha } = await execa('git', ['log', '-1', '--format=%H']);
const shortSha = sha.substring(0, 7);
const baseVersion = semver.inc(originalVersion, 'minor');

const d = new Date();

let timestamp = (d.getUTCFullYear() + '');
timestamp += ('0' + (d.getUTCMonth() + 1)).slice(-2);
timestamp += ('0' + d.getUTCDate()).slice(-2);
timestamp += ('0' + d.getUTCHours()).slice(-2);
timestamp += ('0' + d.getUTCMinutes()).slice(-2);

return `${baseVersion}-${DIST_TAG}.${timestamp}.${shortSha}`;
}

main();
32 changes: 1 addition & 31 deletions .scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function main() {
common.checkGit(tasks);

// publish each package in NPM
publishPackages(tasks, common.packages, version);
common.publishPackages(tasks, common.packages, version);

// push tag to git remote
publishGit(tasks, version, changelog);
Expand All @@ -40,36 +40,6 @@ async function main() {
}


async function publishPackages(tasks, packages, version) {
// first verify version
packages.forEach(package => {
if (package === 'core') {
return;
}

const pkg = common.readPkg(package);
tasks.push({
title: `${pkg.name}: check version (must match: ${version})`,
task: () => {
if (version !== pkg.version) {
throw new Error(`${pkg.name} version ${pkg.version} must match ${version}`);
}
}
});
});

// next publish
packages.forEach(package => {
const pkg = common.readPkg(package);
const projectRoot = common.projectPath(package);

tasks.push({
title: `${pkg.name}: publish ${pkg.version}`,
task: () => execa('npm', ['publish', '--tag', 'latest'], { cwd: projectRoot })
});
});
}

function publishGit(tasks, version, changelog) {
const tag = `v${version}`;

Expand Down
4 changes: 2 additions & 2 deletions angular/BREAKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ Previously an `ion-label` would automatically get added to an `ion-list-header`

## Loading

`dismissOnPageChange` was removed. Fortunatelly all the navigation API is promise based and there are global events (`ionNavWillChange`) you can listen in order to detect when navigation occurs.
`dismissOnPageChange` was removed. Fortunately all the navigation API is promise based and there are global events (`ionNavWillChange`) you can listen in order to detect when navigation occurs.

You should take advantage of these APIs in order to dismiss your loading overlay explicitally.

Expand Down Expand Up @@ -1155,7 +1155,7 @@ The `enabled` property (with a default value of `true`) has been renamed to `dis

## Scroll

`ion-scroll` has been removed, fortunatelly `ion-content` can work as a drop-in replacement:
`ion-scroll` has been removed, fortunately `ion-content` can work as a drop-in replacement:

```diff
- <ion-scroll scrollX="true">
Expand Down
15 changes: 6 additions & 9 deletions angular/src/directives/navigation/ion-back-button.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Directive, ElementRef, HostListener, Optional } from '@angular/core';
import { Directive, HostListener, Optional } from '@angular/core';

import { NavController } from '../../providers/nav-controller';

Expand All @@ -10,19 +10,16 @@ import { IonRouterOutlet } from './ion-router-outlet';
})
export class IonBackButtonDelegate {

set defaultHref(value: string | undefined | null) {
this.elementRef.nativeElement.defaultHref = value;
}
get defaultHref(): string | undefined | null {
return this.elementRef.nativeElement.defaultHref;
}
defaultHref: string | undefined | null;

constructor(
@Optional() private routerOutlet: IonRouterOutlet,
private navCtrl: NavController,
private elementRef: ElementRef,
private navCtrl: NavController
) {}

/**
* @internal
*/
@HostListener('click', ['$event'])
onClick(ev: Event) {
if (this.routerOutlet && this.routerOutlet.canGoBack()) {
Expand Down
Loading

0 comments on commit 8d88990

Please sign in to comment.