2017-12-28 20:28:44 +08:00
|
|
|
import * as fs from 'fs-extra';
|
|
|
|
import * as path from 'path';
|
|
|
|
import { merge } from 'lodash';
|
|
|
|
import { exec } from 'child_process';
|
|
|
|
import { PLUGIN_PATHS, ROOT } from '../build/helpers';
|
2017-12-29 11:12:48 +08:00
|
|
|
import { cpus } from 'os';
|
|
|
|
import * as Queue from 'async-promise-queue';
|
2017-12-28 20:28:44 +08:00
|
|
|
|
|
|
|
const MAIN_PACKAGE_JSON = require('../../package.json');
|
|
|
|
const VERSION = MAIN_PACKAGE_JSON.version;
|
|
|
|
const FLAGS = '--access public --tag beta';
|
|
|
|
|
|
|
|
const PACKAGE_JSON_BASE = {
|
2017-12-29 11:12:48 +08:00
|
|
|
'description': 'Ionic Native - Native plugins for ionic apps',
|
|
|
|
'module': 'index.js',
|
|
|
|
'typings': 'index.d.ts',
|
|
|
|
'author': 'ionic',
|
|
|
|
'license': 'MIT',
|
|
|
|
'repository': {
|
|
|
|
'type': 'git',
|
|
|
|
'url': 'https://github.com/ionic-team/ionic-native.git'
|
2017-12-28 20:28:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-28 21:40:52 +08:00
|
|
|
const DIST = path.resolve(ROOT, 'dist/@ionic-native');
|
2017-12-28 20:28:44 +08:00
|
|
|
|
|
|
|
const PACKAGES = [];
|
|
|
|
|
|
|
|
const RXJS_VEERSION = '^5.0.1';
|
|
|
|
const CORE_VERSION = '^5.0.0';
|
|
|
|
|
|
|
|
const PLUGIN_PEER_DEPENDENCIES = {
|
|
|
|
'@ionic-native/core': VERSION, // TODO change this in production
|
|
|
|
'rxjs': RXJS_VEERSION
|
|
|
|
};
|
|
|
|
|
|
|
|
function getPackageJsonContent(name, peerDependencies = {}) {
|
|
|
|
return merge(PACKAGE_JSON_BASE, {
|
|
|
|
name: '@ionic-native/' + name,
|
|
|
|
peerDependencies,
|
|
|
|
version: VERSION
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function writePackageJson(data: any, dir: string) {
|
|
|
|
const filePath = path.resolve(dir, 'package.json');
|
|
|
|
fs.writeJSONSync(filePath, data);
|
|
|
|
PACKAGES.push(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepare() {
|
|
|
|
// write @ionic-native/core package.json
|
|
|
|
writePackageJson(
|
|
|
|
getPackageJsonContent('core', { 'rxjs': RXJS_VEERSION }),
|
|
|
|
path.resolve(DIST, 'core')
|
|
|
|
);
|
|
|
|
|
|
|
|
// write plugin package.json files
|
|
|
|
PLUGIN_PATHS.forEach((pluginPath: string) => {
|
|
|
|
const pluginName = pluginPath.split(/[\/\\]+/).slice(-2)[0];
|
|
|
|
const packageJsonContents = getPackageJsonContent(pluginName, PLUGIN_PEER_DEPENDENCIES);
|
|
|
|
const dir = path.resolve(DIST, 'plugins', pluginName);
|
|
|
|
|
|
|
|
writePackageJson(packageJsonContents, dir);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-29 11:12:48 +08:00
|
|
|
async function publish(ignoreErrors: boolean = false) {
|
|
|
|
// upload 1 package per CPU thread at a time
|
|
|
|
const worker = Queue.async.asyncify((pkg: any) => {
|
|
|
|
new Promise<any>((resolve, reject) => {
|
|
|
|
exec(`npm publish ${ pkg } ${ FLAGS }`, (err, stdout) => {
|
|
|
|
if (stdout) {
|
|
|
|
console.log(stdout);
|
|
|
|
resolve(stdout);
|
|
|
|
}
|
|
|
|
if (err) {
|
|
|
|
if (!ignoreErrors) {
|
|
|
|
if (err.message.includes('You cannot publish over the previously published version')) {
|
|
|
|
console.log('Ignoring duplicate version error.');
|
|
|
|
return resolve();
|
|
|
|
}
|
|
|
|
reject(err);
|
|
|
|
}
|
|
|
|
}
|
2017-12-28 21:57:50 +08:00
|
|
|
});
|
|
|
|
});
|
2017-12-29 11:12:48 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
|
|
await Queue(worker, PACKAGES, cpus().length);
|
|
|
|
console.log('Done publishing!');
|
|
|
|
} catch (e) {
|
|
|
|
console.log('Error publishing!');
|
|
|
|
console.log(e);
|
2017-12-28 21:57:50 +08:00
|
|
|
}
|
2017-12-28 20:28:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
prepare();
|
|
|
|
publish();
|