@xnoxs/flux-lang 4.0.4 → 4.0.5
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/dist/flux-cli.js +70 -79
- package/dist/flux.cjs.js +5621 -3764
- package/dist/flux.esm.js +5644 -3792
- package/dist/flux.min.js +361 -95
- package/package.json +1 -1
- package/src/self/bundler.flux +21 -16
- package/src/self/bundler.js +2 -19
- package/src/self/cli.flux +274 -220
- package/src/self/cli.js +39 -84
- package/src/self/config.flux +36 -28
- package/src/self/config.js +2 -13
- package/src/self/pkg.flux +39 -136
- package/src/self/pkg.js +5 -14
package/src/self/cli.js
CHANGED
|
@@ -1,42 +1,6 @@
|
|
|
1
|
-
/* compiled from src/self/cli.flux
|
|
1
|
+
/* compiled from src/self/cli.flux */
|
|
2
2
|
'use strict';
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
function find(arr, fn) { return arr.find(fn); }
|
|
6
|
-
|
|
7
|
-
function some(arr, fn) { return arr.some(fn); }
|
|
8
|
-
|
|
9
|
-
function join(arr, sep) { return arr.join(sep != null ? sep : ','); }
|
|
10
|
-
|
|
11
|
-
function clamp(val, min, max) {
|
|
12
|
-
return Math.min(Math.max(val, min), max);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function max(arr) {
|
|
16
|
-
if (arguments.length > 1) return Math.max.apply(null, arguments);
|
|
17
|
-
return Math.max.apply(null, arr);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function padStart(s, len, char) {
|
|
21
|
-
return String(s).padStart(len, char || ' ');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function padEnd(s, len, char) {
|
|
25
|
-
return String(s).padEnd(len, char || ' ');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function trim(s) { return String(s).trim(); }
|
|
29
|
-
|
|
30
|
-
function trimEnd(s) { return String(s).trimEnd(); }
|
|
31
|
-
|
|
32
|
-
function startsWith(s, prefix) { return String(s).startsWith(prefix); }
|
|
33
|
-
|
|
34
|
-
function endsWith(s, suffix) { return String(s).endsWith(suffix); }
|
|
35
|
-
|
|
36
|
-
function repeat(s, n) { return String(s).repeat(n); }
|
|
37
|
-
// ── end stdlib ──
|
|
38
|
-
|
|
39
|
-
// Generated by Flux Transpiler v3.2.0
|
|
3
|
+
// Generated by Flux Transpiler v3.5.3 (self-hosted)
|
|
40
4
|
"use strict";
|
|
41
5
|
|
|
42
6
|
const Fs = require("fs");
|
|
@@ -51,7 +15,7 @@ const { loadConfig } = require("./config");
|
|
|
51
15
|
const { cmdAdd, cmdRemove, cmdInstall, cmdList, cmdSearch, cmdInfo, cmdPublish } = require("./pkg");
|
|
52
16
|
const VERSION = (FLUX_VERSION ?? "3.0.0");
|
|
53
17
|
const STAGE = (FLUX_STAGE ?? "self-hosted");
|
|
54
|
-
const C = { reset: "
|
|
18
|
+
const C = { reset: "\\u001b[0m", bold: "\\u001b[1m", dim: "\\u001b[2m", red: "\\u001b[31m", green: "\\u001b[32m", yellow: "\\u001b[33m", blue: "\\u001b[34m", cyan: "\\u001b[36m", white: "\\u001b[37m", gray: "\\u001b[90m", magenta: "\\u001b[35m" };
|
|
55
19
|
const noColor = (process.env.NO_COLOR || !process.stdout.isTTY);
|
|
56
20
|
function clr(c, s) {
|
|
57
21
|
return (noColor ? s : ((c + s) + C.reset));
|
|
@@ -91,31 +55,19 @@ function showHelp() {
|
|
|
91
55
|
console.log(" flux <command> [options]\n");
|
|
92
56
|
console.log(bold("COMPILER:"));
|
|
93
57
|
const compilerCmds = [["compile <file.flux>", "Compile .flux → .js"], ["bundle <entry.flux>", "Bundle multi-file project into one .js"], ["run <file.flux>", "Compile and run a single-file script"], ["watch <file.flux>", "Watch for changes, auto-compile"], ["check <file.flux>", "Type-check and static analysis"]];
|
|
94
|
-
|
|
95
|
-
const [cmd, desc] = __item__;
|
|
96
|
-
console.log((((" " + green(("flux " + cmd).padEnd(36))) + " ") + gray(desc)));
|
|
97
|
-
}
|
|
58
|
+
compilerCmds.forEach((pair) => console.log((((" " + green(("flux " + pair[0]).padEnd(36))) + " ") + gray(pair[1]))));
|
|
98
59
|
console.log();
|
|
99
60
|
console.log(bold("TOOLING:"));
|
|
100
61
|
const toolCmds = [["lint <file.flux>", "Full lint: types + style + immutability"], ["fmt <file.flux>", "Format source code in-place"], ["test [dir]", "Run *.test.flux files"], ["repl", "Interactive REPL mode"], ["tokens <file.flux>", "Show lexer token list"], ["ast <file.flux>", "Show Abstract Syntax Tree (JSON)"]];
|
|
101
|
-
|
|
102
|
-
const [cmd, desc] = __item__;
|
|
103
|
-
console.log((((" " + green(("flux " + cmd).padEnd(36))) + " ") + gray(desc)));
|
|
104
|
-
}
|
|
62
|
+
toolCmds.forEach((pair) => console.log((((" " + green(("flux " + pair[0]).padEnd(36))) + " ") + gray(pair[1]))));
|
|
105
63
|
console.log();
|
|
106
64
|
console.log(bold("PACKAGE MANAGER:"));
|
|
107
65
|
const pkgCmds = [["init [name] [--template]", "Scaffold a new Flux project"], ["add <pkg[@version]>", "Add a dependency (npm install --save)"], ["remove <pkg>", "Remove a dependency (npm uninstall)"], ["install", "Install all dependencies (npm install)"], ["list", "List installed packages"], ["search <query>", "Search the npm registry"], ["info <pkg>", "Show package details"], ["publish", "Publish package to npm registry"]];
|
|
108
|
-
|
|
109
|
-
const [cmd, desc] = __item__;
|
|
110
|
-
console.log((((" " + cyan(("flux " + cmd).padEnd(36))) + " ") + gray(desc)));
|
|
111
|
-
}
|
|
66
|
+
pkgCmds.forEach((pair) => console.log((((" " + cyan(("flux " + pair[0]).padEnd(36))) + " ") + gray(pair[1]))));
|
|
112
67
|
console.log();
|
|
113
68
|
console.log(bold("SELF-HOSTED:"));
|
|
114
69
|
const selfCmds = [["self-hosted", "Show self-hosted compiler status"], ["self-hosted build", "Bootstrap: compile compiler with itself"], ["self-hosted verify", "Verify self-hosted output matches stage-0"]];
|
|
115
|
-
|
|
116
|
-
const [cmd, desc] = __item__;
|
|
117
|
-
console.log((((" " + yellow(("flux " + cmd).padEnd(36))) + " ") + gray(desc)));
|
|
118
|
-
}
|
|
70
|
+
selfCmds.forEach((pair) => console.log((((" " + yellow(("flux " + pair[0]).padEnd(36))) + " ") + gray(pair[1]))));
|
|
119
71
|
console.log();
|
|
120
72
|
console.log(bold("OPTIONS:"));
|
|
121
73
|
console.log(((" " + yellow("--out, -o <file> ")) + " Output file"));
|
|
@@ -818,91 +770,94 @@ function main() {
|
|
|
818
770
|
const { positional, opts } = parseArgs(process.argv);
|
|
819
771
|
const cmd = (positional[0] ?? "help");
|
|
820
772
|
if (cmd === "compile") {
|
|
821
|
-
|
|
773
|
+
cmdCompile(positional[1], opts);
|
|
822
774
|
}
|
|
823
775
|
else if (cmd === "run") {
|
|
824
|
-
|
|
776
|
+
cmdRun(positional[1], opts);
|
|
825
777
|
}
|
|
826
778
|
else if (cmd === "check") {
|
|
827
|
-
|
|
779
|
+
cmdCheck(positional.slice(1), opts);
|
|
828
780
|
}
|
|
829
781
|
else if (cmd === "fmt") {
|
|
830
|
-
|
|
782
|
+
cmdFmt(positional.slice(1), opts);
|
|
831
783
|
}
|
|
832
784
|
else if (cmd === "format") {
|
|
833
|
-
|
|
785
|
+
cmdFmt(positional.slice(1), opts);
|
|
834
786
|
}
|
|
835
787
|
else if (cmd === "lint") {
|
|
836
|
-
|
|
788
|
+
cmdLint(positional.slice(1), opts);
|
|
837
789
|
}
|
|
838
790
|
else if (cmd === "bundle") {
|
|
839
|
-
|
|
791
|
+
cmdBundle(positional[1], opts);
|
|
840
792
|
}
|
|
841
793
|
else if (cmd === "watch") {
|
|
842
|
-
|
|
794
|
+
cmdWatch(positional[1], opts);
|
|
843
795
|
}
|
|
844
796
|
else if (cmd === "tokens") {
|
|
845
|
-
|
|
797
|
+
cmdTokens(positional[1], opts);
|
|
846
798
|
}
|
|
847
799
|
else if (cmd === "ast") {
|
|
848
|
-
|
|
800
|
+
cmdAst(positional[1], opts);
|
|
849
801
|
}
|
|
850
802
|
else if (cmd === "repl") {
|
|
851
|
-
|
|
803
|
+
cmdRepl(opts);
|
|
804
|
+
}
|
|
805
|
+
else if (cmd === "test") {
|
|
806
|
+
runTests(positional.slice(1), opts);
|
|
852
807
|
}
|
|
853
808
|
else if (cmd === "init") {
|
|
854
|
-
|
|
809
|
+
cmdInit(positional[1], opts);
|
|
855
810
|
}
|
|
856
811
|
else if (cmd === "add") {
|
|
857
|
-
|
|
812
|
+
cmdAdd(positional.slice(1), opts);
|
|
858
813
|
}
|
|
859
814
|
else if (cmd === "remove") {
|
|
860
|
-
|
|
815
|
+
cmdRemove(positional.slice(1), opts);
|
|
861
816
|
}
|
|
862
817
|
else if (cmd === "rm") {
|
|
863
|
-
|
|
818
|
+
cmdRemove(positional.slice(1), opts);
|
|
864
819
|
}
|
|
865
820
|
else if (cmd === "install") {
|
|
866
|
-
|
|
821
|
+
cmdInstall(opts);
|
|
867
822
|
}
|
|
868
823
|
else if (cmd === "i") {
|
|
869
|
-
|
|
824
|
+
cmdInstall(opts);
|
|
870
825
|
}
|
|
871
826
|
else if (cmd === "list") {
|
|
872
|
-
|
|
827
|
+
cmdList(opts);
|
|
873
828
|
}
|
|
874
829
|
else if (cmd === "ls") {
|
|
875
|
-
|
|
830
|
+
cmdList(opts);
|
|
876
831
|
}
|
|
877
832
|
else if (cmd === "search") {
|
|
878
|
-
|
|
833
|
+
cmdSearch(positional[1], opts);
|
|
879
834
|
}
|
|
880
835
|
else if (cmd === "info") {
|
|
881
|
-
|
|
836
|
+
cmdInfo(positional[1], opts);
|
|
882
837
|
}
|
|
883
838
|
else if (cmd === "publish") {
|
|
884
|
-
|
|
839
|
+
cmdPublish(opts);
|
|
885
840
|
}
|
|
886
841
|
else if (cmd === "self-hosted") {
|
|
887
|
-
|
|
842
|
+
cmdSelfHosted(positional[1], opts);
|
|
888
843
|
}
|
|
889
844
|
else if (cmd === "version") {
|
|
890
|
-
|
|
845
|
+
cmdVersion(opts);
|
|
891
846
|
}
|
|
892
847
|
else if (cmd === "-v") {
|
|
893
|
-
|
|
848
|
+
cmdVersion(opts);
|
|
894
849
|
}
|
|
895
850
|
else if (cmd === "--version") {
|
|
896
|
-
|
|
851
|
+
cmdVersion(opts);
|
|
897
852
|
}
|
|
898
853
|
else if (cmd === "help") {
|
|
899
|
-
|
|
854
|
+
showHelp();
|
|
900
855
|
}
|
|
901
856
|
else if (cmd === "--help") {
|
|
902
|
-
|
|
857
|
+
showHelp();
|
|
903
858
|
}
|
|
904
859
|
else if (cmd === "-h") {
|
|
905
|
-
|
|
860
|
+
showHelp();
|
|
906
861
|
}
|
|
907
862
|
else {
|
|
908
863
|
console.error(red(("✗ Unknown command: " + cmd)));
|
package/src/self/config.flux
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
// Flux Self-Hosted Config Reader
|
|
3
3
|
// src/self/config.flux — written in Flux, compiled by stage-0
|
|
4
4
|
//
|
|
5
|
-
// Reads
|
|
6
|
-
// Config file
|
|
7
|
-
//
|
|
8
|
-
//
|
|
5
|
+
// Reads config from package.json ("flux" key) or flux.json fallback.
|
|
6
|
+
// Config file resolution order:
|
|
7
|
+
// 1. package.json → { "flux": { ... } } ← primary
|
|
8
|
+
// 2. flux.json ← legacy fallback
|
|
9
|
+
// 3. default config ← if none found
|
|
9
10
|
// ============================================================
|
|
10
11
|
|
|
11
12
|
import Fs from "fs"
|
|
@@ -24,7 +25,7 @@ export val DEFAULT_CONFIG = {
|
|
|
24
25
|
watch: false,
|
|
25
26
|
ignore: [],
|
|
26
27
|
selfHosted: false,
|
|
27
|
-
registry: "https://registry.
|
|
28
|
+
registry: "https://registry.npmjs.org",
|
|
28
29
|
pkg: {
|
|
29
30
|
name: "",
|
|
30
31
|
version: "1.0.0",
|
|
@@ -36,11 +37,22 @@ export val DEFAULT_CONFIG = {
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
// ── Load flux.json
|
|
40
|
+
// ── Load config (package.json "flux" key first, flux.json fallback) ──
|
|
40
41
|
export fn loadConfig(cwd_):
|
|
41
42
|
val cwd = cwd_ ?? process.cwd()
|
|
42
43
|
|
|
43
|
-
// Try
|
|
44
|
+
// 1. Try package.json → "flux" key (primary)
|
|
45
|
+
val pkgJsonPath = Path.join(cwd, "package.json")
|
|
46
|
+
if Fs.existsSync(pkgJsonPath):
|
|
47
|
+
try:
|
|
48
|
+
val raw = Fs.readFileSync(pkgJsonPath, "utf8")
|
|
49
|
+
val parsed = JSON.parse(raw)
|
|
50
|
+
if parsed.flux and typeof parsed.flux == "object":
|
|
51
|
+
return mergeConfig(DEFAULT_CONFIG, parsed.flux)
|
|
52
|
+
catch(e):
|
|
53
|
+
throw new Error("Invalid package.json: " + e.message)
|
|
54
|
+
|
|
55
|
+
// 2. Try flux.json (legacy fallback)
|
|
44
56
|
val jsonPath = Path.join(cwd, "flux.json")
|
|
45
57
|
if Fs.existsSync(jsonPath):
|
|
46
58
|
try:
|
|
@@ -50,15 +62,7 @@ export fn loadConfig(cwd_):
|
|
|
50
62
|
catch(e):
|
|
51
63
|
throw new Error("Invalid flux.json: " + e.message)
|
|
52
64
|
|
|
53
|
-
//
|
|
54
|
-
val jsPath = Path.join(cwd, "flux.config.js")
|
|
55
|
-
if Fs.existsSync(jsPath):
|
|
56
|
-
try:
|
|
57
|
-
val loaded = require(jsPath)
|
|
58
|
-
return mergeConfig(DEFAULT_CONFIG, loaded)
|
|
59
|
-
catch(e2):
|
|
60
|
-
throw new Error("Invalid flux.config.js: " + e2.message)
|
|
61
|
-
|
|
65
|
+
// 3. Default config
|
|
62
66
|
return { ...DEFAULT_CONFIG }
|
|
63
67
|
|
|
64
68
|
// ── Deep merge config objects ─────────────────────────────────
|
|
@@ -71,12 +75,16 @@ export fn mergeConfig(base, overrides):
|
|
|
71
75
|
result[key] = val_
|
|
72
76
|
return result
|
|
73
77
|
|
|
74
|
-
// ── Write flux.json
|
|
78
|
+
// ── Write flux key into package.json ─────────────────────────
|
|
75
79
|
export fn writeConfig(config, cwd_):
|
|
76
|
-
val cwd
|
|
77
|
-
val
|
|
78
|
-
|
|
79
|
-
Fs.
|
|
80
|
+
val cwd = cwd_ ?? process.cwd()
|
|
81
|
+
val pkgPath = Path.join(cwd, "package.json")
|
|
82
|
+
var pkg = {}
|
|
83
|
+
if Fs.existsSync(pkgPath):
|
|
84
|
+
try: pkg = JSON.parse(Fs.readFileSync(pkgPath, "utf8"))
|
|
85
|
+
catch(e): pkg = {}
|
|
86
|
+
pkg.flux = config
|
|
87
|
+
Fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8")
|
|
80
88
|
|
|
81
89
|
// ── Validate config ───────────────────────────────────────────
|
|
82
90
|
export fn validateConfig(config):
|
|
@@ -93,20 +101,20 @@ export fn validateConfig(config):
|
|
|
93
101
|
errors: errors,
|
|
94
102
|
}
|
|
95
103
|
|
|
96
|
-
// ── Read flux.json
|
|
104
|
+
// ── Read package info (package.json first, flux.json fallback) ────
|
|
97
105
|
export fn readPackage(cwd_):
|
|
98
|
-
val cwd
|
|
106
|
+
val cwd = cwd_ ?? process.cwd()
|
|
107
|
+
val pkgJson = Path.join(cwd, "package.json")
|
|
99
108
|
val fluxJson = Path.join(cwd, "flux.json")
|
|
100
|
-
val pkgJson = Path.join(cwd, "package.json")
|
|
101
109
|
|
|
102
|
-
if Fs.existsSync(
|
|
110
|
+
if Fs.existsSync(pkgJson):
|
|
103
111
|
try:
|
|
104
|
-
return JSON.parse(Fs.readFileSync(
|
|
112
|
+
return JSON.parse(Fs.readFileSync(pkgJson, "utf8"))
|
|
105
113
|
catch(e): return null
|
|
106
114
|
|
|
107
|
-
if Fs.existsSync(
|
|
115
|
+
if Fs.existsSync(fluxJson):
|
|
108
116
|
try:
|
|
109
|
-
return JSON.parse(Fs.readFileSync(
|
|
117
|
+
return JSON.parse(Fs.readFileSync(fluxJson, "utf8"))
|
|
110
118
|
catch(e2): return null
|
|
111
119
|
|
|
112
120
|
return null
|
package/src/self/config.js
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
/* compiled from src/self/config.flux
|
|
1
|
+
/* compiled from src/self/config.flux */
|
|
2
2
|
'use strict';
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
function join(arr, sep) { return arr.join(sep != null ? sep : ','); }
|
|
6
|
-
|
|
7
|
-
function includes(arr, val) { return arr.includes(val); }
|
|
8
|
-
|
|
9
|
-
function keys(obj) { return Object.keys(obj); }
|
|
10
|
-
|
|
11
|
-
function endsWith(s, suffix) { return String(s).endsWith(suffix); }
|
|
12
|
-
// ── end stdlib ──
|
|
13
|
-
|
|
14
|
-
// Generated by Flux Transpiler v3.2.0
|
|
3
|
+
// Generated by Flux Transpiler v3.5.3 (self-hosted)
|
|
15
4
|
"use strict";
|
|
16
5
|
|
|
17
6
|
const Fs = require("fs");
|
package/src/self/pkg.flux
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
// src/self/pkg.flux — written in Flux, compiled by stage-0
|
|
4
4
|
//
|
|
5
5
|
// Commands:
|
|
6
|
-
// flux add <pkg[@version]> install a
|
|
7
|
-
// flux remove <pkg> remove a package
|
|
8
|
-
// flux install install all from
|
|
6
|
+
// flux add <pkg[@version]> install a package (npm install --save)
|
|
7
|
+
// flux remove <pkg> remove a package (npm uninstall)
|
|
8
|
+
// flux install install all from package.json (npm install)
|
|
9
9
|
// flux list list installed packages
|
|
10
|
-
// flux search <query> search the registry
|
|
10
|
+
// flux search <query> search the npm registry
|
|
11
11
|
// flux publish publish to registry
|
|
12
12
|
// flux info <pkg> show package info
|
|
13
13
|
// ============================================================
|
|
@@ -17,11 +17,9 @@ import Path from "path"
|
|
|
17
17
|
import Https from "https"
|
|
18
18
|
import Http from "http"
|
|
19
19
|
import Os from "os"
|
|
20
|
-
import { readPackage
|
|
20
|
+
import { readPackage } from "./config"
|
|
21
21
|
|
|
22
22
|
val REGISTRY_URL = "https://registry.npmjs.org"
|
|
23
|
-
val FLUX_PKG_DIR = "flux_modules"
|
|
24
|
-
val PKG_FILE = "flux.json"
|
|
25
23
|
|
|
26
24
|
// ── ANSI colors ───────────────────────────────────────────────
|
|
27
25
|
val ESC = "\u001b"
|
|
@@ -77,36 +75,6 @@ async fn fetchJson(url):
|
|
|
77
75
|
mod.get(url, { headers: { "User-Agent": "flux-pkg/1.0" } }, onRes).on("error", reject)
|
|
78
76
|
return new Promise(doRequest)
|
|
79
77
|
|
|
80
|
-
// ── Ensure flux.json exists ───────────────────────────────────
|
|
81
|
-
fn ensureFluxJson(cwd_):
|
|
82
|
-
val cwd = cwd_ ?? process.cwd()
|
|
83
|
-
val file = Path.join(cwd, PKG_FILE)
|
|
84
|
-
if not Fs.existsSync(file):
|
|
85
|
-
val pkg = {
|
|
86
|
-
name: Path.basename(cwd),
|
|
87
|
-
version: "1.0.0",
|
|
88
|
-
description: "",
|
|
89
|
-
author: "",
|
|
90
|
-
license: "MIT",
|
|
91
|
-
scripts: {
|
|
92
|
-
start: "flux run src/main.flux",
|
|
93
|
-
build: "flux bundle src/main.flux -o dist/bundle.js",
|
|
94
|
-
dev: "flux watch src/main.flux",
|
|
95
|
-
check: "flux check src/main.flux",
|
|
96
|
-
},
|
|
97
|
-
dependencies: {},
|
|
98
|
-
devDependencies: {},
|
|
99
|
-
}
|
|
100
|
-
Fs.writeFileSync(file, JSON.stringify(pkg, null, 2) + "\n", "utf8")
|
|
101
|
-
ok("Created flux.json")
|
|
102
|
-
return JSON.parse(Fs.readFileSync(file, "utf8"))
|
|
103
|
-
|
|
104
|
-
// ── Save flux.json ────────────────────────────────────────────
|
|
105
|
-
fn saveFluxJson(pkg, cwd_):
|
|
106
|
-
val cwd = cwd_ ?? process.cwd()
|
|
107
|
-
val file = Path.join(cwd, PKG_FILE)
|
|
108
|
-
Fs.writeFileSync(file, JSON.stringify(pkg, null, 2) + "\n", "utf8")
|
|
109
|
-
|
|
110
78
|
// ── Resolve package name@version ─────────────────────────────
|
|
111
79
|
fn parsePackageSpec(spec):
|
|
112
80
|
val atIdx = spec.lastIndexOf("@")
|
|
@@ -115,124 +83,63 @@ fn parsePackageSpec(spec):
|
|
|
115
83
|
return { name: spec, version: "latest" }
|
|
116
84
|
|
|
117
85
|
// ── flux add <pkg[@version]> [--dev] ─────────────────────────
|
|
86
|
+
// Equivalent to: npm install <pkg> --save (or --save-dev)
|
|
118
87
|
export async fn cmdAdd(specs, opts):
|
|
88
|
+
import { execSync } from "child_process"
|
|
119
89
|
val isDev = opts?.dev ?? false
|
|
120
90
|
val cwd = process.cwd()
|
|
121
|
-
val pkg = ensureFluxJson(cwd)
|
|
122
91
|
|
|
123
92
|
for spec in specs:
|
|
124
93
|
val { name, version } = parsePackageSpec(spec)
|
|
125
|
-
val spinner = startSpinner("
|
|
94
|
+
val spinner = startSpinner("Adding " + clr(C.bold, name) + clr(C.gray, "@" + version) + " ...")
|
|
126
95
|
|
|
127
96
|
try:
|
|
128
|
-
val
|
|
129
|
-
val
|
|
130
|
-
|
|
131
|
-
val versionInfo = info_.versions?.[resolvedVersion]
|
|
97
|
+
val saveFlag = isDev ? "--save-dev" : "--save"
|
|
98
|
+
val pkgSpec = version == "latest" ? name : name + "@" + version
|
|
132
99
|
stopSpinner(spinner)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
val depKey = isDev ? "devDependencies" : "dependencies"
|
|
138
|
-
if not pkg[depKey]: pkg[depKey] = {}
|
|
139
|
-
pkg[depKey][name] = "^" + resolvedVersion
|
|
140
|
-
|
|
141
|
-
saveFluxJson(pkg, cwd)
|
|
142
|
-
|
|
143
|
-
val desc = versionInfo.description ? clr(C.gray, " — " + versionInfo.description) : ""
|
|
144
|
-
ok(name + clr(C.green, "@" + resolvedVersion) + desc)
|
|
145
|
-
info("Added to " + (isDev ? "devDependencies" : "dependencies"))
|
|
146
|
-
|
|
100
|
+
console.log(clr(C.cyan, " Adding ") + clr(C.bold, pkgSpec) + clr(C.gray, " to node_modules/ and package.json..."))
|
|
101
|
+
execSync("npm install " + pkgSpec + " " + saveFlag, { cwd, stdio: "inherit" })
|
|
102
|
+
ok("Added " + clr(C.bold, name) + " to node_modules/ and package.json")
|
|
147
103
|
catch(e):
|
|
148
104
|
stopSpinner(spinner)
|
|
149
|
-
err("Failed to
|
|
105
|
+
err("Failed to add " + name + ": " + e.message)
|
|
150
106
|
|
|
151
107
|
console.log()
|
|
152
|
-
console.log(clr(C.gray, " Run ") + clr(C.yellow, "flux install") + clr(C.gray, " to install packages"))
|
|
153
|
-
console.log()
|
|
154
108
|
|
|
155
109
|
// ── flux remove <pkg> ─────────────────────────────────────────
|
|
110
|
+
// Equivalent to: npm uninstall <pkg>
|
|
156
111
|
export fn cmdRemove(names, opts):
|
|
112
|
+
import { execSync } from "child_process"
|
|
157
113
|
val cwd = process.cwd()
|
|
158
|
-
val pkg = ensureFluxJson(cwd)
|
|
159
|
-
var removed = 0
|
|
160
114
|
|
|
161
115
|
for name in names:
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
found = true
|
|
166
|
-
if pkg.devDependencies and pkg.devDependencies[name]:
|
|
167
|
-
delete pkg.devDependencies[name]
|
|
168
|
-
found = true
|
|
169
|
-
|
|
170
|
-
if found:
|
|
116
|
+
try:
|
|
117
|
+
console.log(clr(C.cyan, " Removing ") + clr(C.bold, name) + " ...")
|
|
118
|
+
execSync("npm uninstall " + name, { cwd, stdio: "inherit" })
|
|
171
119
|
ok("Removed " + clr(C.bold, name))
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
err(name + " not found in flux.json")
|
|
175
|
-
|
|
176
|
-
if removed > 0:
|
|
177
|
-
saveFluxJson(pkg, cwd)
|
|
120
|
+
catch(e):
|
|
121
|
+
err("Failed to remove " + name + ": " + e.message)
|
|
178
122
|
|
|
179
123
|
// ── flux install ──────────────────────────────────────────────
|
|
124
|
+
// Equivalent to: npm install (reads package.json)
|
|
180
125
|
export async fn cmdInstall(opts):
|
|
181
126
|
import { execSync } from "child_process"
|
|
127
|
+
val cwd = process.cwd()
|
|
182
128
|
|
|
183
|
-
val
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
val deps = pkg.dependencies ?? {}
|
|
188
|
-
val devDeps = pkg.devDependencies ?? {}
|
|
189
|
-
val all = { ...deps, ...devDeps }
|
|
190
|
-
val names = Object.keys(all)
|
|
191
|
-
|
|
192
|
-
if names.length == 0:
|
|
193
|
-
info("No dependencies found in flux.json")
|
|
129
|
+
val pkgJsonPath = Path.join(cwd, "package.json")
|
|
130
|
+
if not Fs.existsSync(pkgJsonPath):
|
|
131
|
+
err("No package.json found. Run: flux init")
|
|
194
132
|
return
|
|
195
133
|
|
|
196
|
-
console.log(clr(C.cyan, "\n Installing
|
|
197
|
-
|
|
198
|
-
for name in names:
|
|
199
|
-
val spec = all[name]
|
|
200
|
-
console.log(clr(C.gray, " ○ ") + name + clr(C.gray, "@" + spec))
|
|
201
|
-
|
|
202
|
-
console.log()
|
|
203
|
-
|
|
204
|
-
// Ensure flux_modules/ exists with a minimal package.json
|
|
205
|
-
if not Fs.existsSync(fluxModDir):
|
|
206
|
-
Fs.mkdirSync(fluxModDir, { recursive: true })
|
|
207
|
-
|
|
208
|
-
val fluxPkgFile = Path.join(fluxModDir, "package.json")
|
|
209
|
-
if not Fs.existsSync(fluxPkgFile):
|
|
210
|
-
val fluxPkg = { name: pkg.name + "-flux-modules", version: "1.0.0", private: true }
|
|
211
|
-
Fs.writeFileSync(fluxPkgFile, JSON.stringify(fluxPkg, null, 2) + "\n", "utf8")
|
|
212
|
-
|
|
213
|
-
val prodNames = Object.keys(deps)
|
|
214
|
-
val devNames = Object.keys(devDeps)
|
|
215
|
-
|
|
134
|
+
console.log(clr(C.cyan, "\n Installing dependencies from package.json...\n"))
|
|
216
135
|
try:
|
|
217
|
-
|
|
218
|
-
val prodPkgs = prodNames.map(n -> n + "@" + (deps[n] ?? "latest")).join(" ")
|
|
219
|
-
val installCmd = "npm install --prefix " + fluxModDir + " " + prodPkgs
|
|
220
|
-
info("Running: " + installCmd)
|
|
221
|
-
execSync(installCmd, { cwd: cwd, stdio: "inherit" })
|
|
222
|
-
|
|
223
|
-
if devNames.length > 0:
|
|
224
|
-
val devPkgs = devNames.map(n -> n + "@" + (devDeps[n] ?? "latest")).join(" ")
|
|
225
|
-
val devCmd = "npm install --prefix " + fluxModDir + " --save-dev " + devPkgs
|
|
226
|
-
info("Running: " + devCmd)
|
|
227
|
-
execSync(devCmd, { cwd: cwd, stdio: "inherit" })
|
|
228
|
-
|
|
136
|
+
execSync("npm install", { cwd, stdio: "inherit" })
|
|
229
137
|
console.log()
|
|
230
|
-
ok(
|
|
231
|
-
info("Packages resolve automatically when using: flux run, flux bundle")
|
|
138
|
+
ok("Dependencies installed into node_modules/")
|
|
232
139
|
catch(e):
|
|
233
140
|
console.log()
|
|
234
141
|
err("Install failed: " + e.message)
|
|
235
|
-
info("Try manually: npm install
|
|
142
|
+
info("Try manually: npm install")
|
|
236
143
|
|
|
237
144
|
console.log()
|
|
238
145
|
|
|
@@ -242,7 +149,7 @@ export fn cmdList(opts):
|
|
|
242
149
|
val pkg = readPackage(cwd)
|
|
243
150
|
|
|
244
151
|
if not pkg:
|
|
245
|
-
err("No
|
|
152
|
+
err("No package.json found. Run: flux init")
|
|
246
153
|
return
|
|
247
154
|
|
|
248
155
|
console.log()
|
|
@@ -325,12 +232,13 @@ export async fn cmdInfo(name, opts):
|
|
|
325
232
|
|
|
326
233
|
// ── flux upgrade [--check] ────────────────────────────────────
|
|
327
234
|
export async fn cmdUpgrade(opts):
|
|
235
|
+
import { execSync } from "child_process"
|
|
328
236
|
val isCheck = opts?.check ?? false
|
|
329
237
|
val cwd = process.cwd()
|
|
330
238
|
val pkg = readPackage(cwd)
|
|
331
239
|
|
|
332
240
|
if not pkg:
|
|
333
|
-
err("No
|
|
241
|
+
err("No package.json found. Run: flux init")
|
|
334
242
|
return
|
|
335
243
|
|
|
336
244
|
val deps = pkg.dependencies ?? {}
|
|
@@ -371,11 +279,9 @@ export async fn cmdUpgrade(opts):
|
|
|
371
279
|
if isCheck:
|
|
372
280
|
console.log(" " + clr(C.yellow, "↑ ") + clr(C.bold, name) + clr(C.gray, " " + current + " → ") + clr(C.green, "^" + latest))
|
|
373
281
|
else:
|
|
374
|
-
val isDev = devDeps[name] != null
|
|
375
|
-
val depKey = isDev ? "devDependencies" : "dependencies"
|
|
376
|
-
pkg[depKey][name] = "^" + latest
|
|
377
282
|
updated = updated + 1
|
|
378
283
|
console.log(" " + clr(C.green, "✓ ") + clr(C.bold, name) + clr(C.gray, " " + current + " → ") + clr(C.green, "^" + latest))
|
|
284
|
+
execSync("npm install " + name + "@" + latest + " --save", { cwd, stdio: "pipe" })
|
|
379
285
|
|
|
380
286
|
catch(e):
|
|
381
287
|
stopSpinner(spinner)
|
|
@@ -393,9 +299,7 @@ export async fn cmdUpgrade(opts):
|
|
|
393
299
|
if updated == 0:
|
|
394
300
|
ok("All packages are already up to date")
|
|
395
301
|
else:
|
|
396
|
-
|
|
397
|
-
ok(updated + " package(s) updated in flux.json")
|
|
398
|
-
console.log(clr(C.gray, " Run ") + clr(C.yellow, "flux install") + clr(C.gray, " to install updated versions"))
|
|
302
|
+
ok(updated + " package(s) updated in node_modules/ and package.json")
|
|
399
303
|
|
|
400
304
|
console.log()
|
|
401
305
|
|
|
@@ -405,21 +309,20 @@ export fn cmdPublish(opts):
|
|
|
405
309
|
val pkg = readPackage(cwd)
|
|
406
310
|
|
|
407
311
|
if not pkg:
|
|
408
|
-
err("No
|
|
312
|
+
err("No package.json found. Run: flux init")
|
|
409
313
|
return
|
|
410
314
|
|
|
411
315
|
console.log()
|
|
412
316
|
console.log(clr(C.cyan, " Publishing ") + clr(C.bold, pkg.name + "@" + pkg.version) + " ...")
|
|
413
317
|
console.log()
|
|
414
|
-
info("
|
|
415
|
-
info("Checking flux.json...")
|
|
318
|
+
info("Checking package.json...")
|
|
416
319
|
|
|
417
320
|
if not pkg.name:
|
|
418
|
-
err("
|
|
321
|
+
err("package.json must have a name field")
|
|
419
322
|
return
|
|
420
323
|
|
|
421
324
|
if not pkg.version:
|
|
422
|
-
err("
|
|
325
|
+
err("package.json must have a version field")
|
|
423
326
|
return
|
|
424
327
|
|
|
425
328
|
console.log()
|