-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor dev workflow (#1031)
- Loading branch information
Showing
42 changed files
with
742 additions
and
200 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
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
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
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
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,5 @@ | ||
#!/usr/bin/env node | ||
|
||
import { run } from "../src/index.mjs" | ||
|
||
run() |
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,20 @@ | ||
{ | ||
"name": "@rino.app/cli", | ||
"version": "0.0.0", | ||
"private": true, | ||
"type": "module", | ||
"license": "GPL-3.0", | ||
"bin": { | ||
"rino-cli": "bin/rino-cli.mjs" | ||
}, | ||
"devDependencies": { | ||
"@types/lodash-es": "^4.17.6", | ||
"commander": "^9.2.0", | ||
"fast-glob": "^3.2.11", | ||
"json5": "^2.2.1", | ||
"lodash-es": "^4.17.21", | ||
"merge-istanbul": "^1.1.4", | ||
"monorepo-license-checker": "^0.3.0", | ||
"nyc": "^15.1.0" | ||
} | ||
} |
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,10 @@ | ||
import { spawnSync } from "node:child_process" | ||
|
||
import { findTurboBin } from "../utils/find-turbo-bin.mjs" | ||
|
||
export function build(packages, { onlyDependencys = false } = {}) { | ||
const turboBin = findTurboBin() | ||
const args = ["run", "build", ...packages.map((name) => `--filter=${name}${onlyDependencys ? "^" : ""}...`)] | ||
console.log("$", turboBin + " " + args.join(" ")) | ||
spawnSync(turboBin, args, { stdio: "inherit" }) | ||
} |
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,37 @@ | ||
import glob from "fast-glob" | ||
import fs from "node:fs/promises" | ||
|
||
import { findRoot } from "../utils/find-root.mjs" | ||
|
||
const TO_CLEAN = [".next", "dist", "dist-types", ".cache", "coverage", "coverage-e2e", "out", "build", ".turbo"] | ||
const TO_IGNORE = ["node_modules"] | ||
|
||
async function cleanAll() { | ||
const root = findRoot() | ||
|
||
const dirs = [ | ||
...glob.sync( | ||
TO_CLEAN.map((dir) => `**/${dir}/`), | ||
{ | ||
ignore: TO_IGNORE.map((dir) => `**/${dir}/**`), | ||
cwd: root, | ||
onlyDirectories: true, | ||
absolute: true, | ||
}, | ||
), | ||
...glob.sync("node_modules/.cache", { | ||
cwd: root, | ||
onlyDirectories: true, | ||
absolute: true, | ||
}), | ||
] | ||
|
||
for (const dir of dirs) { | ||
await fs.rm(dir, { recursive: true, force: true }) | ||
console.log(`deleted ${dir}`) | ||
} | ||
|
||
console.log(`deleted ${dirs.length} items in total`) | ||
} | ||
|
||
export { cleanAll as clean } |
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,12 @@ | ||
import { spawnSync } from "node:child_process" | ||
|
||
import { findTurboBin } from "../utils/find-turbo-bin.mjs" | ||
import { build } from "./build.mjs" | ||
|
||
export function dev(packages) { | ||
build(packages, { onlyDependencys: true }) | ||
const turboBin = findTurboBin() | ||
const args = ["run", "dev", ...packages.map((name) => `--filter=${name}...`), "--parallel"] | ||
console.log("$", turboBin + " " + args.join(" ")) | ||
spawnSync(turboBin, args, { stdio: "inherit" }) | ||
} |
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,53 @@ | ||
import glob from "fast-glob" | ||
import path from "node:path" | ||
|
||
import { findRoot } from "../utils/find-root.mjs" | ||
import { readJson } from "../utils/read-json.mjs" | ||
import { writeJson } from "../utils/write-json.mjs" | ||
|
||
async function generateTsconfig() { | ||
const root = findRoot() | ||
const tsconfigPaths = glob.sync("packages/*/*/tsconfig.json", { cwd: root, ignore: "**/node_modules/**" }) | ||
tsconfigPaths.sort() | ||
|
||
const rootTsconfigPath = path.join(root, "tsconfig.json") | ||
const rootTsconfigJson = { include: [], files: [], references: [] } | ||
|
||
rootTsconfigJson.references = tsconfigPaths.map((tsconfigPath) => ({ | ||
path: tsconfigPath, | ||
})) | ||
|
||
await writeJson(rootTsconfigPath, rootTsconfigJson) | ||
|
||
for (let tsconfigPath of glob.sync("packages/*/src/tsconfig.json", { cwd: root, ignore: "**/node_modules/**" })) { | ||
const absPath = path.join(root, tsconfigPath) | ||
const oldJson = await readJson(absPath) | ||
const newJson = { | ||
...oldJson, | ||
compilerOptions: { | ||
composite: true, | ||
outDir: "../dist-types/", | ||
...oldJson.compilerOptions, | ||
}, | ||
} | ||
await writeJson(absPath, newJson) | ||
} | ||
|
||
for (let tsconfigPath of glob.sync("packages/*/test/tsconfig.json", { cwd: root, ignore: "**/node_modules/**" })) { | ||
const absPath = path.join(root, tsconfigPath) | ||
const oldJson = await readJson(absPath) | ||
const newJson = { | ||
...oldJson, | ||
compilerOptions: { | ||
composite: true, | ||
outDir: "./.cache/typescript/", | ||
...oldJson.compilerOptions, | ||
}, | ||
} | ||
await writeJson(absPath, newJson) | ||
} | ||
} | ||
|
||
export function generate() { | ||
generateTsconfig() | ||
} |
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,24 @@ | ||
import { spawnSync } from "node:child_process" | ||
import path from "node:path" | ||
|
||
import { findRoot } from "../utils/find-root.mjs" | ||
import { findTurboBin } from "../utils/find-turbo-bin.mjs" | ||
|
||
export function test(testPath) { | ||
const root = findRoot() | ||
const absTestPath = path.resolve(process.cwd(), testPath) | ||
const packageName = path.relative(root, absTestPath).split(path.sep)[1] | ||
const turboBin = findTurboBin() | ||
|
||
if (packageName) { | ||
const args = ["run", "test:vitest", `--filter=${packageName}`, "--", absTestPath] | ||
console.log("$", turboBin + " " + args.join(" ")) | ||
spawnSync(turboBin, args, { stdio: "inherit", cwd: root }) | ||
} else if (root == absTestPath) { | ||
const args = ["run", "test:vitest"] | ||
console.log("$", turboBin + " " + args.join(" ")) | ||
spawnSync(turboBin, args, { stdio: "inherit", cwd: root }) | ||
} else { | ||
throw new Error(`Test path ${absTestPath} must be inside a package`) | ||
} | ||
} |
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,49 @@ | ||
import { program } from "commander" | ||
|
||
import { build } from "./commands/build.mjs" | ||
import { clean } from "./commands/clean.mjs" | ||
import { dev } from "./commands/dev.mjs" | ||
import { generate } from "./commands/generate.mjs" | ||
import { test } from "./commands/test.mjs" | ||
|
||
export function run() { | ||
program | ||
.command("clean") | ||
.description("Clean all temporary files") | ||
.action(() => { | ||
clean() | ||
}) | ||
|
||
program | ||
.command("gen") | ||
.description("Generate files") | ||
.action(() => { | ||
generate() | ||
}) | ||
|
||
program | ||
.command("dev") | ||
.description("Run dev commands for selected packages") | ||
.argument("<packages...>", "Package names to run") | ||
.action((packages) => { | ||
dev(packages) | ||
}) | ||
|
||
program | ||
.command("build") | ||
.description("Run build commands for selected packages") | ||
.argument("<packages...>", "Package names to run") | ||
.action((packages) => { | ||
build(packages) | ||
}) | ||
|
||
program | ||
.command("test") | ||
.description("Test") | ||
.argument("[path]", "File path or directory path", process.cwd()) | ||
.action((path) => { | ||
test(path) | ||
}) | ||
|
||
program.parse() | ||
} |
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,11 @@ | ||
{ | ||
"extends": "../../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"composite": true, | ||
"outDir": "../dist-types/" | ||
}, | ||
"include": [ | ||
"./" | ||
], | ||
"references": [] | ||
} |
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,8 @@ | ||
import { execSync } from "child_process" | ||
|
||
/** | ||
* Find the git repo root absolute path. | ||
*/ | ||
export function findRoot() { | ||
return execSync("git rev-parse --show-toplevel", { encoding: "utf-8" }).trim() | ||
} |
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,7 @@ | ||
import path from "node:path" | ||
|
||
import { findRoot } from "./find-root.mjs" | ||
|
||
export function findTurboBin() { | ||
return path.resolve(findRoot(), "node_modules", ".bin", "turbo") | ||
} |
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,6 @@ | ||
import JSON5 from "json5" | ||
import fs from "node:fs/promises" | ||
|
||
export async function readJson(filePath) { | ||
return JSON5.parse(await fs.readFile(filePath, { encoding: "utf-8" })) | ||
} |
Oops, something went wrong.