coursecode 0.1.43 ā 0.1.44
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/lib/upgrade.js +53 -1
- package/package.json +1 -1
- package/template/vite.config.js +2 -1
package/lib/upgrade.js
CHANGED
|
@@ -83,6 +83,36 @@ function copyFileWithBackup(src, dest) {
|
|
|
83
83
|
return { updated: true, backup: null };
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
export function addMissingRuntimeDependencies(projectPkg, templatePkg) {
|
|
87
|
+
const requiredDeps = templatePkg.dependencies || {};
|
|
88
|
+
const existingDeps = projectPkg.dependencies || {};
|
|
89
|
+
const existingDevDeps = projectPkg.devDependencies || {};
|
|
90
|
+
const added = [];
|
|
91
|
+
|
|
92
|
+
for (const [name, version] of Object.entries(requiredDeps)) {
|
|
93
|
+
if (existingDeps[name]) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
existingDeps[name] = existingDevDeps[name] || version;
|
|
98
|
+
delete existingDevDeps[name];
|
|
99
|
+
added.push(name);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (added.length > 0) {
|
|
103
|
+
projectPkg.dependencies = Object.fromEntries(
|
|
104
|
+
Object.entries(existingDeps).sort(([a], [b]) => a.localeCompare(b))
|
|
105
|
+
);
|
|
106
|
+
if (projectPkg.devDependencies) {
|
|
107
|
+
projectPkg.devDependencies = Object.fromEntries(
|
|
108
|
+
Object.entries(existingDevDeps).sort(([a], [b]) => a.localeCompare(b))
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return added;
|
|
114
|
+
}
|
|
115
|
+
|
|
86
116
|
export async function upgrade(options = {}) {
|
|
87
117
|
const cwd = process.cwd();
|
|
88
118
|
const rcPath = path.join(cwd, '.coursecoderc.json');
|
|
@@ -109,6 +139,7 @@ export async function upgrade(options = {}) {
|
|
|
109
139
|
// Get CLI version (this is the version we'll upgrade to)
|
|
110
140
|
const cliPkg = JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT, 'package.json'), 'utf-8'));
|
|
111
141
|
const targetVersion = cliPkg.version;
|
|
142
|
+
const templatePkg = JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT, 'template', 'package.json'), 'utf-8'));
|
|
112
143
|
|
|
113
144
|
console.log(`
|
|
114
145
|
š¦ CourseCode Upgrade
|
|
@@ -138,6 +169,7 @@ export async function upgrade(options = {}) {
|
|
|
138
169
|
- framework/ (replace entirely)
|
|
139
170
|
- schemas/ (replace entirely)
|
|
140
171
|
- lib/manifest/ (replace entirely)
|
|
172
|
+
- package.json (add missing runtime dependencies)
|
|
141
173
|
- .coursecoderc.json (update version)`;
|
|
142
174
|
|
|
143
175
|
if (options.configs) {
|
|
@@ -150,7 +182,6 @@ export async function upgrade(options = {}) {
|
|
|
150
182
|
|
|
151
183
|
Would NOT touch:
|
|
152
184
|
- course/ (your content)${!options.configs ? '\n - vite.config.js\n - eslint.config.js' : ''}
|
|
153
|
-
- package.json
|
|
154
185
|
- .env
|
|
155
186
|
`;
|
|
156
187
|
console.log(dryRunMsg);
|
|
@@ -231,6 +262,18 @@ export async function upgrade(options = {}) {
|
|
|
231
262
|
rcConfig.upgradedFrom = currentVersion;
|
|
232
263
|
fs.writeFileSync(rcPath, JSON.stringify(rcConfig, null, 2));
|
|
233
264
|
|
|
265
|
+
// Add any runtime dependencies introduced by the new framework while preserving
|
|
266
|
+
// the project's existing version ranges.
|
|
267
|
+
const pkgPath = path.join(cwd, 'package.json');
|
|
268
|
+
let addedRuntimeDeps = [];
|
|
269
|
+
if (fs.existsSync(pkgPath)) {
|
|
270
|
+
const projectPkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
271
|
+
addedRuntimeDeps = addMissingRuntimeDependencies(projectPkg, templatePkg);
|
|
272
|
+
if (addedRuntimeDeps.length > 0) {
|
|
273
|
+
fs.writeFileSync(pkgPath, JSON.stringify(projectPkg, null, 2) + '\n');
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
234
277
|
let successMsg = `
|
|
235
278
|
ā
Upgrade complete!
|
|
236
279
|
|
|
@@ -238,6 +281,15 @@ export async function upgrade(options = {}) {
|
|
|
238
281
|
|
|
239
282
|
Your course/ directory was not modified.`;
|
|
240
283
|
|
|
284
|
+
if (addedRuntimeDeps.length > 0) {
|
|
285
|
+
successMsg += `
|
|
286
|
+
|
|
287
|
+
Runtime dependencies added to package.json:
|
|
288
|
+
- ${addedRuntimeDeps.join('\n - ')}
|
|
289
|
+
|
|
290
|
+
Run npm install to update node_modules and your lockfile.`;
|
|
291
|
+
}
|
|
292
|
+
|
|
241
293
|
if (configUpdates.length > 0) {
|
|
242
294
|
successMsg += `
|
|
243
295
|
|
package/package.json
CHANGED
package/template/vite.config.js
CHANGED
|
@@ -190,6 +190,7 @@ function scanDistFiles() {
|
|
|
190
190
|
function scormPostBuild(isDev) {
|
|
191
191
|
return {
|
|
192
192
|
name: 'scorm-post-build',
|
|
193
|
+
enforce: 'post',
|
|
193
194
|
buildStart() {
|
|
194
195
|
if (isDev) console.log('šØ Building...');
|
|
195
196
|
},
|
|
@@ -251,7 +252,7 @@ function scormPostBuild(isDev) {
|
|
|
251
252
|
console.log('\nš¦ Creating external hosting package archives...');
|
|
252
253
|
await createExternalPackagesForClients({ rootDir: ROOT_DIR, config });
|
|
253
254
|
}
|
|
254
|
-
console.log('\n
|
|
255
|
+
console.log('\nā Package archive created');
|
|
255
256
|
} else {
|
|
256
257
|
console.log('ā
Build complete\n');
|
|
257
258
|
}
|