Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Commit

Permalink
Adding a script to automatically build testing versions of core packages
Browse files Browse the repository at this point in the history
Summary: `node scripts/build-packages.js` will create local builds of the React VR packages (`react-vr`, `react-vr-web`, `ovrui`) and place them in `./package_builds`. Once they have been built, you can run your project against the master version of React VR by running `npm install path/to/react-vr-x.y.z.tgz`, etc from your project directory.

Reviewed By: macarran

Differential Revision: D5064084

fbshipit-source-id: c819c46
  • Loading branch information
andrewimm authored and facebook-github-bot committed May 16, 2017
1 parent 8edafa3 commit 8681fc1
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
.DS_Store
*.log
EndToEnd/testapp/build
package_builds
99 changes: 99 additions & 0 deletions scripts/build-packages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

const child_process = require('child_process');
const fs = require('fs');
const path = require('path');

function prepare() {
return new Promise((resolve, reject) => {
// Build OVRUI
const npm = child_process.spawn('npm', ['run', 'build'], {
stdio: 'inherit',
cwd: PACKAGES.ovrui,
});
npm.on('close', code => {
if (code !== 0) {
reject(code);
}
resolve();
});
});
}

function buildPackage(name, dir) {
console.log(` Packaging \x1b[32m'${name}'\x1b[0m`);
return new Promise((resolve, reject) => {
const json = path.resolve(dir, 'package.json');
fs.stat(json, (err, res) => {
if (err) {
console.log(`\x1b[41;1m${json} does not exist\x1b[0m`);
reject(err);
return;
}
resolve(json);
});
}).then(json => {
const version = require(json).version;
return new Promise((resolve, reject) => {
const npm = child_process.spawn('npm', ['pack'], {stdio: 'inherit', cwd: dir});
npm.on('close', code => {
if (code !== 0) {
reject(code);
}
resolve(path.resolve(dir, `${name}-${version}.tgz`));
});
});
});
}

function relocatePackage(name, src, dest, rev) {
const destfile = path.join(dest, `${name}-${rev}.tgz`);
console.log(`Moving ${src} to ${destfile}`);
return new Promise((resolve, reject) => {
fs.rename(src, destfile, () => {
resolve();
});
});
}

function ensureDirectory(dir) {
try {
const stat = fs.statSync(dir);
if (stat) {
return;
}
} catch (e) {
fs.mkdirSync(dir);
}
}

const PACKAGES = {
ovrui: path.resolve(__dirname, '..', 'OVRUI'),
'react-vr': path.resolve(__dirname, '..'),
'react-vr-web': path.resolve(__dirname, '..', 'ReactVR'),
};

const rev = child_process.execSync('git rev-parse HEAD').toString().trim().substr(0, 8);
console.log(`\x1b[34;1mBuilding packages at git rev ${rev}...\x1b[0m`);
const DEST = path.resolve(__dirname, '..', 'package_builds');
ensureDirectory(DEST);
prepare()
.then(() => {
return Promise.all(
Object.keys(PACKAGES).map(p =>
buildPackage(p, PACKAGES[p]).then(src => relocatePackage(p, src, DEST, rev))
)
);
})
.then(() => {
console.log(`\nBuilt all packages! They are located at \x1b[34m${DEST}\x1b[0m`);
});

0 comments on commit 8681fc1

Please sign in to comment.