purus 0.8.1 → 0.9.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 +32 -14
- package/package.json +18 -11
- package/{index.d.ts → pkg/index.d.ts} +4 -1
- package/{lib → pkg/lib}/build-wrapper.js +30 -8
- package/{lib → pkg/lib}/check-wrapper.js +13 -4
- package/{lib → pkg/lib}/create.js +17 -3
- package/pkg/lib/purus-compiler.js +11387 -0
- package/{lib → pkg/lib}/purus-core.js +6 -4
- package/{lib → pkg/lib}/run-wrapper.js +15 -4
- package/pkg/lib/stdlib.js +152 -0
- package/pkg/stdlib/p-array.js +97 -0
- package/pkg/stdlib/p-datetime.js +200 -0
- package/pkg/stdlib/p-error.js +45 -0
- package/pkg/stdlib/p-json.js +18 -0
- package/pkg/stdlib/p-map.js +57 -0
- package/pkg/stdlib/p-math.js +29 -0
- package/pkg/stdlib/p-number.js +51 -0
- package/pkg/stdlib/p-object.js +69 -0
- package/pkg/stdlib/p-promise.js +45 -0
- package/pkg/stdlib/p-random.js +218 -0
- package/pkg/stdlib/p-regexp.js +50 -0
- package/pkg/stdlib/p-set.js +61 -0
- package/pkg/stdlib/p-string.js +103 -0
- package/lib/purus-compiler.js +0 -10263
- /package/{index.js → pkg/index.js} +0 -0
- /package/{index.mjs → pkg/index.mjs} +0 -0
- /package/{lib → pkg/lib}/config.js +0 -0
package/bin/purus.js
CHANGED
|
@@ -9,21 +9,39 @@ function printHelp() {
|
|
|
9
9
|
console.log("");
|
|
10
10
|
console.log("Usage:");
|
|
11
11
|
console.log(" purus build [file|dir] Compile to JavaScript");
|
|
12
|
-
console.log(
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
console.log(
|
|
13
|
+
" purus build --entry <file|dir> Specify entry file or directory",
|
|
14
|
+
);
|
|
15
|
+
console.log(
|
|
16
|
+
" purus build --output <dir> Specify output directory",
|
|
17
|
+
);
|
|
18
|
+
console.log(
|
|
19
|
+
" purus build Compile using config.purus",
|
|
20
|
+
);
|
|
15
21
|
console.log(" .purus -> .js");
|
|
16
22
|
console.log(" .cpurus -> .cjs (CommonJS)");
|
|
17
23
|
console.log(" .mpurus -> .mjs (ES Module)");
|
|
18
|
-
console.log(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
console.log(
|
|
24
|
+
console.log(
|
|
25
|
+
" purus build --no-header [file] Compile without header comment",
|
|
26
|
+
);
|
|
27
|
+
console.log(
|
|
28
|
+
" purus build --type <type> Set module type (module|commonjs)",
|
|
29
|
+
);
|
|
30
|
+
console.log(
|
|
31
|
+
" purus run [file|dir] Run without generating files",
|
|
32
|
+
);
|
|
33
|
+
console.log(
|
|
34
|
+
" purus run --entry <file|dir> Run entry file or directory",
|
|
35
|
+
);
|
|
22
36
|
console.log(" purus run Run using config.purus");
|
|
23
37
|
console.log(" purus check [file|dir] Syntax check only");
|
|
24
|
-
console.log(
|
|
38
|
+
console.log(
|
|
39
|
+
" purus check --entry <file|dir> Check entry file or directory",
|
|
40
|
+
);
|
|
25
41
|
console.log(" purus new [name] [-y] Create a new project");
|
|
26
|
-
console.log(
|
|
42
|
+
console.log(
|
|
43
|
+
" purus init Initialize project in current directory",
|
|
44
|
+
);
|
|
27
45
|
console.log(" purus version Show version");
|
|
28
46
|
console.log(" purus help Show this help");
|
|
29
47
|
console.log("");
|
|
@@ -33,17 +51,17 @@ function printHelp() {
|
|
|
33
51
|
switch (cmd) {
|
|
34
52
|
case "new":
|
|
35
53
|
case "create":
|
|
36
|
-
require("../lib/create.js");
|
|
54
|
+
require("../pkg/lib/create.js");
|
|
37
55
|
break;
|
|
38
56
|
case "build":
|
|
39
57
|
case "compile":
|
|
40
|
-
require("../lib/build-wrapper.js");
|
|
58
|
+
require("../pkg/lib/build-wrapper.js");
|
|
41
59
|
break;
|
|
42
60
|
case "run":
|
|
43
|
-
require("../lib/run-wrapper.js");
|
|
61
|
+
require("../pkg/lib/run-wrapper.js");
|
|
44
62
|
break;
|
|
45
63
|
case "check":
|
|
46
|
-
require("../lib/check-wrapper.js");
|
|
64
|
+
require("../pkg/lib/check-wrapper.js");
|
|
47
65
|
break;
|
|
48
66
|
case "version":
|
|
49
67
|
case "--version":
|
|
@@ -57,6 +75,6 @@ switch (cmd) {
|
|
|
57
75
|
printHelp();
|
|
58
76
|
break;
|
|
59
77
|
default:
|
|
60
|
-
require("../lib/purus-compiler.js");
|
|
78
|
+
require("../pkg/lib/purus-compiler.js");
|
|
61
79
|
break;
|
|
62
80
|
}
|
package/package.json
CHANGED
|
@@ -1,34 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "purus",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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
|
-
"main": "index.js",
|
|
6
|
-
"module": "index.mjs",
|
|
7
|
-
"types": "index.d.ts",
|
|
5
|
+
"main": "pkg/index.js",
|
|
6
|
+
"module": "pkg/index.mjs",
|
|
7
|
+
"types": "pkg/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"types": "./index.d.ts",
|
|
11
|
-
"import": "./index.mjs",
|
|
12
|
-
"require": "./index.js"
|
|
10
|
+
"types": "./pkg/index.d.ts",
|
|
11
|
+
"import": "./pkg/index.mjs",
|
|
12
|
+
"require": "./pkg/index.js"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"bin": {
|
|
16
16
|
"purus": "bin/purus.js"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
|
-
"
|
|
20
|
-
"index.mjs",
|
|
21
|
-
"index.d.ts",
|
|
19
|
+
"pkg/",
|
|
22
20
|
"bin/",
|
|
23
|
-
"lib/",
|
|
24
21
|
"LICENSE",
|
|
25
22
|
"README.md",
|
|
26
23
|
"README-ja.md"
|
|
27
24
|
],
|
|
28
25
|
"scripts": {
|
|
26
|
+
"test": "moon test --target js",
|
|
29
27
|
"build:compiler": "moon build --target js",
|
|
30
28
|
"build:copy": "node scripts/build.js",
|
|
31
29
|
"build": "npm run build:compiler && npm run build:copy",
|
|
30
|
+
"lint": "moon check",
|
|
31
|
+
"lint:fix": "moon fmt",
|
|
32
|
+
"format": "moon fmt && prettier --write ./bin ./pkg ./scripts",
|
|
33
|
+
"format:check": "moon fmt --check && prettier --check ./bin ./pkg ./scripts",
|
|
34
|
+
"typecheck": "moon check",
|
|
35
|
+
"check": "npm run lint && npm run format:check && npm run build && npm run typecheck",
|
|
32
36
|
"sync": "node scripts/sync-version.js",
|
|
33
37
|
"prepublishOnly": "npm run sync && npm run build"
|
|
34
38
|
},
|
|
@@ -58,5 +62,8 @@
|
|
|
58
62
|
"homepage": "https://purus.work",
|
|
59
63
|
"engines": {
|
|
60
64
|
"node": ">=18"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"prettier": "^3.8.1"
|
|
61
68
|
}
|
|
62
69
|
}
|
|
@@ -34,7 +34,10 @@ export interface CompileOptions {
|
|
|
34
34
|
* const js = compile('const x be 42');
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
|
-
export declare function compile(
|
|
37
|
+
export declare function compile(
|
|
38
|
+
source: string,
|
|
39
|
+
options?: CompileOptions,
|
|
40
|
+
): string;
|
|
38
41
|
|
|
39
42
|
/**
|
|
40
43
|
* Check Purus source code for syntax errors.
|
|
@@ -20,7 +20,10 @@ for (let i = 0; i < args.length; i++) {
|
|
|
20
20
|
} else if (args[i] === "--stdout") {
|
|
21
21
|
toStdout = true;
|
|
22
22
|
} else if (args[i] === "--strict") {
|
|
23
|
-
if (
|
|
23
|
+
if (
|
|
24
|
+
i + 1 < args.length &&
|
|
25
|
+
(args[i + 1] === "true" || args[i + 1] === "false")
|
|
26
|
+
) {
|
|
24
27
|
strict = args[++i] === "true";
|
|
25
28
|
} else {
|
|
26
29
|
strict = true;
|
|
@@ -70,14 +73,23 @@ function resolveModuleType(filePath, cliModuleType, configResult) {
|
|
|
70
73
|
return "module";
|
|
71
74
|
}
|
|
72
75
|
|
|
73
|
-
if (
|
|
76
|
+
if (
|
|
77
|
+
entry &&
|
|
78
|
+
fs.existsSync(entry) &&
|
|
79
|
+
fs.statSync(entry).isFile() &&
|
|
80
|
+
/\.(c|m)?purus$/.test(entry)
|
|
81
|
+
) {
|
|
74
82
|
// Single file - handle directly via compile API
|
|
75
83
|
const source = fs.readFileSync(entry, "utf8");
|
|
76
84
|
const useHeader = !noHeader;
|
|
77
85
|
const useStrict = strict !== null ? strict : true;
|
|
78
86
|
const configResult = loadConfig();
|
|
79
87
|
const resolvedModule = resolveModuleType(entry, moduleType, configResult);
|
|
80
|
-
const js = compile(source, {
|
|
88
|
+
const js = compile(source, {
|
|
89
|
+
header: useHeader,
|
|
90
|
+
strict: useStrict,
|
|
91
|
+
module: resolvedModule,
|
|
92
|
+
});
|
|
81
93
|
|
|
82
94
|
if (toStdout) {
|
|
83
95
|
process.stdout.write(js);
|
|
@@ -113,7 +125,7 @@ if (entry && fs.existsSync(entry) && fs.statSync(entry).isFile() && /\.(c|m)?pur
|
|
|
113
125
|
if (!output) {
|
|
114
126
|
outputDir = path.resolve(
|
|
115
127
|
configResult.configDir,
|
|
116
|
-
configResult.config.output || "dist"
|
|
128
|
+
configResult.config.output || "dist",
|
|
117
129
|
);
|
|
118
130
|
}
|
|
119
131
|
useHeader = configResult.config.header !== false && !noHeader;
|
|
@@ -127,10 +139,12 @@ if (entry && fs.existsSync(entry) && fs.statSync(entry).isFile() && /\.(c|m)?pur
|
|
|
127
139
|
console.log("Error: no input file specified and no config.purus found");
|
|
128
140
|
console.log("");
|
|
129
141
|
console.log("Usage:");
|
|
130
|
-
console.log(
|
|
142
|
+
console.log(
|
|
143
|
+
" purus build <file|dir> Compile a file or directory",
|
|
144
|
+
);
|
|
131
145
|
console.log(" purus build --entry <file|dir> Specify entry");
|
|
132
146
|
console.log(
|
|
133
|
-
" purus build Compile using config.purus"
|
|
147
|
+
" purus build Compile using config.purus",
|
|
134
148
|
);
|
|
135
149
|
process.exit(1);
|
|
136
150
|
}
|
|
@@ -169,9 +183,17 @@ if (entry && fs.existsSync(entry) && fs.statSync(entry).isFile() && /\.(c|m)?pur
|
|
|
169
183
|
|
|
170
184
|
let count = 0;
|
|
171
185
|
for (const f of files) {
|
|
186
|
+
// Skip config.purus itself - it's the build config, not a source file
|
|
187
|
+
if (configResult && path.resolve(f) === path.resolve(configResult.configPath)) {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
172
190
|
const source = fs.readFileSync(f, "utf8");
|
|
173
191
|
const resolvedModule = resolveModuleType(f, moduleType, configResult);
|
|
174
|
-
const js = compile(source, {
|
|
192
|
+
const js = compile(source, {
|
|
193
|
+
header: useHeader,
|
|
194
|
+
strict: useStrict,
|
|
195
|
+
module: resolvedModule,
|
|
196
|
+
});
|
|
175
197
|
let outputPath;
|
|
176
198
|
|
|
177
199
|
if (stat.isFile()) {
|
|
@@ -183,7 +205,7 @@ if (entry && fs.existsSync(entry) && fs.statSync(entry).isFile() && /\.(c|m)?pur
|
|
|
183
205
|
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
184
206
|
fs.writeFileSync(outputPath, js);
|
|
185
207
|
console.log(
|
|
186
|
-
`Compiled ${path.relative(process.cwd(), f)} -> ${path.relative(process.cwd(), outputPath)}
|
|
208
|
+
`Compiled ${path.relative(process.cwd(), f)} -> ${path.relative(process.cwd(), outputPath)}`,
|
|
187
209
|
);
|
|
188
210
|
count++;
|
|
189
211
|
}
|
|
@@ -30,9 +30,13 @@ if (entry && fs.existsSync(entry) && fs.statSync(entry).isFile()) {
|
|
|
30
30
|
console.log("Error: no input file specified and no config.purus found");
|
|
31
31
|
console.log("");
|
|
32
32
|
console.log("Usage:");
|
|
33
|
-
console.log(
|
|
33
|
+
console.log(
|
|
34
|
+
" purus check <file|dir> Check a file or directory",
|
|
35
|
+
);
|
|
34
36
|
console.log(" purus check --entry <file|dir> Specify entry");
|
|
35
|
-
console.log(
|
|
37
|
+
console.log(
|
|
38
|
+
" purus check Check using config.purus",
|
|
39
|
+
);
|
|
36
40
|
process.exit(1);
|
|
37
41
|
}
|
|
38
42
|
|
|
@@ -68,7 +72,9 @@ if (entry && fs.existsSync(entry) && fs.statSync(entry).isFile()) {
|
|
|
68
72
|
console.log(`\n${errors} file${errors === 1 ? "" : "s"} with errors.`);
|
|
69
73
|
process.exit(1);
|
|
70
74
|
} else {
|
|
71
|
-
console.log(
|
|
75
|
+
console.log(
|
|
76
|
+
`${files.length} file${files.length === 1 ? "" : "s"} checked. No errors.`,
|
|
77
|
+
);
|
|
72
78
|
}
|
|
73
79
|
}
|
|
74
80
|
|
|
@@ -89,7 +95,10 @@ function findPurusFiles(dir) {
|
|
|
89
95
|
const fullPath = path.join(dir, entry.name);
|
|
90
96
|
if (entry.isDirectory()) {
|
|
91
97
|
results.push(...findPurusFiles(fullPath));
|
|
92
|
-
} else if (
|
|
98
|
+
} else if (
|
|
99
|
+
/\.(c|m)?purus$/.test(entry.name) &&
|
|
100
|
+
entry.name !== "config.purus"
|
|
101
|
+
) {
|
|
93
102
|
results.push(fullPath);
|
|
94
103
|
}
|
|
95
104
|
}
|
|
@@ -37,7 +37,9 @@ async function run() {
|
|
|
37
37
|
const projectDir = path.resolve(projectName);
|
|
38
38
|
|
|
39
39
|
if (fs.existsSync(projectDir) && !isDirEmpty(projectDir)) {
|
|
40
|
-
console.log(
|
|
40
|
+
console.log(
|
|
41
|
+
`Error: directory '${projectName}' already exists and is not empty`,
|
|
42
|
+
);
|
|
41
43
|
process.exit(1);
|
|
42
44
|
}
|
|
43
45
|
|
|
@@ -54,6 +56,16 @@ const header be true
|
|
|
54
56
|
-- Linter settings
|
|
55
57
|
const lint.no-var be ///warn///
|
|
56
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///
|
|
57
69
|
const lint.indent-size be 2
|
|
58
70
|
const lint.max-line-length be ///off///
|
|
59
71
|
const lint.no-trailing-whitespace be ///warn///
|
|
@@ -71,7 +83,7 @@ const lint.consistent-naming be ///warn///
|
|
|
71
83
|
plugins: ["@puruslang/prettier-plugin-purus"],
|
|
72
84
|
},
|
|
73
85
|
null,
|
|
74
|
-
2
|
|
86
|
+
2,
|
|
75
87
|
) + "\n";
|
|
76
88
|
fs.writeFileSync(path.join(projectDir, ".prettierrc"), prettierrc);
|
|
77
89
|
|
|
@@ -162,7 +174,9 @@ node_modules/
|
|
|
162
174
|
} else {
|
|
163
175
|
const answer = await question(rl, "\nInstall dependencies? (Y/n) ");
|
|
164
176
|
installDeps =
|
|
165
|
-
answer === "" ||
|
|
177
|
+
answer === "" ||
|
|
178
|
+
answer.toLowerCase() === "y" ||
|
|
179
|
+
answer.toLowerCase() === "yes";
|
|
166
180
|
}
|
|
167
181
|
|
|
168
182
|
if (installDeps) {
|