purus 0.8.1 → 0.9.0

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 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(" purus build --entry <file|dir> Specify entry file or directory");
13
- console.log(" purus build --output <dir> Specify output directory");
14
- console.log(" purus build Compile using config.purus");
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(" purus build --no-header [file] Compile without header comment");
19
- console.log(" purus build --type <type> Set module type (module|commonjs)");
20
- console.log(" purus run [file|dir] Run without generating files");
21
- console.log(" purus run --entry <file|dir> Run entry file or directory");
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(" purus check --entry <file|dir> Check entry file or directory");
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(" purus init Initialize project in current directory");
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("");
package/index.d.ts CHANGED
@@ -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(source: string, options?: CompileOptions): string;
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 (i + 1 < args.length && (args[i + 1] === "true" || args[i + 1] === "false")) {
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 (entry && fs.existsSync(entry) && fs.statSync(entry).isFile() && /\.(c|m)?purus$/.test(entry)) {
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, { header: useHeader, strict: useStrict, module: resolvedModule });
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(" purus build <file|dir> Compile a file or directory");
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
  }
@@ -171,7 +185,11 @@ if (entry && fs.existsSync(entry) && fs.statSync(entry).isFile() && /\.(c|m)?pur
171
185
  for (const f of files) {
172
186
  const source = fs.readFileSync(f, "utf8");
173
187
  const resolvedModule = resolveModuleType(f, moduleType, configResult);
174
- const js = compile(source, { header: useHeader, strict: useStrict, module: resolvedModule });
188
+ const js = compile(source, {
189
+ header: useHeader,
190
+ strict: useStrict,
191
+ module: resolvedModule,
192
+ });
175
193
  let outputPath;
176
194
 
177
195
  if (stat.isFile()) {
@@ -183,7 +201,7 @@ if (entry && fs.existsSync(entry) && fs.statSync(entry).isFile() && /\.(c|m)?pur
183
201
  fs.mkdirSync(path.dirname(outputPath), { recursive: true });
184
202
  fs.writeFileSync(outputPath, js);
185
203
  console.log(
186
- `Compiled ${path.relative(process.cwd(), f)} -> ${path.relative(process.cwd(), outputPath)}`
204
+ `Compiled ${path.relative(process.cwd(), f)} -> ${path.relative(process.cwd(), outputPath)}`,
187
205
  );
188
206
  count++;
189
207
  }
@@ -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(" purus check <file|dir> Check a file or directory");
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(" purus check Check using config.purus");
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(`${files.length} file${files.length === 1 ? "" : "s"} checked. No errors.`);
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 (/\.(c|m)?purus$/.test(entry.name) && entry.name !== "config.purus") {
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
  }
package/lib/create.js CHANGED
@@ -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(`Error: directory '${projectName}' already exists and is not empty`);
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 === "" || answer.toLowerCase() === "y" || answer.toLowerCase() === "yes";
177
+ answer === "" ||
178
+ answer.toLowerCase() === "y" ||
179
+ answer.toLowerCase() === "yes";
166
180
  }
167
181
 
168
182
  if (installDeps) {