Skip to content

Commit f4aa472

Browse files
authored
chore: add script to run commands on playground directories (#36)
* chore: add script to run commands on playground directories also optimize build-playground script a bit * chore: update lint-staged prettier pattern to include mjs * style: format playground scripts
1 parent d2a4911 commit f4aa472

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"prepare": "husky install",
2323
"prepublishOnly": "pnpm run build",
2424
"release": "standard-version --sign",
25+
"run:playground": "node scripts/run-playground.mjs",
2526
"test:playground": "playwright test",
2627
"test:playground:ui": "pnpm run test:playground --ui"
2728
},
@@ -73,8 +74,8 @@
7374
"standard-version": "^9.5.0"
7475
},
7576
"lint-staged": {
76-
"*.{js,ts,vue,json,yml,md}": [
77-
"prettier --write"
77+
"*": [
78+
"prettier --write --cache --ignore-unknown"
7879
]
7980
}
8081
}

scripts/build-playground.mjs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import util from "util";
22
import { fileURLToPath } from "url";
3-
import { dirname } from "path";
4-
import { exec as execCallback } from "child_process";
3+
import { dirname, resolve } from "path";
4+
import { exec as execCallback, spawn } from "child_process";
55

66
const exec = util.promisify(execCallback);
77

@@ -14,7 +14,9 @@ const manifestVersions = ["2", "3", "2+3"];
1414
const builds = [];
1515

1616
(async () => {
17-
await exec("pnpm build");
17+
const { stdout } = await exec("pnpm build");
18+
console.log(stdout);
19+
1820
await exec("mkdir -p playground && rm -rf playground/*");
1921

2022
for (const framework of frameworks) {
@@ -33,13 +35,10 @@ const builds = [];
3335
}
3436

3537
for (const buildArgs of builds) {
36-
await exec(`cd playground && node ../create.cjs ${buildArgs.join(" ")}`);
37-
38-
await exec(
39-
`cd playground/${buildArgs[0]} && pnpm i && pnpm build --mode development`
40-
);
41-
console.log(
42-
`cd ${__dirname}/../playground/${buildArgs[0]} && pnpm serve:chrome`
43-
);
38+
spawn(`cd playground && node ../create.cjs ${buildArgs.join(" ")}`, {
39+
shell: true,
40+
});
41+
42+
console.log(resolve(`${__dirname}/../playground/${buildArgs[0]}`));
4443
}
4544
})();

scripts/run-playground.mjs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { fileURLToPath } from "url";
2+
import { dirname, join } from "path";
3+
import { spawn } from "child_process";
4+
import { readdir } from "fs/promises";
5+
6+
async function getDirectories(path) {
7+
try {
8+
return (await readdir(path, { withFileTypes: true }))
9+
.filter((dirent) => dirent.isDirectory())
10+
.map((dirent) => dirent.name);
11+
} catch (e) {
12+
return [];
13+
}
14+
}
15+
16+
const __dirname = dirname(fileURLToPath(import.meta.url));
17+
const playgroundDir = join(__dirname, "../playground");
18+
const builds = await getDirectories(playgroundDir);
19+
20+
const supportedCommands = ["build", "dev", "install"];
21+
22+
const inputCommand = process.argv[2] ?? "build";
23+
24+
if (!supportedCommands.includes(inputCommand)) {
25+
throw new Error(`Supported commands: ${supportedCommands.join(", ")}`);
26+
}
27+
28+
let pnpmCommand = "build";
29+
switch (inputCommand) {
30+
case "build":
31+
pnpmCommand = "build --mode development";
32+
break;
33+
case "dev":
34+
pnpmCommand = "dev --clearScreen false";
35+
break;
36+
default:
37+
pnpmCommand = inputCommand;
38+
}
39+
40+
for (const build of builds) {
41+
spawn(`cd ${join(playgroundDir, build)} && pnpm ${pnpmCommand}`, {
42+
stdio: "inherit",
43+
shell: true,
44+
});
45+
}

0 commit comments

Comments
 (0)