Reduce the number of terminals required to build riot-web to 1

A step towards a real solution for https://github.com/vector-im/riot-web/issues/7305

This approach makes use of `npm link` to remove the use of symlinks in the build process. The build process has also been altered to invoke the build process of each underlying SDK (react, js). This means that one can now `npm link` and `npm start` and have a working environment. 

At the same time, parallelshell was dropped due to lack of maintenance from the maintainer.
This commit is contained in:
Travis Ralston 2018-09-17 17:46:13 -06:00
parent e58ac74aa2
commit 67e9606d55
5 changed files with 2668 additions and 2192 deletions

View file

@ -0,0 +1,44 @@
const fs = require('fs');
const path = require('path');
const child_process = require('child_process');
const task = process.argv[2];
if (task !== "build" && task !== "watch") {
console.error("Expected a task of 'build' or 'watch'");
process.exit(1);
}
const sdkName = process.argv[3];
if (!sdkName) {
console.error("Missing SDK name");
process.exit(1);
}
const sdkPath = path.dirname(require.resolve(`matrix-${sdkName}-sdk/package.json`));
console.log(sdkPath);
// We only want to build the SDK if it looks like it was `npm link`ed
if (fs.existsSync(path.join(sdkPath, '.git'))) {
console.log("Installing develop dependencies");
const devEnv = Object.assign({}, process.env, {NODE_ENV: "development"});
child_process.execSync("npm install --only=dev", {
env: devEnv,
cwd: sdkPath,
});
// Because webpack is made of fail
if (sdkName === "js") {
console.log("Installing source-map-loader");
child_process.execSync("npm install source-map-loader", {
env: devEnv,
cwd: sdkPath,
});
}
console.log("Performing task: " + task);
child_process.execSync(`npm ${task === "build" ? "run build" : "start"}`, {
env: process.env,
cwd: sdkPath,
});
}

View file

@ -52,13 +52,7 @@ function dodep() {
echo "$repo set to branch "`git -C "$repo" rev-parse --abbrev-ref HEAD`
mkdir -p node_modules
rm -r "node_modules/$repo" 2>/dev/null || true
ln -sv "../$repo" node_modules/
(
cd $repo
npm install
)
npm link "../$repo" # This does an npm install for us
}
##############################
@ -77,14 +71,15 @@ echo 'Setting up matrix-react-sdk'
dodep matrix-org matrix-react-sdk
# replace the version of js-sdk that got pulled into react-sdk with a symlink
# replace the version of js-sdk that got pulled into react-sdk with a link
# to our version. Make sure to do this *after* doing 'npm i' in react-sdk,
# otherwise npm helpfully moves another-json from matrix-js-sdk/node_modules
# into matrix-react-sdk/node_modules.
#
# (note this matches the instructions in the README.)
rm -r node_modules/matrix-react-sdk/node_modules/matrix-js-sdk
ln -s ../../matrix-js-sdk node_modules/matrix-react-sdk/node_modules/
cd matrix-react-sdk
npm link ../matrix-js-sdk
cd ../
echo -en 'travis_fold:end:matrix-react-sdk\r'