2017-02-17 06:53:20 +08:00
|
|
|
import fs from 'fs-plus'
|
|
|
|
import path from 'path'
|
2017-02-18 03:22:59 +08:00
|
|
|
import childProcess from 'child_process'
|
2017-02-17 06:53:20 +08:00
|
|
|
|
2017-02-18 03:22:59 +08:00
|
|
|
async function spawn(cmd, args, opts = {}) {
|
2017-02-17 06:53:20 +08:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const options = Object.assign({stdio: 'inherit'}, opts);
|
2017-02-18 03:22:59 +08:00
|
|
|
const proc = childProcess.spawn(cmd, args, options)
|
2017-02-17 06:53:20 +08:00
|
|
|
proc.on("error", reject)
|
|
|
|
proc.on("exit", resolve)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-02-18 03:22:59 +08:00
|
|
|
function unlinkIfExistsSync(p) {
|
|
|
|
try {
|
|
|
|
if (fs.lstatSync(p)) {
|
|
|
|
fs.removeSync(p);
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-22 07:54:02 +08:00
|
|
|
function copyErrorLoggerExtensions(privateDir) {
|
|
|
|
const from = path.join(privateDir, 'src')
|
|
|
|
const to = path.resolve(path.join('packages', 'client-app', 'src'))
|
|
|
|
unlinkIfExistsSync(path.join(to, 'error-logger-extensions'));
|
|
|
|
fs.copySync(from, to);
|
2017-02-18 03:22:59 +08:00
|
|
|
}
|
|
|
|
|
2017-02-17 06:53:20 +08:00
|
|
|
async function installPrivateResources() {
|
|
|
|
console.log("\n---> Linking private plugins")
|
|
|
|
const privateDir = path.resolve(path.join('packages', 'client-private-plugins'))
|
2017-02-18 02:47:01 +08:00
|
|
|
if (!fs.existsSync(privateDir)) {
|
|
|
|
console.log("\n---> No client app to link. Moving on")
|
|
|
|
return;
|
|
|
|
}
|
2017-02-17 06:53:20 +08:00
|
|
|
|
2017-02-22 07:54:02 +08:00
|
|
|
copyErrorLoggerExtensions(privateDir)
|
2017-02-17 06:53:20 +08:00
|
|
|
|
|
|
|
// link private plugins
|
|
|
|
for (const plugin of fs.readdirSync(path.join(privateDir, 'packages'))) {
|
|
|
|
const from = path.resolve(path.join(privateDir, 'packages', plugin));
|
|
|
|
const to = path.resolve(path.join('packages', 'client-app', 'internal_packages', plugin));
|
|
|
|
unlinkIfExistsSync(to);
|
|
|
|
fs.symlinkSync(from, to, 'dir');
|
|
|
|
}
|
|
|
|
|
|
|
|
// link client-sync
|
|
|
|
const clientSyncDir = path.resolve(path.join('packages', 'client-sync'));
|
|
|
|
const destination = path.resolve(path.join('packages', 'client-app', 'internal_packages', 'client-sync'));
|
|
|
|
unlinkIfExistsSync(destination);
|
|
|
|
fs.symlinkSync(clientSyncDir, destination, 'dir');
|
|
|
|
}
|
|
|
|
|
2017-03-28 05:40:28 +08:00
|
|
|
async function lernaBootstrap(installFor) {
|
2017-02-17 06:53:20 +08:00
|
|
|
console.log("\n---> Installing packages");
|
2017-03-08 03:24:34 +08:00
|
|
|
let lernaCmd = "lerna"
|
|
|
|
if (process.platform === "win32") { lernaCmd = "lerna.cmd" }
|
2017-03-15 04:39:56 +08:00
|
|
|
const args = ["bootstrap"]
|
2017-03-28 05:40:28 +08:00
|
|
|
if (installFor === "clientOnly") {
|
2017-03-15 04:39:56 +08:00
|
|
|
args.push("--ignore='cloud-*'")
|
2017-03-28 05:40:28 +08:00
|
|
|
} else if (installFor === "cloudOnly") {
|
|
|
|
args.push("--ignore='client-*'")
|
2017-03-15 04:39:56 +08:00
|
|
|
}
|
2017-03-28 05:40:28 +08:00
|
|
|
await spawn(path.join('node_modules', '.bin', lernaCmd), args)
|
2017-02-17 06:53:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const npmEnvs = {
|
|
|
|
system: process.env,
|
|
|
|
apm: Object.assign({}, process.env, {
|
2017-02-18 03:22:59 +08:00
|
|
|
NPM_CONFIG_TARGET: '0.10.40',
|
2017-02-17 06:53:20 +08:00
|
|
|
}),
|
|
|
|
electron: Object.assign({}, process.env, {
|
2017-02-18 03:22:59 +08:00
|
|
|
NPM_CONFIG_TARGET: '1.4.15',
|
|
|
|
NPM_CONFIG_ARCH: process.arch,
|
|
|
|
NPM_CONFIG_TARGET_ARCH: process.arch,
|
|
|
|
NPM_CONFIG_DISTURL: 'https://atom.io/download/electron',
|
|
|
|
NPM_CONFIG_RUNTIME: 'electron',
|
|
|
|
NPM_CONFIG_BUILD_FROM_SOURCE: true,
|
2017-02-17 06:53:20 +08:00
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
async function npm(cmd, options) {
|
|
|
|
const {cwd, env} = Object.assign({cwd: '.', env: 'system'}, options);
|
2017-03-08 03:50:34 +08:00
|
|
|
let npmCmd = "npm"
|
|
|
|
if (process.platform === "win32") { npmCmd = "npm.cmd" }
|
|
|
|
await spawn(npmCmd, [cmd], {
|
2017-02-17 06:53:20 +08:00
|
|
|
cwd: path.resolve(__dirname, '..', cwd),
|
|
|
|
env: npmEnvs[env],
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async function electronRebuild() {
|
2017-02-22 10:03:19 +08:00
|
|
|
if (!fs.existsSync(path.join("packages", "client-app", "apm"))) {
|
2017-02-18 02:47:01 +08:00
|
|
|
console.log("\n---> No client app to rebuild. Moving on")
|
|
|
|
return;
|
|
|
|
}
|
2017-02-22 03:34:30 +08:00
|
|
|
await npm('install', {
|
2017-02-18 03:22:59 +08:00
|
|
|
cwd: path.join('packages', 'client-app', 'apm'),
|
|
|
|
env: 'apm',
|
|
|
|
})
|
|
|
|
await npm('rebuild', {
|
|
|
|
cwd: path.join('packages', 'client-app'),
|
|
|
|
env: 'electron',
|
|
|
|
})
|
2017-02-17 06:53:20 +08:00
|
|
|
}
|
|
|
|
|
2017-03-01 07:46:54 +08:00
|
|
|
const getJasmineDir = (packageName) => path.resolve(
|
|
|
|
path.join('packages', packageName, 'spec', 'jasmine')
|
|
|
|
)
|
|
|
|
const getJasmineConfigPath = (packageName) => path.resolve(
|
|
|
|
path.join(getJasmineDir(packageName), 'config.json')
|
|
|
|
)
|
|
|
|
|
|
|
|
function linkJasmineConfigs() {
|
|
|
|
console.log("\n---> Linking Jasmine configs");
|
|
|
|
const linkToPackages = ['cloud-api', 'cloud-core', 'cloud-workers']
|
|
|
|
const from = getJasmineConfigPath('isomorphic-core')
|
|
|
|
|
|
|
|
for (const packageName of linkToPackages) {
|
|
|
|
const dir = getJasmineDir(packageName)
|
|
|
|
if (!fs.existsSync(dir)) {
|
|
|
|
fs.mkdirSync(dir)
|
|
|
|
}
|
|
|
|
const to = getJasmineConfigPath(packageName)
|
|
|
|
unlinkIfExistsSync(to)
|
|
|
|
fs.symlinkSync(from, to, 'file')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-01 05:38:14 +08:00
|
|
|
function linkIsomorphicCoreSpecs() {
|
2017-03-03 02:38:59 +08:00
|
|
|
console.log("\n---> Linking isomorphic-core specs to client-app specs")
|
2017-03-01 05:38:14 +08:00
|
|
|
const from = path.resolve(path.join('packages', 'isomorphic-core', 'spec'))
|
2017-03-03 02:38:59 +08:00
|
|
|
const to = path.resolve(path.join('packages', 'client-app', 'spec', 'isomorphic-core'))
|
2017-03-01 05:38:14 +08:00
|
|
|
unlinkIfExistsSync(to)
|
|
|
|
fs.symlinkSync(from, to, 'dir')
|
|
|
|
}
|
|
|
|
|
2017-02-17 06:53:20 +08:00
|
|
|
async function main() {
|
|
|
|
try {
|
2017-03-28 05:40:28 +08:00
|
|
|
let installFor = "all";
|
|
|
|
if (process.env.ONLY_CLIENT === "true") installFor = "clientOnly"
|
|
|
|
if (process.env.ONLY_CLIENT === "false") installFor = "cloudOnly"
|
2017-03-02 06:38:51 +08:00
|
|
|
|
2017-03-28 05:40:28 +08:00
|
|
|
if (installFor === "all" || installFor === "clientOnly") {
|
|
|
|
await installPrivateResources()
|
2017-03-15 03:02:27 +08:00
|
|
|
}
|
2017-03-02 06:38:51 +08:00
|
|
|
|
2017-03-28 05:40:28 +08:00
|
|
|
await lernaBootstrap(installFor);
|
2017-03-02 06:38:51 +08:00
|
|
|
|
2017-03-28 05:40:28 +08:00
|
|
|
if (installFor === "all" || installFor === "clientOnly") {
|
|
|
|
// Given that `lerna bootstrap` does not install optional
|
|
|
|
// dependencies, we need to manually run `npm install` inside
|
|
|
|
// `client-app` so `node-mac-notifier` get's correctly installed and
|
|
|
|
// included in the build See
|
|
|
|
// https://github.com/lerna/lerna/issues/121
|
2017-03-28 07:59:59 +08:00
|
|
|
if (process.platform === "darwin") {
|
|
|
|
console.log("\n---> Reinstalling client-app dependencies to include optional dependencies");
|
|
|
|
await npm('install', {cwd: 'packages/client-app'})
|
|
|
|
}
|
2017-03-28 05:40:28 +08:00
|
|
|
await electronRebuild();
|
2017-03-15 03:02:27 +08:00
|
|
|
linkJasmineConfigs();
|
|
|
|
linkIsomorphicCoreSpecs();
|
|
|
|
}
|
2017-02-17 06:53:20 +08:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
main()
|