nomen-lang 0.0.4 → 0.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/index.mjs +11 -4
- package/package.json +1 -1
- package/src/index.ts +13 -2
package/dist/index.mjs
CHANGED
|
@@ -21430,6 +21430,7 @@ function render_errors(source, errors) {
|
|
|
21430
21430
|
//#endregion
|
|
21431
21431
|
//#region src/index.ts
|
|
21432
21432
|
const SUPPORTED_EXTENSION = ".nm";
|
|
21433
|
+
let build_root;
|
|
21433
21434
|
console.log("\n~ NOMEN ~\n");
|
|
21434
21435
|
const options = yargs(hideBin(process.argv)).usage("Usage: nomen --in [file/folder]").option("in", {
|
|
21435
21436
|
alias: "i",
|
|
@@ -21470,6 +21471,7 @@ const options = yargs(hideBin(process.argv)).usage("Usage: nomen --in [file/fold
|
|
|
21470
21471
|
try {
|
|
21471
21472
|
options.in = options.in ?? resolve_input();
|
|
21472
21473
|
if (!options.in) process.exit(0);
|
|
21474
|
+
if (!build_root) build_root = fs.lstatSync(options.in).isDirectory() ? options.in : path.dirname(options.in);
|
|
21473
21475
|
if (fs.existsSync(options.in)) {
|
|
21474
21476
|
let config = {
|
|
21475
21477
|
arch: "aarch64",
|
|
@@ -21499,13 +21501,19 @@ function resolve_input() {
|
|
|
21499
21501
|
if (fs.existsSync(config_path)) try {
|
|
21500
21502
|
const json = fs.readFileSync(config_path, "utf8").replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
21501
21503
|
const parsed = JSON.parse(json);
|
|
21502
|
-
if (parsed.entry)
|
|
21504
|
+
if (parsed.entry) {
|
|
21505
|
+
build_root = cwd;
|
|
21506
|
+
return path.resolve(cwd, parsed.entry);
|
|
21507
|
+
}
|
|
21503
21508
|
} catch {}
|
|
21504
21509
|
let nm_files = [];
|
|
21505
21510
|
try {
|
|
21506
21511
|
nm_files = fs.readdirSync(cwd).filter((f) => f.endsWith(".nm"));
|
|
21507
21512
|
} catch {}
|
|
21508
|
-
if (nm_files.length === 1)
|
|
21513
|
+
if (nm_files.length === 1) {
|
|
21514
|
+
build_root = cwd;
|
|
21515
|
+
return path.resolve(cwd, nm_files[0]);
|
|
21516
|
+
}
|
|
21509
21517
|
if (nm_files.length > 1) {
|
|
21510
21518
|
console.log(`Found ${nm_files.length} .nm files in ${cwd}. Specify which to run with --in:\n ` + nm_files.join("\n "));
|
|
21511
21519
|
return;
|
|
@@ -21589,9 +21597,8 @@ function processFile(filename, config) {
|
|
|
21589
21597
|
console.log(render_errors(input, result.errors));
|
|
21590
21598
|
return;
|
|
21591
21599
|
}
|
|
21592
|
-
const dir = path.dirname(filename);
|
|
21593
21600
|
const basename = path.basename(filename, ".nm");
|
|
21594
|
-
const buildDir = path.join(
|
|
21601
|
+
const buildDir = path.join(build_root ?? path.dirname(filename), "build");
|
|
21595
21602
|
if (!fs.existsSync(buildDir)) fs.mkdirSync(buildDir, { recursive: true });
|
|
21596
21603
|
const ext = arch === "aarch64" ? ".s" : platform === "macos" || platform === "ios" ? ".m" : ".c";
|
|
21597
21604
|
const headerfile = path.join(buildDir, "main.h");
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -16,6 +16,11 @@ import type Config from "./types/Config.ts";
|
|
|
16
16
|
|
|
17
17
|
const SUPPORTED_EXTENSION = ".nm";
|
|
18
18
|
|
|
19
|
+
// The folder whose `build/` subdirectory receives compiler output. Set during
|
|
20
|
+
// input resolution: the --in folder, the .nm file's folder, or — for
|
|
21
|
+
// package.jsonc discovery — the package folder (cwd), not the entry's folder.
|
|
22
|
+
let build_root: string | undefined;
|
|
23
|
+
|
|
19
24
|
console.log("\n~ NOMEN ~\n");
|
|
20
25
|
|
|
21
26
|
const options = yargs(hideBin(process.argv))
|
|
@@ -74,6 +79,11 @@ try {
|
|
|
74
79
|
if (!options.in) {
|
|
75
80
|
process.exit(0);
|
|
76
81
|
}
|
|
82
|
+
// For an explicit --in, build next to whatever was passed (the folder
|
|
83
|
+
// itself, or the file's folder). Discovery cases set build_root themselves.
|
|
84
|
+
if (!build_root) {
|
|
85
|
+
build_root = fs.lstatSync(options.in).isDirectory() ? options.in : path.dirname(options.in);
|
|
86
|
+
}
|
|
77
87
|
|
|
78
88
|
if (fs.existsSync(options.in)) {
|
|
79
89
|
let config: Config = { arch: "aarch64", platform: default_platform() };
|
|
@@ -131,6 +141,7 @@ function resolve_input(): string | undefined {
|
|
|
131
141
|
const json = raw.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
132
142
|
const parsed = JSON.parse(json);
|
|
133
143
|
if (parsed.entry) {
|
|
144
|
+
build_root = cwd;
|
|
134
145
|
return path.resolve(cwd, parsed.entry);
|
|
135
146
|
}
|
|
136
147
|
} catch {
|
|
@@ -146,6 +157,7 @@ function resolve_input(): string | undefined {
|
|
|
146
157
|
// unreadable working folder
|
|
147
158
|
}
|
|
148
159
|
if (nm_files.length === 1) {
|
|
160
|
+
build_root = cwd;
|
|
149
161
|
return path.resolve(cwd, nm_files[0]);
|
|
150
162
|
}
|
|
151
163
|
if (nm_files.length > 1) {
|
|
@@ -276,9 +288,8 @@ function processFile(filename: string, config: Config) {
|
|
|
276
288
|
return;
|
|
277
289
|
}
|
|
278
290
|
|
|
279
|
-
const dir = path.dirname(filename);
|
|
280
291
|
const basename = path.basename(filename, ".nm");
|
|
281
|
-
const buildDir = path.join(
|
|
292
|
+
const buildDir = path.join(build_root ?? path.dirname(filename), "build");
|
|
282
293
|
if (!fs.existsSync(buildDir)) {
|
|
283
294
|
fs.mkdirSync(buildDir, { recursive: true });
|
|
284
295
|
}
|