@brickflow/cli 0.0.7 ā 0.0.8
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 +6 -0
- package/package.json +11 -11
- package/src/latest/index.js +1 -1
- package/src/translate/ai-context.js +17 -26
- 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.8",
|
|
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
|
@@ -17,7 +17,7 @@ if (args.length > 0) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const currentDir = path.dirname(fileURLToPath(import.meta.url))
|
|
20
|
-
const workspaceRoot = path.resolve(currentDir, '
|
|
20
|
+
const workspaceRoot = path.resolve(currentDir, './')
|
|
21
21
|
const packageJsonPaths = globSync('**/package.json', {
|
|
22
22
|
absolute: true,
|
|
23
23
|
cwd: workspaceRoot,
|
|
@@ -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, '../../../..')
|
|
@@ -251,11 +251,15 @@ function readPositiveInt(name, fallback) {
|
|
|
251
251
|
return Number.isFinite(value) && value > 0 ? value : fallback
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
-
|
|
255
|
-
|
|
254
|
+
export function buildAiContextHelp(command = 'brick translate-context') {
|
|
255
|
+
return `${buildTranslateHelp(command)}\n\nExtra:\n --force`
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export async function runAiContextCli(rawArgs = process.argv.slice(3), command = 'brick translate-context') {
|
|
259
|
+
const helpText = buildAiContextHelp(command)
|
|
256
260
|
|
|
257
261
|
if (rawArgs.includes('--help') || rawArgs.includes('-h')) {
|
|
258
|
-
console.log(
|
|
262
|
+
console.log(helpText)
|
|
259
263
|
process.exit(0)
|
|
260
264
|
}
|
|
261
265
|
|
|
@@ -268,31 +272,18 @@ async function runCli() {
|
|
|
268
272
|
} catch (error) {
|
|
269
273
|
console.error(error instanceof Error ? error.message : String(error))
|
|
270
274
|
console.error('')
|
|
271
|
-
console.error(
|
|
275
|
+
console.error(helpText)
|
|
272
276
|
process.exit(1)
|
|
273
277
|
}
|
|
274
278
|
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
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)
|
|
279
|
+
const targets = listTranslationTargets(workspaceRoot)
|
|
280
|
+
const requestedSamplePaths =
|
|
281
|
+
positional.length > 0 ? new Set(positional.map((samplePath) => resolve(workspaceRoot, samplePath))) : null
|
|
282
|
+
const targetEntries = requestedSamplePaths
|
|
283
|
+
? targets.filter(({ samplePath }) => requestedSamplePaths.has(samplePath))
|
|
284
|
+
: targets
|
|
295
285
|
|
|
286
|
+
for (const { samplePath, sourceFilePath } of targetEntries) {
|
|
296
287
|
if (!sourceFilePath || !fs.existsSync(samplePath)) {
|
|
297
288
|
continue
|
|
298
289
|
}
|
|
@@ -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)
|
|
@@ -255,6 +257,35 @@ export function listWorkspaceFiles(workspaceRoot) {
|
|
|
255
257
|
}
|
|
256
258
|
}
|
|
257
259
|
|
|
260
|
+
export function listTranslationSamplePaths(workspaceRoot) {
|
|
261
|
+
return globSync(TRANSLATION_SAMPLE_GLOB, {
|
|
262
|
+
absolute: true,
|
|
263
|
+
cwd: workspaceRoot,
|
|
264
|
+
ignore: IGNORED_GLOB_PATTERNS,
|
|
265
|
+
}).sort()
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export function listTranslationTargets(workspaceRoot) {
|
|
269
|
+
const samplePaths = listTranslationSamplePaths(workspaceRoot)
|
|
270
|
+
const sourceFiles = listWorkspaceFiles(workspaceRoot).filter(
|
|
271
|
+
(filePath) => /\.(?:js|ts|vue)$/.test(filePath) && !filePath.endsWith('.d.ts'),
|
|
272
|
+
)
|
|
273
|
+
const sampleToSource = new Map()
|
|
274
|
+
|
|
275
|
+
for (const sourceFilePath of sourceFiles) {
|
|
276
|
+
const samplePath = getTranslationPaths(sourceFilePath)?.samplePath
|
|
277
|
+
|
|
278
|
+
if (samplePath && existsSync(samplePath) && !sampleToSource.has(samplePath)) {
|
|
279
|
+
sampleToSource.set(samplePath, sourceFilePath)
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return samplePaths.map((samplePath) => ({
|
|
284
|
+
samplePath,
|
|
285
|
+
sourceFilePath: sampleToSource.get(samplePath),
|
|
286
|
+
}))
|
|
287
|
+
}
|
|
288
|
+
|
|
258
289
|
export function normalize(input) {
|
|
259
290
|
return input.trim().toLowerCase().replace(/\s+/g, ' ')
|
|
260
291
|
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { exec } from 'child_process'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import { fileURLToPath } from 'url'
|
|
5
|
+
|
|
6
|
+
const args = process.argv.slice(3)
|
|
7
|
+
|
|
8
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
9
|
+
printHelp()
|
|
10
|
+
process.exit(0)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (args.length > 0) {
|
|
14
|
+
printHelp()
|
|
15
|
+
process.exit(1)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const currentDir = path.dirname(fileURLToPath(import.meta.url))
|
|
19
|
+
const workspaceRoot = path.resolve(currentDir, '../../../..')
|
|
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 writeJson(filePath, value) {
|
|
143
|
+
fs.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function walkDirectoryForPackageJson(directoryPath) {
|
|
147
|
+
const entries = fs.readdirSync(directoryPath, { withFileTypes: true })
|
|
148
|
+
const filePaths = []
|
|
149
|
+
|
|
150
|
+
for (const entry of entries) {
|
|
151
|
+
if (entry.name === 'node_modules') {
|
|
152
|
+
continue
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const entryPath = path.join(directoryPath, entry.name)
|
|
156
|
+
|
|
157
|
+
if (entry.isDirectory()) {
|
|
158
|
+
filePaths.push(...walkDirectoryForPackageJson(entryPath))
|
|
159
|
+
continue
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (entry.isFile() && entry.name === 'package.json') {
|
|
163
|
+
filePaths.push(entryPath)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return filePaths
|
|
168
|
+
}
|