@ngcorex/cli 0.1.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/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ajay Kumar Sharma
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,136 @@
1
+ # @ngcorex/cli
2
+
3
+ Command-line interface for **ngCorex**.
4
+
5
+ This package provides the `ngcorex` CLI used to build CSS from an
6
+ `ngcorex.config.ts` file using the ngCorex engine.
7
+
8
+ It is intended to be installed as a development dependency in projects
9
+ that use ngCorex.
10
+
11
+ ---
12
+
13
+ ## What This CLI Does
14
+
15
+ The ngCorex CLI:
16
+
17
+ - loads `ngcorex.config.ts`
18
+ - validates design tokens
19
+ - applies constraints
20
+ - generates CSS variables
21
+ - writes the output CSS file
22
+ - supports watch mode and dry runs
23
+
24
+ All work happens **at build time**.
25
+
26
+ ---
27
+
28
+ ## Installation
29
+
30
+ Install the CLI as a dev dependency:
31
+
32
+ ```bash
33
+ npm install --save-dev @ngcorex/cli
34
+ ````
35
+
36
+ > The CLI depends on `@ngcorex/css`, which will be installed automatically.
37
+
38
+ ---
39
+
40
+ ## Commands
41
+
42
+ ### Build CSS
43
+
44
+ ```bash
45
+ npx ngcorex build
46
+ ```
47
+
48
+ * Loads `ngcorex.config.ts`
49
+ * Generates CSS output
50
+ * Writes the output file
51
+
52
+ ---
53
+
54
+ ### Watch Mode
55
+
56
+ ```bash
57
+ npx ngcorex build --watch
58
+ ```
59
+
60
+ * Watches `ngcorex.config.ts`
61
+ * Rebuilds on change
62
+ * Does not exit on errors
63
+
64
+ ---
65
+
66
+ ### Dry Run
67
+
68
+ ```bash
69
+ npx ngcorex build --dry-run
70
+ ```
71
+
72
+ * Runs the full pipeline
73
+ * Does NOT write any files
74
+ * Useful for testing configuration
75
+
76
+ ---
77
+
78
+ ### Version
79
+
80
+ ```bash
81
+ npx ngcorex version
82
+ ```
83
+
84
+ Prints the CLI version.
85
+
86
+ ---
87
+
88
+ ## Configuration File
89
+
90
+ The CLI expects a file named:
91
+
92
+ ```
93
+ ngcorex.config.ts
94
+ ```
95
+
96
+ ### Example
97
+
98
+ ```ts
99
+ import { defineNgCorexConfig } from '@ngcorex/css';
100
+
101
+ export default defineNgCorexConfig({
102
+ tokens: {
103
+ spacing: {
104
+ 1: 4,
105
+ 2: 8
106
+ }
107
+ }
108
+ });
109
+ ```
110
+
111
+ ### Important Rules
112
+
113
+ * The config file **must import from npm packages only**
114
+ * Relative imports are **not allowed**
115
+ * The config is transpiled internally using esbuild
116
+
117
+ ---
118
+
119
+ ## Output
120
+
121
+ The CLI generates CSS variables based on your tokens and constraints.
122
+
123
+ Example output:
124
+
125
+ ```css
126
+ :root {
127
+ --spacing-1: 4px;
128
+ --spacing-2: 8px;
129
+ }
130
+ ```
131
+
132
+ ---
133
+
134
+ ## License
135
+
136
+ MIT
package/dist/bin.js ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ import { runCommand } from './commands/index.js';
3
+ import { handleCliError } from './utils/logger.js';
4
+ async function main() {
5
+ const args = process.argv.slice(2);
6
+ try {
7
+ await runCommand(args);
8
+ }
9
+ catch (error) {
10
+ handleCliError(error);
11
+ process.exit(1);
12
+ }
13
+ }
14
+ main();
@@ -0,0 +1,27 @@
1
+ import { runBuild } from './run-build.js';
2
+ import { watchConfig } from '../watch/watch-config.js';
3
+ export async function buildCommand(args) {
4
+ const watch = args.indexOf('--watch') !== -1;
5
+ const dryRun = args.indexOf('--dry-run') !== -1;
6
+ if (watch) {
7
+ // initial build
8
+ try {
9
+ await runBuild({ dryRun });
10
+ }
11
+ catch (error) {
12
+ console.error(error instanceof Error ? error.message : error);
13
+ }
14
+ // watch mode
15
+ watchConfig(async () => {
16
+ try {
17
+ await runBuild({ dryRun });
18
+ }
19
+ catch (error) {
20
+ console.error(error instanceof Error ? error.message : error);
21
+ }
22
+ });
23
+ return;
24
+ }
25
+ // single build
26
+ await runBuild({ dryRun });
27
+ }
@@ -0,0 +1,27 @@
1
+ import { buildCommand } from './build.js';
2
+ import { versionCommand } from './version.js';
3
+ export async function runCommand(args) {
4
+ const command = args[0];
5
+ switch (command) {
6
+ case 'build':
7
+ await buildCommand(args.slice(1));
8
+ break;
9
+ case 'version':
10
+ case '--version':
11
+ case '-v':
12
+ await versionCommand();
13
+ break;
14
+ default:
15
+ printHelp();
16
+ }
17
+ }
18
+ function printHelp() {
19
+ console.log(`
20
+ ngCorex CLI
21
+
22
+ Usage:
23
+ ngcorex build Generate CSS
24
+ ngcorex build --watch
25
+ ngcorex version Show version
26
+ `);
27
+ }
@@ -0,0 +1,18 @@
1
+ import { resolveConfigPath } from '../config/resolve-path.js';
2
+ import { loadConfig } from '../config/load-config.js';
3
+ import { writeCss } from '../output/write-css.js';
4
+ import { buildCssFromConfig } from '@ngcorex/css';
5
+ import { resolve } from 'node:path';
6
+ export async function runBuild(options = {}) {
7
+ const configPath = resolveConfigPath();
8
+ const config = await loadConfig(configPath);
9
+ console.log('✔ Loaded ngcorex.config.ts');
10
+ const css = buildCssFromConfig(config);
11
+ console.log('✔ Generated CSS');
12
+ const outputFile = config.output?.file ?? 'src/styles/ngcorex.css';
13
+ const outputPath = resolve(process.cwd(), outputFile);
14
+ writeCss(outputPath, css, { dryRun: options.dryRun });
15
+ if (!options.dryRun) {
16
+ console.log(`✔ Output written to ${outputFile}`);
17
+ }
18
+ }
@@ -0,0 +1,9 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { dirname, join } from 'node:path';
4
+ export async function versionCommand() {
5
+ const __dirname = dirname(fileURLToPath(import.meta.url));
6
+ const pkgPath = join(__dirname, '../../package.json');
7
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
8
+ console.log(`ngCorex v${pkg.version}`);
9
+ }
@@ -0,0 +1,24 @@
1
+ import { build } from 'esbuild';
2
+ import { pathToFileURL } from 'node:url';
3
+ import { mkdirSync } from 'node:fs';
4
+ import { join } from 'node:path';
5
+ export async function loadConfig(configPath) {
6
+ const cacheDir = join(process.cwd(), '.ngcorex');
7
+ const outFile = join(cacheDir, 'config.mjs');
8
+ // ensure cache dir exists
9
+ mkdirSync(cacheDir, { recursive: true });
10
+ // transpile config to real file
11
+ await build({
12
+ entryPoints: [configPath],
13
+ outfile: outFile,
14
+ bundle: true,
15
+ platform: 'node',
16
+ format: 'esm',
17
+ target: 'node18'
18
+ });
19
+ const module = await import(pathToFileURL(outFile).href + `?t=${Date.now()}`);
20
+ if (!module.default) {
21
+ throw new Error('ngcorex.config.ts must export a default configuration');
22
+ }
23
+ return module.default;
24
+ }
@@ -0,0 +1,11 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+ export function resolveConfigPath(customPath) {
4
+ const path = customPath
5
+ ? resolve(process.cwd(), customPath)
6
+ : resolve(process.cwd(), 'ngcorex.config.ts');
7
+ if (!existsSync(path)) {
8
+ throw new Error(`ngCorex config not found at ${path}`);
9
+ }
10
+ return path;
11
+ }
@@ -0,0 +1,11 @@
1
+ import { mkdirSync, writeFileSync } from 'node:fs';
2
+ import { dirname } from 'node:path';
3
+ export function writeCss(filePath, css, options = {}) {
4
+ if (options.dryRun) {
5
+ console.log(`ℹ Dry run – skipping write to ${filePath}`);
6
+ return;
7
+ }
8
+ const dir = dirname(filePath);
9
+ mkdirSync(dir, { recursive: true });
10
+ writeFileSync(filePath, css, 'utf-8');
11
+ }
@@ -0,0 +1,8 @@
1
+ export function handleCliError(error) {
2
+ if (error instanceof Error) {
3
+ console.error(`✖ ${error.message}`);
4
+ }
5
+ else {
6
+ console.error('✖ Unknown error');
7
+ }
8
+ }
@@ -0,0 +1,16 @@
1
+ import { watch } from 'node:fs';
2
+ import { resolveConfigPath } from '../config/resolve-path.js';
3
+ export function watchConfig(onChange) {
4
+ const configPath = resolveConfigPath();
5
+ console.log(`✔ Watching ${configPath}`);
6
+ let timeout = null;
7
+ watch(configPath, () => {
8
+ if (timeout) {
9
+ clearTimeout(timeout);
10
+ }
11
+ timeout = setTimeout(() => {
12
+ console.log('\n↻ Rebuilding...\n');
13
+ onChange();
14
+ }, 100);
15
+ });
16
+ }
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@ngcorex/cli",
3
+ "version": "0.1.0",
4
+ "description": "CLI for ngCorex - Angular-native design token engine",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "bin": {
8
+ "ngcorex": "dist/bin.js"
9
+ },
10
+ "dependencies": {
11
+ "@ngcorex/css": "^0.1.0"
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "README.md",
16
+ "LICENSE.md"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsc -p tsconfig.json"
20
+ }
21
+ }