purus 0.9.1 → 0.10.1
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/bin/purus.js +9 -0
- package/package.json +2 -2
- package/pkg/lib/create.js +5 -47
- package/pkg/lib/generate-config.js +35 -0
- package/pkg/lib/init.js +85 -0
- package/pkg/lib/purus-compiler.js +751 -753
- package/pkg/lib/templates.js +50 -0
package/bin/purus.js
CHANGED
|
@@ -42,6 +42,9 @@ function printHelp() {
|
|
|
42
42
|
console.log(
|
|
43
43
|
" purus init Initialize project in current directory",
|
|
44
44
|
);
|
|
45
|
+
console.log(
|
|
46
|
+
" purus config Generate config.purus in current directory",
|
|
47
|
+
);
|
|
45
48
|
console.log(" purus version Show version");
|
|
46
49
|
console.log(" purus help Show this help");
|
|
47
50
|
console.log("");
|
|
@@ -53,6 +56,12 @@ switch (cmd) {
|
|
|
53
56
|
case "create":
|
|
54
57
|
require("../pkg/lib/create.js");
|
|
55
58
|
break;
|
|
59
|
+
case "init":
|
|
60
|
+
require("../pkg/lib/init.js");
|
|
61
|
+
break;
|
|
62
|
+
case "config":
|
|
63
|
+
require("../pkg/lib/generate-config.js");
|
|
64
|
+
break;
|
|
56
65
|
case "build":
|
|
57
66
|
case "compile":
|
|
58
67
|
require("../pkg/lib/build-wrapper.js");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "purus",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Purus - /ˈpuː.rus/ means pure✨ in Latin - is a beautiful, simple, and easy-to-use language. It compiles to JavaScript. It makes your fingers free from the Shift key. With Purus, you can write code almost without pressing the Shift key.",
|
|
5
5
|
"main": "pkg/index.js",
|
|
6
6
|
"module": "pkg/index.mjs",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
},
|
|
62
62
|
"homepage": "https://purus.work",
|
|
63
63
|
"engines": {
|
|
64
|
-
"node": ">=
|
|
64
|
+
"node": ">=20"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"prettier": "^3.8.1"
|
package/pkg/lib/create.js
CHANGED
|
@@ -4,6 +4,7 @@ const fs = require("fs");
|
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const readline = require("readline");
|
|
6
6
|
const { spawnSync } = require("child_process");
|
|
7
|
+
const { CONFIG_PURUS, PRETTIERRC, MAIN_PURUS, GITIGNORE } = require("./templates.js");
|
|
7
8
|
|
|
8
9
|
function question(rl, text) {
|
|
9
10
|
return new Promise((resolve) => rl.question(text, (a) => resolve(a.trim())));
|
|
@@ -47,53 +48,13 @@ async function run() {
|
|
|
47
48
|
fs.mkdirSync(path.join(projectDir, "src"), { recursive: true });
|
|
48
49
|
|
|
49
50
|
// config.purus
|
|
50
|
-
|
|
51
|
-
const entry be ///src///
|
|
52
|
-
const output be ///dist///
|
|
53
|
-
const type be ///module///
|
|
54
|
-
const header be true
|
|
55
|
-
|
|
56
|
-
-- Linter settings
|
|
57
|
-
const lint.no-var be ///warn///
|
|
58
|
-
const lint.no-nil be ///warn///
|
|
59
|
-
const lint.bare-assignment be ///warn///
|
|
60
|
-
const lint.no-function be ///warn///
|
|
61
|
-
const lint.no-protected be ///warn///
|
|
62
|
-
const lint.no-else-if be ///warn///
|
|
63
|
-
const lint.no-js-chars be ///error///
|
|
64
|
-
const lint.no-js-operators be ///error///
|
|
65
|
-
const lint.no-for-range be ///warn///
|
|
66
|
-
const lint.bracket-match be ///error///
|
|
67
|
-
const lint.const-reassign be ///error///
|
|
68
|
-
const lint.duplicate-use be ///warn///
|
|
69
|
-
const lint.indent-size be 2
|
|
70
|
-
const lint.max-line-length be ///off///
|
|
71
|
-
const lint.no-trailing-whitespace be ///warn///
|
|
72
|
-
const lint.no-unused-import be ///warn///
|
|
73
|
-
const lint.consistent-naming be ///warn///
|
|
74
|
-
`;
|
|
75
|
-
fs.writeFileSync(path.join(projectDir, "config.purus"), configPurus);
|
|
51
|
+
fs.writeFileSync(path.join(projectDir, "config.purus"), CONFIG_PURUS);
|
|
76
52
|
|
|
77
53
|
// .prettierrc
|
|
78
|
-
|
|
79
|
-
JSON.stringify(
|
|
80
|
-
{
|
|
81
|
-
tabWidth: 2,
|
|
82
|
-
semi: false,
|
|
83
|
-
plugins: ["@puruslang/prettier-plugin-purus"],
|
|
84
|
-
},
|
|
85
|
-
null,
|
|
86
|
-
2,
|
|
87
|
-
) + "\n";
|
|
88
|
-
fs.writeFileSync(path.join(projectDir, ".prettierrc"), prettierrc);
|
|
54
|
+
fs.writeFileSync(path.join(projectDir, ".prettierrc"), PRETTIERRC);
|
|
89
55
|
|
|
90
56
|
// src/main.purus
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const message be ///Hello, World///
|
|
94
|
-
console.log[message]
|
|
95
|
-
`;
|
|
96
|
-
fs.writeFileSync(path.join(projectDir, "src/main.purus"), mainPurus);
|
|
57
|
+
fs.writeFileSync(path.join(projectDir, "src/main.purus"), MAIN_PURUS);
|
|
97
58
|
|
|
98
59
|
// README.md
|
|
99
60
|
const readme = `# ${projectName}
|
|
@@ -119,10 +80,7 @@ purus build
|
|
|
119
80
|
fs.writeFileSync(path.join(projectDir, "README.md"), readme);
|
|
120
81
|
|
|
121
82
|
// .gitignore
|
|
122
|
-
|
|
123
|
-
node_modules/
|
|
124
|
-
`;
|
|
125
|
-
fs.writeFileSync(path.join(projectDir, ".gitignore"), gitignore);
|
|
83
|
+
fs.writeFileSync(path.join(projectDir, ".gitignore"), GITIGNORE);
|
|
126
84
|
|
|
127
85
|
console.log(" config.purus");
|
|
128
86
|
console.log(" .prettierrc");
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const readline = require("readline");
|
|
6
|
+
const { CONFIG_PURUS } = require("./templates.js");
|
|
7
|
+
|
|
8
|
+
function question(rl, text) {
|
|
9
|
+
return new Promise((resolve) => rl.question(text, (a) => resolve(a.trim())));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async function run() {
|
|
13
|
+
const configPath = path.join(process.cwd(), "config.purus");
|
|
14
|
+
|
|
15
|
+
if (fs.existsSync(configPath)) {
|
|
16
|
+
const rl = readline.createInterface({
|
|
17
|
+
input: process.stdin,
|
|
18
|
+
output: process.stdout,
|
|
19
|
+
});
|
|
20
|
+
const answer = await question(
|
|
21
|
+
rl,
|
|
22
|
+
"config.purus already exists. Overwrite? [y/N] ",
|
|
23
|
+
);
|
|
24
|
+
rl.close();
|
|
25
|
+
if (answer.toLowerCase() !== "y") {
|
|
26
|
+
console.log("Aborted.");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
fs.writeFileSync(configPath, CONFIG_PURUS);
|
|
32
|
+
console.log("Generated config.purus");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
run();
|
package/pkg/lib/init.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { CONFIG_PURUS, PRETTIERRC, MAIN_PURUS, GITIGNORE } = require("./templates.js");
|
|
6
|
+
|
|
7
|
+
function run() {
|
|
8
|
+
const cwd = process.cwd();
|
|
9
|
+
|
|
10
|
+
// config.purus
|
|
11
|
+
const configPath = path.join(cwd, "config.purus");
|
|
12
|
+
if (!fs.existsSync(configPath)) {
|
|
13
|
+
fs.writeFileSync(configPath, CONFIG_PURUS);
|
|
14
|
+
console.log(" config.purus");
|
|
15
|
+
} else {
|
|
16
|
+
console.log(" config.purus (skipped: already exists)");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// .prettierrc
|
|
20
|
+
const prettierrcPath = path.join(cwd, ".prettierrc");
|
|
21
|
+
if (!fs.existsSync(prettierrcPath)) {
|
|
22
|
+
fs.writeFileSync(prettierrcPath, PRETTIERRC);
|
|
23
|
+
console.log(" .prettierrc");
|
|
24
|
+
} else {
|
|
25
|
+
console.log(" .prettierrc (skipped: already exists)");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// .gitignore
|
|
29
|
+
const gitignorePath = path.join(cwd, ".gitignore");
|
|
30
|
+
if (!fs.existsSync(gitignorePath)) {
|
|
31
|
+
fs.writeFileSync(gitignorePath, GITIGNORE);
|
|
32
|
+
console.log(" .gitignore");
|
|
33
|
+
} else {
|
|
34
|
+
console.log(" .gitignore (skipped: already exists)");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/main.purus
|
|
38
|
+
const srcDir = path.join(cwd, "src");
|
|
39
|
+
if (!fs.existsSync(srcDir)) {
|
|
40
|
+
fs.mkdirSync(srcDir, { recursive: true });
|
|
41
|
+
}
|
|
42
|
+
const mainPurusPath = path.join(srcDir, "main.purus");
|
|
43
|
+
if (!fs.existsSync(mainPurusPath)) {
|
|
44
|
+
fs.writeFileSync(mainPurusPath, MAIN_PURUS);
|
|
45
|
+
console.log(" src/main.purus");
|
|
46
|
+
} else {
|
|
47
|
+
console.log(" src/main.purus (skipped: already exists)");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// package.json — add scripts if it exists, skip if not
|
|
51
|
+
const pkgPath = path.join(cwd, "package.json");
|
|
52
|
+
if (fs.existsSync(pkgPath)) {
|
|
53
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
54
|
+
let changed = false;
|
|
55
|
+
if (!pkg.main) { pkg.main = "dist/main.js"; changed = true; }
|
|
56
|
+
if (!pkg.type) { pkg.type = "module"; changed = true; }
|
|
57
|
+
pkg.scripts = pkg.scripts || {};
|
|
58
|
+
const scripts = {
|
|
59
|
+
purus: "purus",
|
|
60
|
+
build: "purus build",
|
|
61
|
+
compile: "purus compile",
|
|
62
|
+
exec: "purus run",
|
|
63
|
+
format: "prettier --write ./src",
|
|
64
|
+
lint: "purus-lint",
|
|
65
|
+
};
|
|
66
|
+
for (const [k, v] of Object.entries(scripts)) {
|
|
67
|
+
if (!pkg.scripts[k]) { pkg.scripts[k] = v; changed = true; }
|
|
68
|
+
}
|
|
69
|
+
if (changed) {
|
|
70
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
71
|
+
console.log(" package.json (scripts updated)");
|
|
72
|
+
} else {
|
|
73
|
+
console.log(" package.json (skipped: scripts already set)");
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
console.log(
|
|
77
|
+
"\nNo package.json found. Run `npm init` then `purus init` again to add scripts.",
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
console.log("\nInitialized Purus project in current directory.");
|
|
82
|
+
console.log("Run `purus build` to compile.");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
run();
|