noshift.js 0.8.0 → 0.10.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/README-ja.md CHANGED
@@ -21,38 +21,56 @@
21
21
 
22
22
  ## インストール
23
23
 
24
+ ### グローバルインストール
25
+
24
26
  ```bash
25
27
  npm install -g noshift.js@latest
26
28
  ```
27
29
 
30
+ ### ローカルインストール
31
+
32
+ ```bash
33
+ npm install -D noshift.js@latest
34
+ ```
35
+
28
36
  ---
29
37
 
30
38
  ## はじめに
31
39
 
32
40
  ```bash
33
41
  # 新しいプロジェクトを作成
42
+
43
+ # グローバル
34
44
  nsc create my-project
35
45
 
46
+ # ローカル
47
+ npx nsc create my-project
48
+
36
49
  # または、現在のディレクトリに nsjsconfig.json だけを作成
50
+
51
+ # グローバル
37
52
  nsc init
53
+
54
+ # ローカル
55
+ npx nsc init
38
56
  ```
39
57
 
40
58
  ---
41
59
 
42
60
  ## CLI リファレンス
43
61
 
44
- `nsc` は TypeScript `tsc` に似た使い心地を目指しています。
62
+ `nsc` は NoShift.js のコンパイラ CLI です。
45
63
 
46
64
  | コマンド | エイリアス | 説明 |
47
65
  |---|---|---|
48
- | `nsc` | | `nsjsconfig.json` を使って `.nsjs` → `.js` にコンパイル |
49
- | `nsc watch` | `nsc -w` `nsc --watch` | 変更を監視して自動的に再コンパイル |
50
- | `nsc init` | `nsc --init` | 現在のディレクトリに `nsjsconfig.json` を作成 |
51
- | `nsc clean` | `nsc --clean` | 出力ディレクトリ (`outdir`) を削除 |
52
- | `nsc run <file>` | `nsc -r <file>` `nsc --run <file>` | `.nsjs` ファイルを直接実行 |
53
- | `nsc create [name]` | `nsc --create [name]` | 新しいプロジェクトを作成(`--no-prettier` で Prettier スキップ) |
54
- | `nsc version` | `nsc -v` `nsc --version` | バージョンを表示 |
55
- | `nsc help` | `nsc -h` `nsc --help` | ヘルプを表示 |
66
+ | `nsc` / `npx nsc` | | `nsjsconfig.json` を使って `.nsjs` → `.js` にコンパイル |
67
+ | `nsc watch` / `npx nsc watch` | `nsc -w` `nsc --watch` | 変更を監視して自動的に再コンパイル |
68
+ | `nsc init` / `npx nsc init` | `nsc --init` | 現在のディレクトリに `nsjsconfig.json` を作成 |
69
+ | `nsc clean` / `npx nsc clean` | `nsc --clean` | 出力ディレクトリ (`outdir`) を削除 |
70
+ | `nsc run <file>` / `npx nsc run <file>` | `nsc -r <file>` `nsc --run <file>` | `.nsjs` ファイルを直接実行 |
71
+ | `nsc create [name]` / `npx nsc create [name]` | `nsc --create [name]` | 新しいプロジェクトを作成(`--no-prettier` で Prettier スキップ) |
72
+ | `nsc version` / `npx nsc version` | `nsc -v` `nsc --version` | バージョンを表示 |
73
+ | `nsc help` / `npx nsc help` | `nsc -h` `nsc --help` | ヘルプを表示 |
56
74
 
57
75
  ---
58
76
 
