@xnoxs/flux-lang 3.4.2 → 3.4.4

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/src/self/pkg.js CHANGED
@@ -118,13 +118,11 @@ function cmdRemove(names, opts) {
118
118
  for (const name of names) {
119
119
  let found = false;
120
120
  if ((pkg.dependencies && pkg.dependencies[name])) {
121
- delete;
122
- pkg.dependencies[name];
121
+ delete pkg.dependencies[name];
123
122
  found = true;
124
123
  }
125
124
  if ((pkg.devDependencies && pkg.devDependencies[name])) {
126
- delete;
127
- pkg.devDependencies[name];
125
+ delete pkg.devDependencies[name];
128
126
  found = true;
129
127
  }
130
128
  if (found) {
@@ -285,4 +283,79 @@ function cmdPublish(opts) {
285
283
  info("Run: flux publish --registry <url> for a custom registry");
286
284
  console.log();
287
285
  }
288
- module.exports.cmdPublish = cmdPublish;
286
+ module.exports.cmdPublish = cmdPublish;
287
+
288
+ // ── flux upgrade [--check] ─────────────────────────────────────────────────
289
+ // Checks all dependencies in flux.json for newer versions and updates them.
290
+ // --check : dry-run, only show what would change without writing
291
+ async function cmdUpgrade(opts) {
292
+ const check = (opts && opts.check) || false;
293
+ const cwd = process.cwd();
294
+ const pkg = readPackage(cwd);
295
+ if (!pkg) { err('No flux.json found. Run: flux init'); return; }
296
+
297
+ const allDeps = Object.assign({}, pkg.dependencies || {}, pkg.devDependencies || {});
298
+ const names = Object.keys(allDeps);
299
+ if (names.length === 0) { info('No dependencies in flux.json'); return; }
300
+
301
+ console.log();
302
+ console.log(clr(C.cyan, ' Checking ' + names.length + ' package(s) for updates...\n'));
303
+
304
+ let updated = 0;
305
+ let upToDate = 0;
306
+ let failed = 0;
307
+
308
+ for (const name of names) {
309
+ const current = allDeps[name].replace(/^[\^~>=<\s]+/, '');
310
+ try {
311
+ const data = await fetchJson(REGISTRY_URL + '/' + name);
312
+ const latest = data['dist-tags'] && data['dist-tags'].latest;
313
+ if (!latest) { err(name + ' — could not resolve latest'); failed++; continue; }
314
+
315
+ const isDev = !!(pkg.devDependencies && pkg.devDependencies[name]);
316
+ const tag = isDev ? clr(C.blue, ' (dev)') : '';
317
+
318
+ if (current === latest) {
319
+ console.log(' ' + clr(C.gray, '✓') + ' ' + clr(C.bold, name) + clr(C.gray, '@' + current + ' — up to date') + tag);
320
+ upToDate++;
321
+ } else {
322
+ console.log(' ' + clr(C.yellow, '↑') + ' ' + clr(C.bold, name) + clr(C.gray, '@' + current) + ' → ' + clr(C.green, latest) + tag);
323
+ if (!check) {
324
+ if (isDev) {
325
+ if (!pkg.devDependencies) pkg.devDependencies = {};
326
+ pkg.devDependencies[name] = '^' + latest;
327
+ } else {
328
+ if (!pkg.dependencies) pkg.dependencies = {};
329
+ pkg.dependencies[name] = '^' + latest;
330
+ }
331
+ }
332
+ updated++;
333
+ }
334
+ } catch (e) {
335
+ err(name + ' — ' + e.message);
336
+ failed++;
337
+ }
338
+ }
339
+
340
+ console.log();
341
+ if (check) {
342
+ console.log(clr(C.cyan, ' Check mode: no changes written.'));
343
+ if (updated > 0) {
344
+ console.log(clr(C.yellow, ' ' + updated + ' update(s) available. Run: flux upgrade'));
345
+ } else {
346
+ console.log(clr(C.green, ' All packages are up to date.'));
347
+ }
348
+ } else {
349
+ if (updated > 0) {
350
+ const pkgPath = Path.join(cwd, 'flux.json');
351
+ Fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf8');
352
+ ok(updated + ' package(s) updated in flux.json');
353
+ info('Run: flux install to apply changes');
354
+ } else {
355
+ console.log(clr(C.green, ' ✓ All packages are already up to date.'));
356
+ }
357
+ if (failed > 0) info(failed + ' package(s) could not be checked');
358
+ }
359
+ console.log();
360
+ }
361
+ module.exports.cmdUpgrade = cmdUpgrade;