@brickflow/cli 0.0.7 ā 0.0.9
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/package.json +11 -11
- package/src/latest/index.js +3 -4
- package/src/shared/workspace-root.js +31 -0
- package/src/translate/ai-context.js +52 -61
- package/src/translate/index.js +7 -38
- package/src/translate/utils.js +31 -0
- package/src/translate-context/index.js +3 -0
- package/src/upgrade/index.js +168 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brickflow/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.mjs",
|
|
@@ -15,16 +15,16 @@
|
|
|
15
15
|
"format:check": "pnpm exec prettier . --ignore-path ../../.prettierignore --check"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@babel/parser": "
|
|
19
|
-
"@babel/traverse": "
|
|
20
|
-
"@babel/types": "
|
|
21
|
-
"@google/genai": "
|
|
22
|
-
"@vue/compiler-sfc": "
|
|
23
|
-
"fantasticon": "
|
|
24
|
-
"glob": "
|
|
25
|
-
"looks-same": "
|
|
26
|
-
"sharp": "
|
|
27
|
-
"svgo": "
|
|
18
|
+
"@babel/parser": "7.29.7",
|
|
19
|
+
"@babel/traverse": "7.29.7",
|
|
20
|
+
"@babel/types": "7.29.7",
|
|
21
|
+
"@google/genai": "2.6.0",
|
|
22
|
+
"@vue/compiler-sfc": "3.5.35",
|
|
23
|
+
"fantasticon": "4.1.0",
|
|
24
|
+
"glob": "13.0.6",
|
|
25
|
+
"looks-same": "10.0.1",
|
|
26
|
+
"sharp": "0.34.5",
|
|
27
|
+
"svgo": "4.0.1"
|
|
28
28
|
},
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
package/src/latest/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { exec } from 'child_process'
|
|
2
2
|
import fs from 'fs'
|
|
3
3
|
import { globSync } from 'glob'
|
|
4
|
-
|
|
5
|
-
import {
|
|
4
|
+
|
|
5
|
+
import { resolveWorkspaceRoot } from '../shared/workspace-root.js'
|
|
6
6
|
|
|
7
7
|
const args = process.argv.slice(3)
|
|
8
8
|
|
|
@@ -16,8 +16,7 @@ if (args.length > 0) {
|
|
|
16
16
|
process.exit(1)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const
|
|
20
|
-
const workspaceRoot = path.resolve(currentDir, '../../../..')
|
|
19
|
+
const workspaceRoot = resolveWorkspaceRoot()
|
|
21
20
|
const packageJsonPaths = globSync('**/package.json', {
|
|
22
21
|
absolute: true,
|
|
23
22
|
cwd: workspaceRoot,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
|
|
4
|
+
const WORKSPACE_MARKERS = ['.git', 'pnpm-workspace.yaml', 'lerna.json', 'turbo.json']
|
|
5
|
+
|
|
6
|
+
export function resolveWorkspaceRoot(startDir = process.cwd()) {
|
|
7
|
+
let currentDir = path.resolve(startDir)
|
|
8
|
+
let packageRoot = null
|
|
9
|
+
|
|
10
|
+
while (true) {
|
|
11
|
+
if (hasAnyFile(currentDir, WORKSPACE_MARKERS)) {
|
|
12
|
+
return currentDir
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (fs.existsSync(path.join(currentDir, 'package.json'))) {
|
|
16
|
+
packageRoot = currentDir
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const parentDir = path.dirname(currentDir)
|
|
20
|
+
|
|
21
|
+
if (parentDir === currentDir) {
|
|
22
|
+
return packageRoot || startDir
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
currentDir = parentDir
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function hasAnyFile(directoryPath, fileNames) {
|
|
30
|
+
return fileNames.some((fileName) => fs.existsSync(path.join(directoryPath, fileName)))
|
|
31
|
+
}
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
parseTranslateRuntimeArgs,
|
|
13
13
|
setTranslateRuntimeConfig,
|
|
14
14
|
} from './runtime-config.js'
|
|
15
|
-
import {
|
|
15
|
+
import { listTranslationTargets, stringifySortedJson } from './utils.js'
|
|
16
16
|
|
|
17
17
|
const currentDir = dirname(fileURLToPath(import.meta.url))
|
|
18
18
|
const workspaceRoot = resolve(currentDir, '../../../..')
|
|
@@ -20,6 +20,10 @@ const CONTEXT_FILE_NAME = 'ai-context.json'
|
|
|
20
20
|
const CHANGE_THRESHOLD = readFloat('TRANSLATE_CONTEXT_MIN_CHANGE', 0.3)
|
|
21
21
|
const SOURCE_MAX_CHARS = readPositiveInt('TRANSLATE_CONTEXT_SOURCE_MAX_CHARS', 16000)
|
|
22
22
|
|
|
23
|
+
export function buildAiContextHelp(command = 'brick translate-context') {
|
|
24
|
+
return `${buildTranslateHelp(command)}\n\nExtra:\n --force`
|
|
25
|
+
}
|
|
26
|
+
|
|
23
27
|
export function calculateChangeRatio(previousSource, nextSource) {
|
|
24
28
|
const before = normalizeSource(previousSource)
|
|
25
29
|
const after = normalizeSource(nextSource)
|
|
@@ -112,6 +116,52 @@ export function getContextFilePath(samplePath) {
|
|
|
112
116
|
return join(dirname(samplePath), CONTEXT_FILE_NAME)
|
|
113
117
|
}
|
|
114
118
|
|
|
119
|
+
export async function runAiContextCli(rawArgs = process.argv.slice(3), command = 'brick translate-context') {
|
|
120
|
+
const helpText = buildAiContextHelp(command)
|
|
121
|
+
|
|
122
|
+
if (rawArgs.includes('--help') || rawArgs.includes('-h')) {
|
|
123
|
+
console.log(helpText)
|
|
124
|
+
process.exit(0)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const force = rawArgs.includes('--force')
|
|
128
|
+
const filteredArgs = rawArgs.filter((arg) => arg !== '--force')
|
|
129
|
+
const { options, positional } = parseTranslateRuntimeArgs(filteredArgs)
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
setTranslateRuntimeConfig(options)
|
|
133
|
+
} catch (error) {
|
|
134
|
+
console.error(error instanceof Error ? error.message : String(error))
|
|
135
|
+
console.error('')
|
|
136
|
+
console.error(helpText)
|
|
137
|
+
process.exit(1)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const targets = listTranslationTargets(workspaceRoot)
|
|
141
|
+
const requestedSamplePaths =
|
|
142
|
+
positional.length > 0 ? new Set(positional.map((samplePath) => resolve(workspaceRoot, samplePath))) : null
|
|
143
|
+
const targetEntries = requestedSamplePaths
|
|
144
|
+
? targets.filter(({ samplePath }) => requestedSamplePaths.has(samplePath))
|
|
145
|
+
: targets
|
|
146
|
+
|
|
147
|
+
for (const { samplePath, sourceFilePath } of targetEntries) {
|
|
148
|
+
if (!sourceFilePath || !fs.existsSync(samplePath)) {
|
|
149
|
+
continue
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const description = await ensureAiContext({
|
|
153
|
+
force,
|
|
154
|
+
sample: JSON.parse(fs.readFileSync(samplePath, 'utf-8')),
|
|
155
|
+
samplePath,
|
|
156
|
+
sourceFilePath,
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
if (description) {
|
|
160
|
+
console.log(`š§ Context updated: ${relative(workspaceRoot, samplePath)}`)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
115
165
|
function buildContextContents({ sampleEntries, samplePath, sourceCode, sourceFilePath }) {
|
|
116
166
|
return [
|
|
117
167
|
`Sample path: ${samplePath}`,
|
|
@@ -251,65 +301,6 @@ function readPositiveInt(name, fallback) {
|
|
|
251
301
|
return Number.isFinite(value) && value > 0 ? value : fallback
|
|
252
302
|
}
|
|
253
303
|
|
|
254
|
-
async function runCli() {
|
|
255
|
-
const rawArgs = process.argv.slice(2)
|
|
256
|
-
|
|
257
|
-
if (rawArgs.includes('--help') || rawArgs.includes('-h')) {
|
|
258
|
-
console.log(`${buildTranslateHelp('node packages/cli/src/translate/ai-context.js')}\n\nExtra:\n --force`)
|
|
259
|
-
process.exit(0)
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
const force = rawArgs.includes('--force')
|
|
263
|
-
const filteredArgs = rawArgs.filter((arg) => arg !== '--force')
|
|
264
|
-
const { options, positional } = parseTranslateRuntimeArgs(filteredArgs)
|
|
265
|
-
|
|
266
|
-
try {
|
|
267
|
-
setTranslateRuntimeConfig(options)
|
|
268
|
-
} catch (error) {
|
|
269
|
-
console.error(error instanceof Error ? error.message : String(error))
|
|
270
|
-
console.error('')
|
|
271
|
-
console.error(`${buildTranslateHelp('node packages/cli/src/translate/ai-context.js')}\n\nExtra:\n --force`)
|
|
272
|
-
process.exit(1)
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const sourceFiles = listWorkspaceFiles(workspaceRoot).filter(
|
|
276
|
-
(filePath) => /\.(?:js|ts|vue)$/.test(filePath) && !filePath.endsWith('.d.ts'),
|
|
277
|
-
)
|
|
278
|
-
const sampleToSource = new Map()
|
|
279
|
-
|
|
280
|
-
for (const sourceFilePath of sourceFiles) {
|
|
281
|
-
const samplePath = getTranslationPaths(sourceFilePath)?.samplePath
|
|
282
|
-
|
|
283
|
-
if (samplePath && fs.existsSync(samplePath) && !sampleToSource.has(samplePath)) {
|
|
284
|
-
sampleToSource.set(samplePath, sourceFilePath)
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
const targetSamplePaths =
|
|
289
|
-
positional.length > 0
|
|
290
|
-
? positional.map((samplePath) => resolve(workspaceRoot, samplePath))
|
|
291
|
-
: [...sampleToSource.keys()].sort()
|
|
292
|
-
|
|
293
|
-
for (const samplePath of targetSamplePaths) {
|
|
294
|
-
const sourceFilePath = sampleToSource.get(samplePath)
|
|
295
|
-
|
|
296
|
-
if (!sourceFilePath || !fs.existsSync(samplePath)) {
|
|
297
|
-
continue
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
const description = await ensureAiContext({
|
|
301
|
-
force,
|
|
302
|
-
sample: JSON.parse(fs.readFileSync(samplePath, 'utf-8')),
|
|
303
|
-
samplePath,
|
|
304
|
-
sourceFilePath,
|
|
305
|
-
})
|
|
306
|
-
|
|
307
|
-
if (description) {
|
|
308
|
-
console.log(`š§ Context updated: ${relative(workspaceRoot, samplePath)}`)
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
304
|
function writeTextPreservingEol(filePath, content) {
|
|
314
305
|
const eol = detectEol(filePath)
|
|
315
306
|
const normalized = String(content).replace(/\r?\n/g, eol)
|
|
@@ -317,5 +308,5 @@ function writeTextPreservingEol(filePath, content) {
|
|
|
317
308
|
}
|
|
318
309
|
|
|
319
310
|
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
320
|
-
await
|
|
311
|
+
await runAiContextCli(process.argv.slice(2), 'node packages/cli/src/translate/ai-context.js')
|
|
321
312
|
}
|
package/src/translate/index.js
CHANGED
|
@@ -3,10 +3,10 @@ import { globSync } from 'glob'
|
|
|
3
3
|
import { dirname, join, relative, resolve } from 'path'
|
|
4
4
|
import { fileURLToPath } from 'url'
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { getAiContextState } from './ai-context.js'
|
|
7
7
|
import { translateBatch } from './ai.js'
|
|
8
8
|
import { buildTranslateHelp, parseTranslateRuntimeArgs, setTranslateRuntimeConfig } from './runtime-config.js'
|
|
9
|
-
import {
|
|
9
|
+
import { listTranslationTargets, sortObjectKeys, stringifySortedJson } from './utils.js'
|
|
10
10
|
|
|
11
11
|
const currentDir = dirname(fileURLToPath(import.meta.url))
|
|
12
12
|
const workspaceRoot = resolve(currentDir, '../../../..')
|
|
@@ -68,33 +68,10 @@ const languageCodes = [
|
|
|
68
68
|
]),
|
|
69
69
|
].sort()
|
|
70
70
|
|
|
71
|
-
const
|
|
72
|
-
'{packages/brick,apps/*}/{components/**/translate,pages-translate/*,layouts/**,global/*}/sample.json',
|
|
73
|
-
{
|
|
74
|
-
absolute: true,
|
|
75
|
-
cwd: workspaceRoot,
|
|
76
|
-
ignore: ['**/node_modules/**', '**/.nuxt/**', '**/dist/**', '**/.output/**', '**/coverage/**', '**/public/**'],
|
|
77
|
-
},
|
|
78
|
-
).sort()
|
|
79
|
-
|
|
80
|
-
const sourceFiles = listWorkspaceFiles(workspaceRoot).filter(
|
|
81
|
-
(filePath) => /\.(?:js|ts|vue)$/.test(filePath) && !filePath.endsWith('.d.ts'),
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
const sampleToSource = new Map()
|
|
85
|
-
|
|
86
|
-
for (const sourceFilePath of sourceFiles) {
|
|
87
|
-
const samplePath = getTranslationPaths(sourceFilePath)?.samplePath
|
|
88
|
-
|
|
89
|
-
if (samplePath && fs.existsSync(samplePath) && !sampleToSource.has(samplePath)) {
|
|
90
|
-
sampleToSource.set(samplePath, sourceFilePath)
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const tasks = samplePaths.map((samplePath) => ({
|
|
71
|
+
const tasks = listTranslationTargets(workspaceRoot).map(({ samplePath, sourceFilePath }) => ({
|
|
95
72
|
sample: readJson(samplePath),
|
|
96
73
|
samplePath,
|
|
97
|
-
sourceFilePath
|
|
74
|
+
sourceFilePath,
|
|
98
75
|
}))
|
|
99
76
|
|
|
100
77
|
const total = tasks.reduce((count, task) => count + Object.keys(task.sample).length * languageCodes.length, 0)
|
|
@@ -111,7 +88,7 @@ for (const task of tasks) {
|
|
|
111
88
|
|
|
112
89
|
process.stdout.write('\n')
|
|
113
90
|
console.log(
|
|
114
|
-
`ā
Done: ${
|
|
91
|
+
`ā
Done: ${tasks.length} sample folders, ${languageCodes.length} languages, batch=${BATCH_MAX_ITEMS}/${BATCH_MAX_CHARS}`,
|
|
115
92
|
)
|
|
116
93
|
|
|
117
94
|
function createProgress(totalCount) {
|
|
@@ -228,18 +205,10 @@ async function processSample({ sample, samplePath, sourceFilePath }) {
|
|
|
228
205
|
let componentContext = null
|
|
229
206
|
|
|
230
207
|
if (pendingEntriesByLocales.size > 0) {
|
|
231
|
-
|
|
208
|
+
componentContext = getAiContextState({
|
|
232
209
|
samplePath,
|
|
233
210
|
sourceFilePath,
|
|
234
|
-
})
|
|
235
|
-
|
|
236
|
-
componentContext = contextState.shouldRegenerate
|
|
237
|
-
? await ensureAiContext({
|
|
238
|
-
sample,
|
|
239
|
-
samplePath,
|
|
240
|
-
sourceFilePath,
|
|
241
|
-
})
|
|
242
|
-
: contextState.description
|
|
211
|
+
}).description
|
|
243
212
|
}
|
|
244
213
|
|
|
245
214
|
for (const [localeKey, entries] of pendingEntriesByLocales) {
|
package/src/translate/utils.js
CHANGED
|
@@ -19,6 +19,8 @@ const IGNORED_GLOB_PATTERNS = [
|
|
|
19
19
|
'**/public/**',
|
|
20
20
|
]
|
|
21
21
|
const IGNORED_SOURCE_SEGMENTS = ['/node_modules/', '/.nuxt/', '/dist/', '/.output/', '/coverage/', '/public/']
|
|
22
|
+
const TRANSLATION_SAMPLE_GLOB =
|
|
23
|
+
'{packages/brick,apps/*}/{components/**/translate,pages-translate/*,layouts/**,global/*}/sample.json'
|
|
22
24
|
|
|
23
25
|
export function compileVueToJS(code, filePath) {
|
|
24
26
|
const { descriptor } = parseSFC(code)
|
|
@@ -233,6 +235,35 @@ export function getTranslationPaths(id) {
|
|
|
233
235
|
}
|
|
234
236
|
}
|
|
235
237
|
|
|
238
|
+
export function listTranslationSamplePaths(workspaceRoot) {
|
|
239
|
+
return globSync(TRANSLATION_SAMPLE_GLOB, {
|
|
240
|
+
absolute: true,
|
|
241
|
+
cwd: workspaceRoot,
|
|
242
|
+
ignore: IGNORED_GLOB_PATTERNS,
|
|
243
|
+
}).sort()
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function listTranslationTargets(workspaceRoot) {
|
|
247
|
+
const samplePaths = listTranslationSamplePaths(workspaceRoot)
|
|
248
|
+
const sourceFiles = listWorkspaceFiles(workspaceRoot).filter(
|
|
249
|
+
(filePath) => /\.(?:js|ts|vue)$/.test(filePath) && !filePath.endsWith('.d.ts'),
|
|
250
|
+
)
|
|
251
|
+
const sampleToSource = new Map()
|
|
252
|
+
|
|
253
|
+
for (const sourceFilePath of sourceFiles) {
|
|
254
|
+
const samplePath = getTranslationPaths(sourceFilePath)?.samplePath
|
|
255
|
+
|
|
256
|
+
if (samplePath && existsSync(samplePath) && !sampleToSource.has(samplePath)) {
|
|
257
|
+
sampleToSource.set(samplePath, sourceFilePath)
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return samplePaths.map((samplePath) => ({
|
|
262
|
+
samplePath,
|
|
263
|
+
sourceFilePath: sampleToSource.get(samplePath),
|
|
264
|
+
}))
|
|
265
|
+
}
|
|
266
|
+
|
|
236
267
|
export function listWorkspaceFiles(workspaceRoot) {
|
|
237
268
|
try {
|
|
238
269
|
const output = execFileSync('git', ['ls-files', '-co', '--exclude-standard', '-z'], {
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { exec } from 'child_process'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
|
|
5
|
+
import { resolveWorkspaceRoot } from '../shared/workspace-root.js'
|
|
6
|
+
|
|
7
|
+
const args = process.argv.slice(3)
|
|
8
|
+
|
|
9
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
10
|
+
printHelp()
|
|
11
|
+
process.exit(0)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (args.length > 0) {
|
|
15
|
+
printHelp()
|
|
16
|
+
process.exit(1)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const workspaceRoot = resolveWorkspaceRoot()
|
|
20
|
+
const packageJsonPaths = findPackageJsonPaths()
|
|
21
|
+
const localPackageNames = collectLocalBrickflowPackageNames(packageJsonPaths)
|
|
22
|
+
|
|
23
|
+
if (localPackageNames.length === 0) {
|
|
24
|
+
console.log('No local @brickflow/* packages found in the repository')
|
|
25
|
+
process.exit(0)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const latestVersions = new Map()
|
|
29
|
+
|
|
30
|
+
for (const packageName of localPackageNames) {
|
|
31
|
+
const version = await readLatestVersion(packageName)
|
|
32
|
+
|
|
33
|
+
if (version) {
|
|
34
|
+
latestVersions.set(packageName, version)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (latestVersions.size === 0) {
|
|
39
|
+
throw new Error('Could not resolve latest versions for local @brickflow/* packages')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log('\x1b[32m', '\rBrickflow package upgrade')
|
|
43
|
+
|
|
44
|
+
let changedFiles = 0
|
|
45
|
+
let index = 0
|
|
46
|
+
|
|
47
|
+
for (const packageJsonPath of packageJsonPaths) {
|
|
48
|
+
index += 1
|
|
49
|
+
|
|
50
|
+
const packageJson = readJson(packageJsonPath)
|
|
51
|
+
const before = JSON.stringify(packageJson)
|
|
52
|
+
|
|
53
|
+
updateDependencySections(packageJson, latestVersions)
|
|
54
|
+
|
|
55
|
+
if (JSON.stringify(packageJson) !== before) {
|
|
56
|
+
writeJson(packageJsonPath, packageJson)
|
|
57
|
+
changedFiles += 1
|
|
58
|
+
console.log(`\nš¦ Updated ${getPackageLabel(packageJsonPath)}`)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const percent = Math.round((index * 100) / packageJsonPaths.length)
|
|
62
|
+
process.stdout.write(`\rš© Upgrade: [${'ā'.repeat(Math.round(percent / 10)).padEnd(10, ' ')}] ${percent}%`)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
process.stdout.write('\n')
|
|
66
|
+
console.log(`Updated ${changedFiles} package.json file(s)`)
|
|
67
|
+
console.log('\x1b[0m', '')
|
|
68
|
+
|
|
69
|
+
function collectLocalBrickflowPackageNames(filePaths) {
|
|
70
|
+
return filePaths
|
|
71
|
+
.map((filePath) => readJson(filePath).name)
|
|
72
|
+
.filter((packageName) => isBrickflowPackageName(packageName))
|
|
73
|
+
.sort()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function findPackageJsonPaths() {
|
|
77
|
+
return walkDirectoryForPackageJson(workspaceRoot).sort()
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function getDependencySections(packageJson) {
|
|
81
|
+
return ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']
|
|
82
|
+
.map((sectionName) => ({
|
|
83
|
+
name: sectionName,
|
|
84
|
+
value: packageJson[sectionName],
|
|
85
|
+
}))
|
|
86
|
+
.filter((section) => section.value && typeof section.value === 'object')
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function getPackageLabel(packageJsonPath) {
|
|
90
|
+
const relativePath = path.relative(workspaceRoot, packageJsonPath).replace(/\\/g, '/')
|
|
91
|
+
const packageDir = path.dirname(relativePath)
|
|
92
|
+
|
|
93
|
+
return packageDir === '.' ? 'root' : packageDir
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function isBrickflowPackageName(packageName) {
|
|
97
|
+
return typeof packageName === 'string' && packageName.startsWith('@brickflow/')
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function printHelp() {
|
|
101
|
+
console.log(`brick upgrade
|
|
102
|
+
|
|
103
|
+
Usage:
|
|
104
|
+
brick upgrade
|
|
105
|
+
|
|
106
|
+
Notes:
|
|
107
|
+
Finds local @brickflow/* package names from package.json files in the repository
|
|
108
|
+
Fetches the latest published version for each of those packages
|
|
109
|
+
Updates matching dependencies, devDependencies, peerDependencies and optionalDependencies in all package.json files`)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function readJson(filePath) {
|
|
113
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf8'))
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function readLatestVersion(packageName) {
|
|
117
|
+
return new Promise((resolve) => {
|
|
118
|
+
exec(`npm view ${packageName} version`, (error, stdout) => {
|
|
119
|
+
if (error) {
|
|
120
|
+
console.warn(`Skipping ${packageName}: ${error.message}`)
|
|
121
|
+
resolve(null)
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
resolve(String(stdout).trim().replace('\n', ''))
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function updateDependencySections(packageJson, latestVersionsMap) {
|
|
131
|
+
for (const section of getDependencySections(packageJson)) {
|
|
132
|
+
for (const dependencyName of Object.keys(section.value)) {
|
|
133
|
+
const latestVersion = latestVersionsMap.get(dependencyName)
|
|
134
|
+
|
|
135
|
+
if (latestVersion) {
|
|
136
|
+
section.value[dependencyName] = latestVersion
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function walkDirectoryForPackageJson(directoryPath) {
|
|
143
|
+
const entries = fs.readdirSync(directoryPath, { withFileTypes: true })
|
|
144
|
+
const filePaths = []
|
|
145
|
+
|
|
146
|
+
for (const entry of entries) {
|
|
147
|
+
if (entry.name === 'node_modules') {
|
|
148
|
+
continue
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const entryPath = path.join(directoryPath, entry.name)
|
|
152
|
+
|
|
153
|
+
if (entry.isDirectory()) {
|
|
154
|
+
filePaths.push(...walkDirectoryForPackageJson(entryPath))
|
|
155
|
+
continue
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (entry.isFile() && entry.name === 'package.json') {
|
|
159
|
+
filePaths.push(entryPath)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return filePaths
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function writeJson(filePath, value) {
|
|
167
|
+
fs.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`)
|
|
168
|
+
}
|