This repository has been archived by the owner on Dec 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a script to automatically build testing versions of core packages
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
1 parent
8edafa3
commit 8681fc1
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ node_modules | |
.DS_Store | ||
*.log | ||
EndToEnd/testapp/build | ||
package_builds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
}); |