@@ -280,6 +298,55 @@ for (let i = 0; i < 3; i++) {
280
298
 
281
299
  ---
282
300
 
301
+ ## プログラマティック API
302
+
303
+ コード内からライブラリとして `.nsjs` コードをコンパイルできます。
304
+
305
+ ### ESM
306
+
307
+ ```js
308
+ import { compile } from "noshift.js";
309
+
310
+ const result = compile('console.log^8^2^3hello^2^9;');
311
+ console.log(result.outputText);
312
+ // => console.log("Hello");
313
+ ```
314
+
315
+ ### CJS
316
+
317
+ ```js
318
+ const { compile } = require("noshift.js");
319
+
320
+ const result = compile('console.log^8^2^3hello^2^9;');
321
+ console.log(result.outputText);
322
+ // => console.log("Hello");
323
+ ```
324
+
325
+ ### オプション
326
+
327
+ ```js
328
+ const result = compile(source, {
329
+ capitalizeInStrings: false, // 文字列内の ^3 を無効化
330
+ });
331
+ ```
332
+
333
+ ### 構文診断
334
+
335
+ `diagnose()` を使ってコンパイル前に構文エラーをチェックできます:
336
+
337
+ ```js
338
+ import { diagnose } from "noshift.js";
339
+
340
+ const errors = diagnose(source);
341
+ if (errors.length > 0) {
342
+ for (const e of errors) {
343
+ console.error(`Line ${e.line}:${e.column} - ${e.message}`);
344
+ }
345
+ }
346
+ ```
347
+
348
+ ---
349
+
283
350
  ## ファイル名の規則
284
351
 
285
352
  `_` で始まるファイルはコンパイル対象から除外されます(パーシャル・ユーティリティ用途に便利)。
package/README.md CHANGED
@@ -22,38 +22,56 @@ Typing shifted symbols (`!`, `"`, `(`, `)`, `{`, `}` …) is tiring.
22
22
 
23
23
  ## Installation
24
24
 
25
+ ### Global Install
26
+
25
27
  ```bash
26
28
  npm install -g noshift.js@latest
27
29
  ```
28
30
 
31
+ ### Local Install
32
+
33
+ ```bash
34
+ npm install -D noshift.js@latest
35
+ ```
36
+
29
37
  ---
30
38
 
31
39
  ## Getting Started
32
40
 
33
41
  ```bash
34
42
  # Create a new project
43
+
44
+ # Global
35
45
  nsc create my-project
36
46
 
47
+ # Local
48
+ npx nsc create my-project
49
+
37
50
  # Or initialize only a nsjsconfig.json in the current directory
51
+
52
+ # Global
38
53
  nsc init
54
+
55
+ # Local
56
+ npx nsc init
39
57
  ```
40
58
 
41
59
  ---
42
60
 
43
61
  ## CLI Reference
44
62
 
45
- `nsc` is designed to feel like TypeScript's `tsc`.
63
+ `nsc` is the NoShift.js compiler CLI.
46
64
 
47
65
  | Command | Alias | Description |
48
66
  |---|---|---|
49
- | `nsc` | | Compile `.nsjs` → `.js` using `nsjsconfig.json` |
50
- | `nsc watch` | `nsc -w` `nsc --watch` | Watch for changes and recompile automatically |
51
- | `nsc init` | `nsc --init` | Create `nsjsconfig.json` in the current directory |
52
- | `nsc clean` | `nsc --clean` | Delete the output directory (`outdir`) |
53
- | `nsc run <file>` | `nsc -r <file>` `nsc --run <file>` | Run a `.nsjs` file directly |
54
- | `nsc create [name]` | `nsc --create [name]` | Scaffold a new project (`--no-prettier` to skip Prettier) |
55
- | `nsc version` | `nsc -v` `nsc --version` | Show version |
56
- | `nsc help` | `nsc -h` `nsc --help` | Show help |
67
+ | `nsc` / `npx nsc` | | Compile `.nsjs` → `.js` using `nsjsconfig.json` |
68
+ | `nsc watch` / `npx nsc watch` | `nsc -w` `nsc --watch` | Watch for changes and recompile automatically |
69
+ | `nsc init` / `npx nsc init` | `nsc --init` | Create `nsjsconfig.json` in the current directory |
70
+ | `nsc clean` / `npx nsc clean` | `nsc --clean` | Delete the output directory (`outdir`) |
71
+ | `nsc run <file>` / `npx nsc run <file>` | `nsc -r <file>` `nsc --run <file>` | Run a `.nsjs` file directly |
72
+ | `nsc create [name]` / `npx nsc create [name]` | `nsc --create [name]` | Scaffold a new project (`--no-prettier` to skip Prettier) |
73
+ | `nsc version` / `npx nsc version` | `nsc -v` `nsc --version` | Show version |
74
+ | `nsc help` / `npx nsc help` | `nsc -h` `nsc --help` | Show help |
57
75
 
58
76
  ---
59
77
 
@@ -281,6 +299,55 @@ for (let i = 0; i < 3; i++) {
281
299
 
282
300
  ---
283
301
 
302
+ ## Programmatic API
303
+
304
+ You can use NoShift.js as a library to compile `.nsjs` code from within your own scripts.
305
+
306
+ ### ESM
307
+
308
+ ```js
309
+ import { compile } from "noshift.js";
310
+
311
+ const result = compile('console.log^8^2^3hello^2^9;');
312
+ console.log(result.outputText);
313
+ // => console.log("Hello");
314
+ ```
315
+
316
+ ### CJS
317
+
318
+ ```js
319
+ const { compile } = require("noshift.js");
320
+
321
+ const result = compile('console.log^8^2^3hello^2^9;');
322
+ console.log(result.outputText);
323
+ // => console.log("Hello");
324
+ ```
325
+
326
+ ### Options
327
+
328
+ ```js
329
+ const result = compile(source, {
330
+ capitalizeInStrings: false, // Disable ^3 inside strings
331
+ });
332
+ ```
333
+
334
+ ### Syntax Diagnostics
335
+
336
+ Use `diagnose()` to check for syntax errors before compiling:
337
+
338
+ ```js
339
+ import { diagnose } from "noshift.js";
340
+
341
+ const errors = diagnose(source);
342
+ if (errors.length > 0) {
343
+ for (const e of errors) {
344
+ console.error(`Line ${e.line}:${e.column} - ${e.message}`);
345
+ }
346
+ }
347
+ ```
348
+
349
+ ---
350
+
284
351
  ## File Naming
285
352
 
286
353
  Files starting with `_` are excluded from compilation (useful for partials/utilities).
@@ -1,6 +1,6 @@
1
1
  import { promises as fs } from "fs";
2
2
  import path from "path";
3
- import convert, { checkUppercaseWarnings } from "../src/convert.js";
3
+ import convert, { checkUppercaseWarnings, diagnose } from "../src/convert.js";
4
4
  import { loadConfig } from "../src/config.js";
5
5
  import { handleSigint } from "../src/signal-handler.js";
6
6
  import * as logger from "../src/logger.js";
@@ -74,6 +74,19 @@ export default async function compile() {
74
74
  try {
75
75
  const code = await fs.readFile(file, "utf-8");
76
76
 
77
+ // 構文エラーチェック
78
+ const syntaxErrors = diagnose(code);
79
+ if (syntaxErrors.length > 0) {
80
+ for (const e of syntaxErrors) {
81
+ logger.errorCode(
82
+ "NS1",
83
+ `${relative.replace(/\\/g, "/")}:${e.line}:${e.column} - ${e.message}`,
84
+ );
85
+ }
86
+ errors += syntaxErrors.length;
87
+ continue;
88
+ }
89
+
77
90
  // 大文字警告チェック
78
91
  if (warnUppercase) {
79
92
  const warnings = checkUppercaseWarnings(code, convertOptions);
@@ -42,12 +42,14 @@ export default async function create(projectNameArg, options = {}) {
42
42
  // Add scripts to package.json
43
43
  const pkgPath = path.join(projectPath, "package.json");
44
44
  const pkg = JSON.parse(await fs.readFile(pkgPath, "utf-8"));
45
- pkg.scripts = pkg.scripts ?? {};
46
- pkg.scripts.compile = "nsc";
47
- pkg.scripts.dev = "nsc watch";
45
+ pkg.scripts = {};
48
46
  if (usePrettier) {
49
47
  pkg.scripts.format = "prettier --write ./src";
50
48
  }
49
+ pkg.scripts.compile = "nsc";
50
+ pkg.scripts.dev = "nsc watch";
51
+ pkg.scripts.clean = "nsc clean";
52
+ pkg.scripts.script = "nsc run";
51
53
  await fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
52
54
 
53
55
  // Create nsjsconfig.json
package/commands/dev.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { promises as fs, watch } from "fs";
2
2
  import path from "path";
3
- import convert from "../src/convert.js";
3
+ import convert, { diagnose } from "../src/convert.js";
4
4
  import { loadConfig } from "../src/config.js";
5
5
  import { handleSigint } from "../src/signal-handler.js";
6
6
  import * as logger from "../src/logger.js";
@@ -35,6 +35,17 @@ async function compileFile(file, rootDir, outDir, cwd, convertOptions = {}) {
35
35
  .join(outDir, path.relative(rootDir, file))
36
36
  .replace(/\.nsjs$/, ".js");
37
37
  const code = await fs.readFile(file, "utf-8");
38
+
39
+ // 構文エラーチェック
40
+ const syntaxErrors = diagnose(code);
41
+ if (syntaxErrors.length > 0) {
42
+ const rel = relative;
43
+ for (const e of syntaxErrors) {
44
+ logger.errorCode("NS1", `${rel}:${e.line}:${e.column} - ${e.message}`);
45
+ }
46
+ throw new Error(`${syntaxErrors.length} syntax error(s)`);
47
+ }
48
+
38
49
  const js = convert(code, convertOptions);
39
50
  await fs.mkdir(path.dirname(destPath), { recursive: true });
40
51
  await fs.writeFile(destPath, js, "utf-8");
package/commands/run.js CHANGED
@@ -1,14 +1,23 @@
1
1
  import { promises as fs } from "fs";
2
2
  import path from "path";
3
3
  import { spawn } from "child_process";
4
- import convert from "../src/convert.js";
4
+ import convert, { diagnose } from "../src/convert.js";
5
5
  import { loadConfig } from "../src/config.js";
6
6
  import { handleSigint } from "../src/signal-handler.js";
7
7
  import * as logger from "../src/logger.js";
8
+ import { askInput } from "../src/prompt.js";
8
9
 
9
10
  export default async function run(file) {
10
11
  handleSigint();
11
12
 
13
+ if (!file) {
14
+ file = await askInput("File path");
15
+ if (!file) {
16
+ logger.error("File path is required.");
17
+ process.exit(1);
18
+ }
19
+ }
20
+
12
21
  const cwd = process.cwd();
13
22
  let config;
14
23
  try {
@@ -31,6 +40,17 @@ export default async function run(file) {
31
40
  process.exit(1);
32
41
  }
33
42
 
43
+ // 構文エラーチェック
44
+ const syntaxErrors = diagnose(code);
45
+ if (syntaxErrors.length > 0) {
46
+ const relative = path.relative(cwd, filePath).replace(/\\/g, "/");
47
+ for (const e of syntaxErrors) {
48
+ logger.errorCode("NS1", `${relative}:${e.line}:${e.column} - ${e.message}`);
49
+ }
50
+ logger.error(`Found ${syntaxErrors.length} syntax error(s).`);
51
+ process.exit(1);
52
+ }
53
+
34
54
  const js = convert(code, convertOptions);
35
55
 
36
56
  // ソースファイルと同じディレクトリに一時ファイルを作成する。
package/package.json CHANGED
@@ -1,10 +1,17 @@
1
1
  {
2
2
  "name": "noshift.js",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Joke language.",
5
5
  "bin": {
6
6
  "nsc": "./bin/cli.js"
7
7
  },
8
+ "main": "./src/index.cjs",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./src/index.js",
12
+ "require": "./src/index.cjs"
13
+ }
14
+ },
8
15
  "type": "module",
9
16
  "scripts": {
10
17
  "compile": "node commands/compile.js",