@brickflow/cli 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/index.mjs +109 -0
- package/package.json +7 -2
package/CHANGELOG.md
CHANGED
package/index.mjs
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { execFile } from 'node:child_process'
|
|
4
|
+
import { readdir, readFile, writeFile } from 'node:fs/promises'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
7
|
+
import { promisify } from 'node:util'
|
|
8
|
+
|
|
9
|
+
const execFileAsync = promisify(execFile)
|
|
10
|
+
const cliDir = path.dirname(fileURLToPath(import.meta.url))
|
|
11
|
+
const repoRoot = path.resolve(cliDir, '../..')
|
|
12
|
+
const workspaceRoots = ['apps', 'packages']
|
|
13
|
+
|
|
14
|
+
async function getWorkspacePackageJsonPaths() {
|
|
15
|
+
const packagePaths = []
|
|
16
|
+
|
|
17
|
+
for (const workspaceRoot of workspaceRoots) {
|
|
18
|
+
const rootPath = path.join(repoRoot, workspaceRoot)
|
|
19
|
+
const entries = await readdir(rootPath, { withFileTypes: true })
|
|
20
|
+
|
|
21
|
+
for (const entry of entries) {
|
|
22
|
+
if (!entry.isDirectory()) {
|
|
23
|
+
continue
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
packagePaths.push(path.join(rootPath, entry.name, 'package.json'))
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return packagePaths
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function main() {
|
|
34
|
+
const [command] = process.argv.slice(2)
|
|
35
|
+
|
|
36
|
+
switch (command) {
|
|
37
|
+
case 'latest':
|
|
38
|
+
await runLatest()
|
|
39
|
+
return
|
|
40
|
+
default:
|
|
41
|
+
printHelp()
|
|
42
|
+
process.exitCode = 1
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function printHelp() {
|
|
47
|
+
console.log(`brick cli
|
|
48
|
+
|
|
49
|
+
Usage:
|
|
50
|
+
brick latest`)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function renderProgress(percent) {
|
|
54
|
+
const completed = Math.round(percent / 10)
|
|
55
|
+
return `${'#'.repeat(completed)}${'.'.repeat(10 - completed)}`
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function runLatest() {
|
|
59
|
+
console.log('\x1b[32mPackage update')
|
|
60
|
+
|
|
61
|
+
const packagePaths = await getWorkspacePackageJsonPaths()
|
|
62
|
+
let index = 0
|
|
63
|
+
|
|
64
|
+
for (const packagePath of packagePaths) {
|
|
65
|
+
index += 1
|
|
66
|
+
|
|
67
|
+
const packageJson = JSON.parse(await readFile(packagePath, 'utf8'))
|
|
68
|
+
await updatePackageVersions(packageJson)
|
|
69
|
+
await writeFile(packagePath, `${JSON.stringify(packageJson, null, 2)}\n`)
|
|
70
|
+
|
|
71
|
+
const percent = Math.round((index * 100) / packagePaths.length)
|
|
72
|
+
process.stdout.write(`\rUpdating: [${renderProgress(percent)}] ${percent}%`)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
process.stdout.write('\n')
|
|
76
|
+
console.log('\x1b[0m')
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function updatePackageVersions(packageJson) {
|
|
80
|
+
const dependencyEntries = [
|
|
81
|
+
...Object.entries(packageJson.dependencies || {}).map(([name, version]) => ({
|
|
82
|
+
group: 'dependencies',
|
|
83
|
+
name,
|
|
84
|
+
version,
|
|
85
|
+
})),
|
|
86
|
+
...Object.entries(packageJson.devDependencies || {}).map(([name, version]) => ({
|
|
87
|
+
group: 'devDependencies',
|
|
88
|
+
name,
|
|
89
|
+
version,
|
|
90
|
+
})),
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
await Promise.all(
|
|
94
|
+
dependencyEntries.map(async ({ group, name, version }) => {
|
|
95
|
+
if (version === 'workspace:*' || version === 'workspace: *') {
|
|
96
|
+
return
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
const { stdout } = await execFileAsync('npm', ['view', name, 'version'])
|
|
101
|
+
packageJson[group][name] = stdout.trim()
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.info(error instanceof Error ? error.message : String(error))
|
|
104
|
+
}
|
|
105
|
+
}),
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
await main()
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brickflow/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.mjs",
|
|
7
|
+
"bin": {
|
|
8
|
+
"brick": "./index.mjs"
|
|
9
|
+
},
|
|
6
10
|
"scripts": {
|
|
11
|
+
"latest": "node ./index.mjs latest",
|
|
7
12
|
"lint": "pnpm run --if-present typecheck && eslint -v && NODE_ENV=deploy eslint --cache .",
|
|
8
13
|
"lint:fix": "pnpm exec eslint . --fix",
|
|
9
14
|
"format": "pnpm exec prettier . --ignore-path ../../.prettierignore --write",
|