create-sonicjs 3.0.0-beta.19 → 3.0.0-beta.20
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
CHANGED
package/src/cli.js
CHANGED
|
@@ -409,7 +409,7 @@ async function copyTemplate(templateName, targetDir, options) {
|
|
|
409
409
|
|
|
410
410
|
// Add @sonicjs-cms/core dependency
|
|
411
411
|
packageJson.dependencies = {
|
|
412
|
-
'@sonicjs-cms/core': '^3.0.0-beta.
|
|
412
|
+
'@sonicjs-cms/core': '^3.0.0-beta.20',
|
|
413
413
|
...packageJson.dependencies
|
|
414
414
|
}
|
|
415
415
|
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"test": "vitest --run",
|
|
16
16
|
"test:watch": "vitest",
|
|
17
17
|
"update": "npm install @sonicjs-cms/core@latest --save",
|
|
18
|
-
"update:beta": "npm install @sonicjs-cms/core@beta --save"
|
|
18
|
+
"update:beta": "npm install @sonicjs-cms/core@beta --save",
|
|
19
|
+
"update:plugin": "tsx scripts/update-plugin.ts"
|
|
19
20
|
},
|
|
20
21
|
"dependencies": {},
|
|
21
22
|
"devDependencies": {
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* update-plugin.ts
|
|
3
|
+
*
|
|
4
|
+
* Downloads the latest version of a bundled plugin from the SonicJS starter
|
|
5
|
+
* template on GitHub and overwrites the local copies.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* npx tsx scripts/update-plugin.ts [plugin-name]
|
|
9
|
+
* npx tsx scripts/update-plugin.ts example # default
|
|
10
|
+
* npx tsx scripts/update-plugin.ts example --dry-run
|
|
11
|
+
*
|
|
12
|
+
* Why this exists:
|
|
13
|
+
* `create-sonicjs` scaffolds plugin source files into your project — they are
|
|
14
|
+
* your code, not a package dependency. Running `npm install` updates
|
|
15
|
+
* @sonicjs-cms/core but leaves the plugin files untouched. This script pulls
|
|
16
|
+
* the latest files from the canonical starter template on GitHub main and
|
|
17
|
+
* overwrites your local copies, giving you bug fixes and improvements without
|
|
18
|
+
* starting a fresh project.
|
|
19
|
+
*
|
|
20
|
+
* Caution:
|
|
21
|
+
* This overwrites the plugin files — commit or stash local changes first.
|
|
22
|
+
* Custom modifications you've made will be lost.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { writeFileSync, mkdirSync } from 'fs'
|
|
26
|
+
import { dirname, join } from 'path'
|
|
27
|
+
import { fileURLToPath } from 'url'
|
|
28
|
+
|
|
29
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
30
|
+
const PROJECT_ROOT = join(__dirname, '..')
|
|
31
|
+
|
|
32
|
+
const GITHUB_RAW_BASE =
|
|
33
|
+
'https://raw.githubusercontent.com/SonicJs-Org/sonicjs/main/packages/create-app/templates/starter/src/plugins'
|
|
34
|
+
|
|
35
|
+
// Map of plugin name → files relative to its plugin directory.
|
|
36
|
+
// Add new plugins here as they are added to the starter template.
|
|
37
|
+
const PLUGIN_MANIFEST: Record<string, string[]> = {
|
|
38
|
+
example: [
|
|
39
|
+
'index.ts',
|
|
40
|
+
'routes/api.ts',
|
|
41
|
+
'routes/admin.ts',
|
|
42
|
+
'collections/moods.collection.ts',
|
|
43
|
+
],
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function fetchText(url: string): Promise<string> {
|
|
47
|
+
const res = await fetch(url)
|
|
48
|
+
if (!res.ok) throw new Error(`HTTP ${res.status} fetching ${url}`)
|
|
49
|
+
return res.text()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function updatePlugin(pluginName: string, dryRun: boolean) {
|
|
53
|
+
const files = PLUGIN_MANIFEST[pluginName]
|
|
54
|
+
if (!files) {
|
|
55
|
+
console.error(
|
|
56
|
+
`Unknown plugin "${pluginName}". Available: ${Object.keys(PLUGIN_MANIFEST).join(', ')}`
|
|
57
|
+
)
|
|
58
|
+
process.exit(1)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
console.log(
|
|
62
|
+
`\n${dryRun ? '[dry-run] ' : ''}Updating plugin: ${pluginName} from SonicJS main branch\n`
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
for (const file of files) {
|
|
66
|
+
const url = `${GITHUB_RAW_BASE}/${pluginName}/${file}`
|
|
67
|
+
const localPath = join(PROJECT_ROOT, 'src', 'plugins', pluginName, file)
|
|
68
|
+
|
|
69
|
+
process.stdout.write(` fetching ${file} ... `)
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
const content = await fetchText(url)
|
|
73
|
+
if (!dryRun) {
|
|
74
|
+
mkdirSync(dirname(localPath), { recursive: true })
|
|
75
|
+
writeFileSync(localPath, content, 'utf8')
|
|
76
|
+
}
|
|
77
|
+
console.log('✓')
|
|
78
|
+
} catch (err) {
|
|
79
|
+
console.log('✗')
|
|
80
|
+
console.error(` Error: ${(err as Error).message}`)
|
|
81
|
+
process.exit(1)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
console.log(
|
|
86
|
+
`\n${dryRun ? '[dry-run] no files written — ' : ''}Done. ${files.length} file(s) updated.\n`
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
if (!dryRun) {
|
|
90
|
+
console.log('Next steps:')
|
|
91
|
+
console.log(' 1. Review the changes: git diff src/plugins/' + pluginName)
|
|
92
|
+
console.log(' 2. Run type check: npm run type-check')
|
|
93
|
+
console.log(' 3. Commit if happy: git add src/plugins/' + pluginName + ' && git commit -m "chore(plugins): update ' + pluginName + ' plugin"\n')
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const args = process.argv.slice(2)
|
|
98
|
+
const pluginName = args.find(a => !a.startsWith('--')) ?? 'example'
|
|
99
|
+
const dryRun = args.includes('--dry-run')
|
|
100
|
+
|
|
101
|
+
updatePlugin(pluginName, dryRun)
|