@fugood/bricks-ctor 2.25.0-beta.10 → 2.25.0-beta.11
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/package.json +3 -3
- package/tools/update-config.ts +110 -0
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fugood/bricks-ctor",
|
|
3
|
-
"version": "2.25.0-beta.
|
|
3
|
+
"version": "2.25.0-beta.11",
|
|
4
4
|
"main": "index.ts",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"typecheck": "tsc --noEmit",
|
|
7
7
|
"build": "bun scripts/build.js"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@fugood/bricks-cli": "^2.25.0-beta.
|
|
10
|
+
"@fugood/bricks-cli": "^2.25.0-beta.11",
|
|
11
11
|
"@huggingface/gguf": "^0.3.2",
|
|
12
12
|
"@iarna/toml": "^3.0.0",
|
|
13
13
|
"@modelcontextprotocol/sdk": "^1.15.0",
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"oxfmt": "^0.36.0"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "701de04bd2b569a5fe446a1c89ac776bb79f89f7"
|
|
29
29
|
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { parseArgs } from 'util'
|
|
3
|
+
import { sh } from './_shell'
|
|
4
|
+
import { buildCommitArgs } from './_git-author'
|
|
5
|
+
|
|
6
|
+
const cwd = process.cwd()
|
|
7
|
+
|
|
8
|
+
const readJson = async (p: string) => JSON.parse(await readFile(p, 'utf8'))
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
values: { 'auto-commit': autoCommit, 'no-check': noCheck, 'no-validate': noValidate, yes, help },
|
|
12
|
+
} = parseArgs({
|
|
13
|
+
args: process.argv.slice(2),
|
|
14
|
+
options: {
|
|
15
|
+
'auto-commit': { type: 'boolean' },
|
|
16
|
+
'no-check': { type: 'boolean' },
|
|
17
|
+
'no-validate': { type: 'boolean' },
|
|
18
|
+
yes: { type: 'boolean', short: 'y' },
|
|
19
|
+
help: { type: 'boolean', short: 'h' },
|
|
20
|
+
},
|
|
21
|
+
allowPositionals: true,
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
if (help) {
|
|
25
|
+
console.log(`Push compiled config to BRICKS without creating a release.
|
|
26
|
+
|
|
27
|
+
Options:
|
|
28
|
+
--auto-commit Auto-commit unstaged changes before pushing
|
|
29
|
+
--no-check Skip the conflict guard (don't pass --last-commit-id)
|
|
30
|
+
--no-validate Skip server-side config schema validation
|
|
31
|
+
-y, --yes Skip all prompts
|
|
32
|
+
-h, --help Show this help message`)
|
|
33
|
+
process.exit(0)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Detect git repo (mirrors deploy.ts)
|
|
37
|
+
const { exitCode } = await sh`cd ${cwd} && git status`.quiet().nothrow()
|
|
38
|
+
const isGitRepo = exitCode === 0
|
|
39
|
+
|
|
40
|
+
if (!isGitRepo && !yes) {
|
|
41
|
+
const confirmContinue = prompt('No git repository found, continue? (y/n)')
|
|
42
|
+
if (confirmContinue !== 'y') throw new Error('Update cancelled')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Read application.json + compiled config
|
|
46
|
+
const app = await readJson(`${cwd}/application.json`)
|
|
47
|
+
const config = await readJson(`${cwd}/.bricks/build/application-config.json`)
|
|
48
|
+
|
|
49
|
+
// Handle unstaged changes the same way deploy.ts does.
|
|
50
|
+
let commitId = ''
|
|
51
|
+
let parentCommitId = ''
|
|
52
|
+
if (isGitRepo) {
|
|
53
|
+
const unstagedChanges = await sh`cd ${cwd} && git diff --name-only --diff-filter=ACMR`.text()
|
|
54
|
+
if (unstagedChanges) {
|
|
55
|
+
if (autoCommit) {
|
|
56
|
+
// Capture the pre-commit HEAD so we can use it as the conflict-check
|
|
57
|
+
// baseline (the server should still hold it from the prior deploy).
|
|
58
|
+
parentCommitId = (await sh`cd ${cwd} && git rev-parse HEAD`.nothrow().text()).trim()
|
|
59
|
+
await sh`cd ${cwd} && git add -A`
|
|
60
|
+
const commitArgs = await buildCommitArgs(cwd, ['chore: update bricks config'])
|
|
61
|
+
await sh`cd ${cwd} && git ${commitArgs}`
|
|
62
|
+
} else {
|
|
63
|
+
throw new Error('Unstaged changes found, please commit or stash your changes before updating')
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
commitId = (await sh`cd ${cwd} && git rev-parse HEAD`.text()).trim()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Auto-derive --last-commit-id for the server-side conflict guard.
|
|
70
|
+
// - parent of the auto-commit (server still holds it from the prior deploy)
|
|
71
|
+
// - current HEAD (clean tree — server should be at the same commit too)
|
|
72
|
+
let lastCommitId: string | undefined
|
|
73
|
+
if (!noCheck) {
|
|
74
|
+
if (parentCommitId) lastCommitId = parentCommitId
|
|
75
|
+
else if (commitId) lastCommitId = commitId
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!yes) {
|
|
79
|
+
const confirm = prompt('Are you sure you want to push the new config? (y/n)')
|
|
80
|
+
if (confirm !== 'y') throw new Error('Update cancelled')
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const isModule = app.type === 'module'
|
|
84
|
+
const command = isModule ? 'module' : 'app'
|
|
85
|
+
|
|
86
|
+
const updateConfig = {
|
|
87
|
+
...config,
|
|
88
|
+
bricks_project_last_commit_id: commitId || undefined,
|
|
89
|
+
}
|
|
90
|
+
const configPath = `${cwd}/.bricks/build/update-config.json`
|
|
91
|
+
await writeFile(configPath, JSON.stringify(updateConfig))
|
|
92
|
+
|
|
93
|
+
const args = ['bricks', command, 'update', app.id, '-f', configPath, '--json']
|
|
94
|
+
if (noValidate) args.push('--no-validate')
|
|
95
|
+
if (lastCommitId) args.push('--last-commit-id', lastCommitId)
|
|
96
|
+
|
|
97
|
+
const result = await sh`${args}`.quiet().nothrow()
|
|
98
|
+
|
|
99
|
+
if (result.exitCode !== 0) {
|
|
100
|
+
const output = result.stderr.toString() || result.stdout.toString()
|
|
101
|
+
try {
|
|
102
|
+
const json = JSON.parse(output)
|
|
103
|
+
throw new Error(json.error?.message || json.error || 'Update failed')
|
|
104
|
+
} catch {
|
|
105
|
+
throw new Error(output || 'Update failed')
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const output = JSON.parse(result.stdout.toString())
|
|
110
|
+
console.log(`${isModule ? 'Module' : 'App'} config updated: ${output.target?.name || app.name}`)
|