@appling/cli 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alexandros Fotiadis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,59 @@
1
- # Temporary Holding Version
1
+ # @appling/cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Command line tool to check and format Appling models (`.appling` files).
4
+
5
+ Appling is a declarative language that describes a business or web application in five layers: domain, behavior, application, interfaces and experience. The language itself lives in [`@appling/lang`](https://www.npmjs.com/package/@appling/lang).
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install --save-dev @appling/cli
11
+ ```
12
+
13
+ Or run it without installing:
14
+
15
+ ```sh
16
+ npx @appling/cli check models
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```sh
22
+ appling check [files or folders...]
23
+ appling fmt [files or folders...]
24
+ ```
25
+
26
+ Folders are searched recursively for `.appling` files. Hidden folders and `node_modules` are skipped. Without a path, the current folder is used.
27
+
28
+ All files are loaded as one workspace, so references between modules resolve across files.
29
+
30
+ ### check
31
+
32
+ Parses, links and validates every file and prints one line per problem:
33
+
34
+ ```
35
+ models/sales.appling:13:23 error A machine must govern an entity field marked "state" with an enum type.
36
+ 2 file(s), 1 error(s)
37
+ ```
38
+
39
+ ### fmt
40
+
41
+ Rewrites every file into its canonical form:
42
+
43
+ - Gives every element without a stable id a new one, such as `entity Order #1kzox`.
44
+ - Normalizes whitespace, indentation and line breaks. Comments are kept.
45
+ - Running it twice changes nothing.
46
+
47
+ Files with syntax errors are left untouched and reported.
48
+
49
+ ## Exit codes
50
+
51
+ | Code | Meaning |
52
+ |---|---|
53
+ | 0 | No errors |
54
+ | 1 | `check` found errors, or `fmt` skipped a file with syntax errors |
55
+ | 2 | Unknown command |
56
+
57
+ ## License
58
+
59
+ MIT
package/out/main.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/out/main.js ADDED
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env node
2
+ import { randomBytes } from 'node:crypto';
3
+ import { readdirSync, statSync, writeFileSync } from 'node:fs';
4
+ import { join, relative, resolve } from 'node:path';
5
+ import { AstUtils, URI } from 'langium';
6
+ import { NodeFileSystem } from 'langium/node';
7
+ import { createApplingServices, hasStableId, print } from '@appling/lang';
8
+ const USAGE = 'Usage: appling <check|fmt> [files or folders...]';
9
+ async function main([command, ...paths]) {
10
+ if (command !== 'check' && command !== 'fmt') {
11
+ console.error(USAGE);
12
+ return 2;
13
+ }
14
+ const files = (paths.length ? paths : ['.']).flatMap(p => applingFiles(resolve(p)));
15
+ const { shared } = createApplingServices(NodeFileSystem);
16
+ const documents = await Promise.all(files.map(f => shared.workspace.LangiumDocuments.getOrCreateDocument(URI.file(f))));
17
+ await shared.workspace.DocumentBuilder.build(documents, { validation: command === 'check' });
18
+ return command === 'check' ? check(documents) : format(documents);
19
+ }
20
+ function check(documents) {
21
+ let errors = 0;
22
+ for (const doc of documents) {
23
+ for (const d of doc.diagnostics ?? []) {
24
+ const severity = d.severity === 1 ? 'error' : 'warning';
25
+ if (severity === 'error')
26
+ errors++;
27
+ console.log(`${relative('.', doc.uri.fsPath)}:${d.range.start.line + 1}:${d.range.start.character + 1} ${severity} ${d.message}`);
28
+ }
29
+ }
30
+ console.log(`${documents.length} file(s), ${errors} error(s)`);
31
+ return errors ? 1 : 0;
32
+ }
33
+ function format(documents) {
34
+ const used = new Set(documents.flatMap(doc => AstUtils.streamAst(doc.parseResult.value)
35
+ .filter(hasStableId)
36
+ .map(n => n.id)
37
+ .toArray()));
38
+ const newId = () => {
39
+ let id;
40
+ do
41
+ id = '#' + randomBytes(4).readUInt32BE().toString(36).padStart(7, '0').slice(-5);
42
+ while (used.has(id));
43
+ used.add(id);
44
+ return id;
45
+ };
46
+ let failed = 0;
47
+ for (const doc of documents) {
48
+ const { lexerErrors, parserErrors } = doc.parseResult;
49
+ if (lexerErrors.length || parserErrors.length) {
50
+ failed++;
51
+ console.error(`${relative('.', doc.uri.fsPath)}: not formatted, fix syntax errors first (run "appling check")`);
52
+ continue;
53
+ }
54
+ const text = print(doc.parseResult.value, newId);
55
+ if (text !== doc.textDocument.getText()) {
56
+ writeFileSync(doc.uri.fsPath, text);
57
+ console.log(`formatted ${relative('.', doc.uri.fsPath)}`);
58
+ }
59
+ }
60
+ return failed ? 1 : 0;
61
+ }
62
+ function applingFiles(path) {
63
+ if (!statSync(path).isDirectory())
64
+ return [path];
65
+ return readdirSync(path, { withFileTypes: true })
66
+ .filter(e => !e.name.startsWith('.') && e.name !== 'node_modules')
67
+ .flatMap(e => e.isDirectory() ? applingFiles(join(path, e.name)) : e.name.endsWith('.appling') ? [join(path, e.name)] : []);
68
+ }
69
+ main(process.argv.slice(2)).then(code => process.exit(code));
package/package.json CHANGED
@@ -1,6 +1,27 @@
1
1
  {
2
2
  "name": "@appling/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Command line tool to check and format Appling models",
5
+ "type": "module",
6
+ "bin": {
7
+ "appling": "./out/main.js"
8
+ },
9
+ "files": [
10
+ "out"
11
+ ],
12
+ "dependencies": {
13
+ "@appling/lang": "0.1.1",
14
+ "langium": "4.4.0"
15
+ },
16
+ "devDependencies": {
17
+ "@types/node": "^24.19.2",
18
+ "typescript": "7.0.2"
19
+ },
20
+ "license": "MIT",
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "scripts": {
25
+ "build": "tsc"
26
+ }
6
27
  }