@xnoxs/flux-lang 4.0.3 → 4.0.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/dist/flux-cli.js +4996 -8159
- package/dist/flux.cjs.js +3763 -5620
- package/dist/flux.esm.js +3767 -5619
- package/dist/flux.min.js +95 -361
- package/index.js +9 -10
- package/package.json +4 -5
- package/src/self/bundler.js +202 -1
- package/src/self/cli.js +116 -43
- package/src/self/config.js +33 -19
- package/src/self/pkg.js +33 -111
package/src/self/pkg.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
/* compiled from src/self/pkg.flux by Flux Lang */
|
|
2
|
+
'use strict';
|
|
1
3
|
// ── Flux stdlib ──
|
|
2
4
|
|
|
3
|
-
function map(arr, fn) { return arr.map(fn); }
|
|
4
|
-
|
|
5
5
|
function join(arr, sep) { return arr.join(sep != null ? sep : ','); }
|
|
6
6
|
|
|
7
7
|
function keys(obj) { return Object.keys(obj); }
|
|
@@ -17,10 +17,8 @@ const Path = require("path");
|
|
|
17
17
|
const Https = require("https");
|
|
18
18
|
const Http = require("http");
|
|
19
19
|
const Os = require("os");
|
|
20
|
-
const { readPackage
|
|
20
|
+
const { readPackage } = require("./config");
|
|
21
21
|
const REGISTRY_URL = "https://registry.npmjs.org";
|
|
22
|
-
const FLUX_PKG_DIR = "flux_modules";
|
|
23
|
-
const PKG_FILE = "flux.json";
|
|
24
22
|
const ESC = "\u001b";
|
|
25
23
|
const C = { reset: (ESC + "[0m"), bold: (ESC + "[1m"), dim: (ESC + "[2m"), red: (ESC + "[31m"), green: (ESC + "[32m"), yellow: (ESC + "[33m"), blue: (ESC + "[34m"), cyan: (ESC + "[36m"), gray: (ESC + "[90m") };
|
|
26
24
|
function clr(c, s) {
|
|
@@ -79,21 +77,6 @@ async function fetchJson(url) {
|
|
|
79
77
|
}
|
|
80
78
|
return new Promise(doRequest);
|
|
81
79
|
}
|
|
82
|
-
function ensureFluxJson(cwd_) {
|
|
83
|
-
const cwd = (cwd_ ?? process.cwd());
|
|
84
|
-
const file = Path.join(cwd, PKG_FILE);
|
|
85
|
-
if (!Fs.existsSync(file)) {
|
|
86
|
-
const pkg = { name: Path.basename(cwd), version: "1.0.0", description: "", author: "", license: "MIT", scripts: { start: "flux run src/main.flux", build: "flux bundle src/main.flux -o dist/bundle.js", dev: "flux watch src/main.flux", check: "flux check src/main.flux" }, dependencies: { }, devDependencies: { } };
|
|
87
|
-
Fs.writeFileSync(file, (JSON.stringify(pkg, null, 2) + "\n"), "utf8");
|
|
88
|
-
ok("Created flux.json");
|
|
89
|
-
}
|
|
90
|
-
return JSON.parse(Fs.readFileSync(file, "utf8"));
|
|
91
|
-
}
|
|
92
|
-
function saveFluxJson(pkg, cwd_) {
|
|
93
|
-
const cwd = (cwd_ ?? process.cwd());
|
|
94
|
-
const file = Path.join(cwd, PKG_FILE);
|
|
95
|
-
Fs.writeFileSync(file, (JSON.stringify(pkg, null, 2) + "\n"), "utf8");
|
|
96
|
-
}
|
|
97
80
|
function parsePackageSpec(spec) {
|
|
98
81
|
const atIdx = spec.lastIndexOf("@");
|
|
99
82
|
if ((atIdx > 0)) {
|
|
@@ -102,118 +85,61 @@ function parsePackageSpec(spec) {
|
|
|
102
85
|
return { name: spec, version: "latest" };
|
|
103
86
|
}
|
|
104
87
|
async function cmdAdd(specs, opts) {
|
|
88
|
+
const { execSync } = require("child_process");
|
|
105
89
|
const isDev = (opts?.dev ?? false);
|
|
106
90
|
const cwd = process.cwd();
|
|
107
|
-
const pkg = ensureFluxJson(cwd);
|
|
108
91
|
for (const spec of specs) {
|
|
109
92
|
const { name, version } = parsePackageSpec(spec);
|
|
110
|
-
const spinner = startSpinner(((("
|
|
93
|
+
const spinner = startSpinner(((("Adding " + clr(C.bold, name)) + clr(C.gray, ("@" + version))) + " ..."));
|
|
111
94
|
try {
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
const versionInfo = info_.versions?.[resolvedVersion];
|
|
95
|
+
const saveFlag = (isDev ? "--save-dev" : "--save");
|
|
96
|
+
const pkgSpec = ((version == "latest") ? name : ((name + "@") + version));
|
|
115
97
|
stopSpinner(spinner);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
const depKey = (isDev ? "devDependencies" : "dependencies");
|
|
121
|
-
if (!pkg[depKey]) {
|
|
122
|
-
pkg[depKey] = { };
|
|
123
|
-
}
|
|
124
|
-
pkg[depKey][name] = ("^" + resolvedVersion);
|
|
125
|
-
saveFluxJson(pkg, cwd);
|
|
126
|
-
const desc = (versionInfo.description ? clr(C.gray, (" — " + versionInfo.description)) : "");
|
|
127
|
-
ok(((name + clr(C.green, ("@" + resolvedVersion))) + desc));
|
|
128
|
-
info(("Added to " + (isDev ? "devDependencies" : "dependencies")));
|
|
98
|
+
console.log(((clr(C.cyan, " Adding ") + clr(C.bold, pkgSpec)) + clr(C.gray, " to node_modules/ and package.json...")));
|
|
99
|
+
execSync(((("npm install " + pkgSpec) + " ") + saveFlag), { cwd, stdio: "inherit" });
|
|
100
|
+
ok((("Added " + clr(C.bold, name)) + " to node_modules/ and package.json"));
|
|
129
101
|
}
|
|
130
102
|
catch (e) {
|
|
131
103
|
stopSpinner(spinner);
|
|
132
|
-
err(((("Failed to
|
|
104
|
+
err(((("Failed to add " + name) + ": ") + e.message));
|
|
133
105
|
}
|
|
134
106
|
}
|
|
135
107
|
console.log();
|
|
136
|
-
console.log(((clr(C.gray, " Run ") + clr(C.yellow, "flux install")) + clr(C.gray, " to install packages")));
|
|
137
|
-
console.log();
|
|
138
108
|
}
|
|
139
109
|
module.exports.cmdAdd = cmdAdd;
|
|
140
110
|
function cmdRemove(names, opts) {
|
|
111
|
+
const { execSync } = require("child_process");
|
|
141
112
|
const cwd = process.cwd();
|
|
142
|
-
const pkg = ensureFluxJson(cwd);
|
|
143
|
-
let removed = 0;
|
|
144
113
|
for (const name of names) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
found = true;
|
|
149
|
-
}
|
|
150
|
-
if ((pkg.devDependencies && pkg.devDependencies[name])) {
|
|
151
|
-
delete pkg.devDependencies[name];
|
|
152
|
-
found = true;
|
|
153
|
-
}
|
|
154
|
-
if (found) {
|
|
114
|
+
try {
|
|
115
|
+
console.log(((clr(C.cyan, " Removing ") + clr(C.bold, name)) + " ..."));
|
|
116
|
+
execSync(("npm uninstall " + name), { cwd, stdio: "inherit" });
|
|
155
117
|
ok(("Removed " + clr(C.bold, name)));
|
|
156
|
-
removed = (removed + 1);
|
|
157
118
|
}
|
|
158
|
-
|
|
159
|
-
err((name + "
|
|
119
|
+
catch (e) {
|
|
120
|
+
err(((("Failed to remove " + name) + ": ") + e.message));
|
|
160
121
|
}
|
|
161
122
|
}
|
|
162
|
-
if ((removed > 0)) {
|
|
163
|
-
saveFluxJson(pkg, cwd);
|
|
164
|
-
}
|
|
165
123
|
}
|
|
166
124
|
module.exports.cmdRemove = cmdRemove;
|
|
167
125
|
async function cmdInstall(opts) {
|
|
168
126
|
const { execSync } = require("child_process");
|
|
169
127
|
const cwd = process.cwd();
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const devDeps = (pkg.devDependencies ?? { });
|
|
174
|
-
const all = { ...deps, ...devDeps };
|
|
175
|
-
const names = Object.keys(all);
|
|
176
|
-
if ((names.length == 0)) {
|
|
177
|
-
info("No dependencies found in flux.json");
|
|
128
|
+
const pkgJsonPath = Path.join(cwd, "package.json");
|
|
129
|
+
if (!Fs.existsSync(pkgJsonPath)) {
|
|
130
|
+
err("No package.json found. Run: flux init");
|
|
178
131
|
return;
|
|
179
132
|
}
|
|
180
|
-
console.log(
|
|
181
|
-
for (const name of names) {
|
|
182
|
-
const spec = all[name];
|
|
183
|
-
console.log(((clr(C.gray, " ○ ") + name) + clr(C.gray, ("@" + spec))));
|
|
184
|
-
}
|
|
185
|
-
console.log();
|
|
186
|
-
if (!Fs.existsSync(fluxModDir)) {
|
|
187
|
-
Fs.mkdirSync(fluxModDir, { recursive: true });
|
|
188
|
-
}
|
|
189
|
-
const fluxPkgFile = Path.join(fluxModDir, "package.json");
|
|
190
|
-
if (!Fs.existsSync(fluxPkgFile)) {
|
|
191
|
-
const fluxPkg = { name: (pkg.name + "-flux-modules"), version: "1.0.0", private: true };
|
|
192
|
-
Fs.writeFileSync(fluxPkgFile, (JSON.stringify(fluxPkg, null, 2) + "\n"), "utf8");
|
|
193
|
-
}
|
|
194
|
-
const prodNames = Object.keys(deps);
|
|
195
|
-
const devNames = Object.keys(devDeps);
|
|
133
|
+
console.log(clr(C.cyan, "\n Installing dependencies from package.json...\n"));
|
|
196
134
|
try {
|
|
197
|
-
|
|
198
|
-
const prodPkgs = prodNames.map((n) => ((n + "@") + (deps[n] ?? "latest"))).join(" ");
|
|
199
|
-
const installCmd = ((("npm install --prefix " + fluxModDir) + " ") + prodPkgs);
|
|
200
|
-
info(("Running: " + installCmd));
|
|
201
|
-
execSync(installCmd, { cwd, stdio: "inherit" });
|
|
202
|
-
}
|
|
203
|
-
if ((devNames.length > 0)) {
|
|
204
|
-
const devPkgs = devNames.map((n) => ((n + "@") + (devDeps[n] ?? "latest"))).join(" ");
|
|
205
|
-
const devCmd = ((("npm install --prefix " + fluxModDir) + " --save-dev ") + devPkgs);
|
|
206
|
-
info(("Running: " + devCmd));
|
|
207
|
-
execSync(devCmd, { cwd, stdio: "inherit" });
|
|
208
|
-
}
|
|
135
|
+
execSync("npm install", { cwd, stdio: "inherit" });
|
|
209
136
|
console.log();
|
|
210
|
-
ok(
|
|
211
|
-
info("Packages resolve automatically when using: flux run, flux bundle");
|
|
137
|
+
ok("Dependencies installed into node_modules/");
|
|
212
138
|
}
|
|
213
139
|
catch (e) {
|
|
214
140
|
console.log();
|
|
215
141
|
err(("Install failed: " + e.message));
|
|
216
|
-
info("Try manually: npm install
|
|
142
|
+
info("Try manually: npm install");
|
|
217
143
|
}
|
|
218
144
|
console.log();
|
|
219
145
|
}
|
|
@@ -222,7 +148,7 @@ function cmdList(opts) {
|
|
|
222
148
|
const cwd = process.cwd();
|
|
223
149
|
const pkg = readPackage(cwd);
|
|
224
150
|
if (!pkg) {
|
|
225
|
-
err("No
|
|
151
|
+
err("No package.json found. Run: flux init");
|
|
226
152
|
return;
|
|
227
153
|
}
|
|
228
154
|
console.log();
|
|
@@ -311,11 +237,12 @@ async function cmdInfo(name, opts) {
|
|
|
311
237
|
}
|
|
312
238
|
module.exports.cmdInfo = cmdInfo;
|
|
313
239
|
async function cmdUpgrade(opts) {
|
|
240
|
+
const { execSync } = require("child_process");
|
|
314
241
|
const isCheck = (opts?.check ?? false);
|
|
315
242
|
const cwd = process.cwd();
|
|
316
243
|
const pkg = readPackage(cwd);
|
|
317
244
|
if (!pkg) {
|
|
318
|
-
err("No
|
|
245
|
+
err("No package.json found. Run: flux init");
|
|
319
246
|
return;
|
|
320
247
|
}
|
|
321
248
|
const deps = (pkg.dependencies ?? { });
|
|
@@ -356,11 +283,9 @@ async function cmdUpgrade(opts) {
|
|
|
356
283
|
console.log(((((" " + clr(C.yellow, "↑ ")) + clr(C.bold, name)) + clr(C.gray, ((" " + current) + " → "))) + clr(C.green, ("^" + latest))));
|
|
357
284
|
}
|
|
358
285
|
else {
|
|
359
|
-
const isDev = (devDeps[name] != null);
|
|
360
|
-
const depKey = (isDev ? "devDependencies" : "dependencies");
|
|
361
|
-
pkg[depKey][name] = ("^" + latest);
|
|
362
286
|
updated = (updated + 1);
|
|
363
287
|
console.log(((((" " + clr(C.green, "✓ ")) + clr(C.bold, name)) + clr(C.gray, ((" " + current) + " → "))) + clr(C.green, ("^" + latest))));
|
|
288
|
+
execSync((((("npm install " + name) + "@") + latest) + " --save"), { cwd, stdio: "pipe" });
|
|
364
289
|
}
|
|
365
290
|
}
|
|
366
291
|
}
|
|
@@ -384,9 +309,7 @@ async function cmdUpgrade(opts) {
|
|
|
384
309
|
ok("All packages are already up to date");
|
|
385
310
|
}
|
|
386
311
|
else {
|
|
387
|
-
|
|
388
|
-
ok((updated + " package(s) updated in flux.json"));
|
|
389
|
-
console.log(((clr(C.gray, " Run ") + clr(C.yellow, "flux install")) + clr(C.gray, " to install updated versions")));
|
|
312
|
+
ok((updated + " package(s) updated in node_modules/ and package.json"));
|
|
390
313
|
}
|
|
391
314
|
}
|
|
392
315
|
console.log();
|
|
@@ -396,20 +319,19 @@ function cmdPublish(opts) {
|
|
|
396
319
|
const cwd = process.cwd();
|
|
397
320
|
const pkg = readPackage(cwd);
|
|
398
321
|
if (!pkg) {
|
|
399
|
-
err("No
|
|
322
|
+
err("No package.json found. Run: flux init");
|
|
400
323
|
return;
|
|
401
324
|
}
|
|
402
325
|
console.log();
|
|
403
326
|
console.log(((clr(C.cyan, " Publishing ") + clr(C.bold, ((pkg.name + "@") + pkg.version))) + " ..."));
|
|
404
327
|
console.log();
|
|
405
|
-
info("
|
|
406
|
-
info("Checking flux.json...");
|
|
328
|
+
info("Checking package.json...");
|
|
407
329
|
if (!pkg.name) {
|
|
408
|
-
err("
|
|
330
|
+
err("package.json must have a name field");
|
|
409
331
|
return;
|
|
410
332
|
}
|
|
411
333
|
if (!pkg.version) {
|
|
412
|
-
err("
|
|
334
|
+
err("package.json must have a version field");
|
|
413
335
|
return;
|
|
414
336
|
}
|
|
415
337
|
console.log();
|