Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 0 additions & 126 deletions ensure-packages-built.js

This file was deleted.

42 changes: 42 additions & 0 deletions internal/build-tools/concurrent-packages-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const childProcess = require("child_process");
const { getRootFolder } = require("./git-utils");

async function build(path) {
const rootFolderPath = await getRootFolder();
return new Promise((resolve, reject) => {
const buildProcess = childProcess.spawn(
"npm",
["run", "build", `-w="${path}"`],
{
shell: true,
cwd: rootFolderPath,
stdio: "inherit",
}
);

buildProcess.on("close", (code) => {
if (code == 0) {
resolve();
} else {
reject(code);
}
});
});
}

// no depedencies
const stage1 = () => [build("internal"), build("packages/live-share")];

// dependent on "packages/live-share"
const stage2 = () => [
build("packages/live-share-acs"),
build("packages/live-share-media"),
build("packages/live-share-canvas"),
];

// dependent on "stage 2"
const stage3 = () => [build("packages/live-share-react")];

Promise.all(stage1())
.then(() => Promise.all(stage2()))
.then(() => Promise.all(stage3()));
125 changes: 125 additions & 0 deletions internal/build-tools/ensure-packages-built.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/**
* This file is used to ensure that the live-share-sdk packages are built prior to being used by the samples.
* This is executed after running `npm install` from the any of the packages or samples, or the root directory.
*/

const childProcess = require("child_process");
const fs = require("fs");
const { getGitHash, getRootFolder } = require("./git-utils");

console.log("Ensuring local Live Share SDK packages have been built");
ensurePackagesBuilt();
/**
* if packages are not built or if they are old builds then:
*
* 1. run npm install from root to ensure all dependencies are met
* 2. run npm run build:packages from root
*/
async function ensurePackagesBuilt() {
const rootFolderPath = await getRootFolder();
const currentGitHash = await getGitHash();
const buildDataJsonPath = `${rootFolderPath}/internal/build-tools/build-data.json`;

if (doesNeedBuild()) {
await npmInstallFromDirectory(rootFolderPath);
await build();
} else {
console.log("Live Share SDK packages already built");
}

async function npmInstallFromDirectory(directory) {
console.log("running npm install from: ", directory);
return new Promise((resolve, reject) => {
const installProcess = childProcess.spawn(
"npm",
["install", " --ignore-scripts"],
{
shell: true,
cwd: directory,
stdio: "inherit",
}
);

installProcess.on("close", (code) => {
if (code == 0) {
resolve();
} else {
reject(code);
}
});
});
}

async function build() {
console.log("Building Live Share SDK packages");
return new Promise((resolve, reject) => {
const buildProcess = childProcess.spawn(
"npm",
["run", "build:packages"],
{
shell: true,
cwd: rootFolderPath,
stdio: "inherit",
}
);

buildProcess.on("close", (code) => {
if (code === 0) {
fs.writeFileSync(
buildDataJsonPath,
JSON.stringify({
lastGitHashBuilt: currentGitHash,
})
);
resolve();
} else {
reject(code);
}
});
});
}

function doesNeedBuild() {
const isOldBuild = currentGitHash !== getBuildData()?.lastGitHashBuilt;

if (isOldBuild) {
return true;
}

const liveShareBuilt = fs.existsSync(
`${rootFolderPath}/node_modules/@microsoft/live-share/bin`
);
const liveShareMediaBuilt = fs.existsSync(
`${rootFolderPath}/node_modules/@microsoft/live-share-media/bin`
);
const liveShareCanvasBuilt = fs.existsSync(
`${rootFolderPath}/node_modules/@microsoft/live-share-canvas/bin`
);
const liveShareReactBuilt = fs.existsSync(
`${rootFolderPath}/node_modules/@microsoft/live-share-react/bin`
);
const liveShareAcsBuilt = fs.existsSync(
`${rootFolderPath}/node_modules/@microsoft/live-share-acs/bin`
);
const testUtils = fs.existsSync(
`${rootFolderPath}/node_modules/@live-share-private/test-utils/bin`
);

return [
liveShareBuilt,
liveShareMediaBuilt,
liveShareCanvasBuilt,
liveShareReactBuilt,
liveShareAcsBuilt,
testUtils,
].includes(false);
}

function getBuildData() {
try {
return require(buildDataJsonPath);
} catch {
return undefined;
}
}
}
47 changes: 47 additions & 0 deletions internal/build-tools/git-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const childProcess = require("child_process");

async function getGitHash() {
const currentGitHash = childProcess.spawn("git", ["rev-parse", "HEAD"], {
shell: true,
cwd: process.cwd(),
});
return new Promise((resolve, reject) => {
currentGitHash.stdout.on("data", (data) => {
const hash = data.toString().slice(0, -1);
resolve(hash);
});
currentGitHash.on("close", (code) => {
if (code != 0) {
reject(code);
}
});
});
}

async function getRootFolder() {
const rootDir = childProcess.spawn(
"git",
["rev-parse", " --show-toplevel"],
{
shell: true,
cwd: process.cwd(),
}
);

return new Promise((resolve, reject) => {
rootDir.stdout.on("data", (data) => {
const path = data.toString().slice(0, -1);
resolve(path);
});
rootDir.on("close", (code) => {
if (code != 0) {
reject(code);
}
});
});
}

module.exports = {
getGitHash,
getRootFolder,
};
Loading