-
Notifications
You must be signed in to change notification settings - Fork 3
/
publish.js
45 lines (36 loc) · 1.3 KB
/
publish.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* eslint no-console: off */
import { readdirSync, readFileSync } from "fs";
import { spawnSync } from "child_process";
import path from "path";
// Load the root package file so we can iterate over configured workspaces
const packageJSON = readFileSync("./package.json");
const data = JSON.parse(packageJSON);
let workspaces = [];
data.workspaces.forEach((workspace) => {
// If this is a glob, remove the asterisk
if (workspace.substring(workspace.length - 1) === "*") {
workspace = workspace.substring(0, workspace.length - 1);
// Find every workspace under this glob
readdirSync(path.resolve(workspace)).forEach((file) => {
// Skip all dot files
if (file.substring(0, 1) === ".") {
return;
}
workspaces.push(path.join(workspace, file));
});
} else {
// This is a specific workspace, go ahead and just add it
workspaces.push(workspace);
}
});
// Make a unique list of all the workspaces that we found
workspaces = workspaces.filter((v, i, a) => a.indexOf(v) === i);
workspaces.forEach((workspace) => {
const command = `--workspace=${workspace}`;
const result = spawnSync("npm", ["publish", "--access=public", command]);
if (result.status === 0) {
console.log(`Published ${workspace}`);
} else {
console.log(`Skipping ${workspace}`);
}
});