@ngcorex/cli 0.1.3 → 0.1.5
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.md +48 -2
- package/dist/commands/index.js +10 -0
- package/dist/commands/init.js +50 -0
- package/dist/watch/watch-config.js +14 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,6 +39,23 @@ npm install -D @ngcorex/cli
|
|
|
39
39
|
|
|
40
40
|
> The CLI depends on `@ngcorex/css`, which will be installed automatically.
|
|
41
41
|
|
|
42
|
+
### Initialize ngCorex
|
|
43
|
+
|
|
44
|
+
To quickly get started, run:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
ngcorex init
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
This will create:
|
|
51
|
+
|
|
52
|
+
- `tokens.json`
|
|
53
|
+
- `ngcorex.config.ts`
|
|
54
|
+
|
|
55
|
+
If the files already exist, they will not be overwritten.
|
|
56
|
+
|
|
57
|
+
***Or Create files manually:***
|
|
58
|
+
|
|
42
59
|
### Create tokens.json
|
|
43
60
|
|
|
44
61
|
Create a `tokens.json` file at your project root:
|
|
@@ -86,8 +103,27 @@ export default defineNgCorexConfig({
|
|
|
86
103
|
|
|
87
104
|
---
|
|
88
105
|
|
|
106
|
+
## Command Overview
|
|
107
|
+
|
|
108
|
+
The ngCorex CLI supports the following commands:
|
|
109
|
+
|
|
110
|
+
- `ngcorex init` – create starter config and tokens
|
|
111
|
+
- `ngcorex build` – generate CSS from tokens
|
|
112
|
+
- `ngcorex build --watch` – rebuild on file changes
|
|
113
|
+
- `ngcorex build --dry-run` – validate without writing files
|
|
114
|
+
- `ngcorex version` / `--version` / `-v` – print CLI version
|
|
115
|
+
- `ngcorex --help` / `-h` – show help information
|
|
116
|
+
|
|
89
117
|
## Commands
|
|
90
118
|
|
|
119
|
+
### Initialize
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
npx ngcorex init
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
91
127
|
### Build CSS
|
|
92
128
|
|
|
93
129
|
```bash
|
|
@@ -107,8 +143,8 @@ npx ngcorex build --watch
|
|
|
107
143
|
```
|
|
108
144
|
|
|
109
145
|
- Watches `ngcorex.config.ts`
|
|
110
|
-
-
|
|
111
|
-
-
|
|
146
|
+
- Watches `tokens.json` (if present)
|
|
147
|
+
- Rebuilds CSS when either file changes
|
|
112
148
|
|
|
113
149
|
---
|
|
114
150
|
|
|
@@ -134,6 +170,16 @@ Prints the CLI version.
|
|
|
134
170
|
|
|
135
171
|
---
|
|
136
172
|
|
|
173
|
+
### Help
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
npx ngcorex --help
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Prints available commands and usage information.
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
137
183
|
## Output
|
|
138
184
|
|
|
139
185
|
The CLI generates CSS variables based on your tokens and constraints.
|
package/dist/commands/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { buildCommand } from './build.js';
|
|
2
2
|
import { versionCommand } from './version.js';
|
|
3
|
+
import { initCommand } from './init.js';
|
|
3
4
|
export async function runCommand(args) {
|
|
4
5
|
const command = args[0];
|
|
5
6
|
switch (command) {
|
|
@@ -11,6 +12,14 @@ export async function runCommand(args) {
|
|
|
11
12
|
case '-v':
|
|
12
13
|
await versionCommand();
|
|
13
14
|
break;
|
|
15
|
+
case 'init': {
|
|
16
|
+
await initCommand();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
case '--help':
|
|
20
|
+
case '-h':
|
|
21
|
+
printHelp();
|
|
22
|
+
return;
|
|
14
23
|
default:
|
|
15
24
|
printHelp();
|
|
16
25
|
}
|
|
@@ -20,6 +29,7 @@ function printHelp() {
|
|
|
20
29
|
ngCorex CLI
|
|
21
30
|
|
|
22
31
|
Usage:
|
|
32
|
+
ngcorex init Create starter config and tokens
|
|
23
33
|
ngcorex build Generate CSS
|
|
24
34
|
ngcorex build --watch
|
|
25
35
|
ngcorex version Show version
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export async function initCommand() {
|
|
4
|
+
const cwd = process.cwd();
|
|
5
|
+
const tokensPath = path.resolve(cwd, 'tokens.json');
|
|
6
|
+
const configPath = path.resolve(cwd, 'ngcorex.config.ts');
|
|
7
|
+
let createdSomething = false;
|
|
8
|
+
// tokens.json
|
|
9
|
+
if (!fs.existsSync(tokensPath)) {
|
|
10
|
+
fs.writeFileSync(tokensPath, JSON.stringify({
|
|
11
|
+
spacing: {
|
|
12
|
+
"xs": "1rem",
|
|
13
|
+
"sm": "1.25rem"
|
|
14
|
+
},
|
|
15
|
+
colors: {
|
|
16
|
+
gray: {
|
|
17
|
+
"100": "#f3f4f6",
|
|
18
|
+
"900": "#111827"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}, null, 2));
|
|
22
|
+
console.info('✔ Created tokens.json');
|
|
23
|
+
createdSomething = true;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
console.info('i tokens.json already exists — skipped');
|
|
27
|
+
}
|
|
28
|
+
// ngcorex.config.ts
|
|
29
|
+
if (!fs.existsSync(configPath)) {
|
|
30
|
+
fs.writeFileSync(configPath, `import { defineNgCorexConfig } from '@ngcorex/css';
|
|
31
|
+
|
|
32
|
+
export default defineNgCorexConfig({
|
|
33
|
+
output: {
|
|
34
|
+
file: 'src/styles/ngcorex.css'
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
`);
|
|
38
|
+
console.info('✔ Created ngcorex.config.ts');
|
|
39
|
+
createdSomething = true;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
console.info('i ngcorex.config.ts already exists — skipped');
|
|
43
|
+
}
|
|
44
|
+
if (createdSomething) {
|
|
45
|
+
console.info('');
|
|
46
|
+
console.info('Next steps:');
|
|
47
|
+
console.info('- Run `ngcorex build` to generate CSS');
|
|
48
|
+
console.info('- Edit tokens.json to customize your design tokens');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { watch } from 'node:fs';
|
|
1
|
+
import { watch, existsSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
2
3
|
import { resolveConfigPath } from '../config/resolve-path.js';
|
|
3
4
|
export function watchConfig(onChange) {
|
|
4
5
|
const configPath = resolveConfigPath();
|
|
6
|
+
const tokensPath = resolve(process.cwd(), 'tokens.json');
|
|
5
7
|
console.log(`✔ Watching ${configPath}`);
|
|
8
|
+
if (existsSync(tokensPath)) {
|
|
9
|
+
console.log(`✔ Watching ${tokensPath}`);
|
|
10
|
+
}
|
|
6
11
|
let timeout = null;
|
|
7
|
-
|
|
12
|
+
const triggerRebuild = () => {
|
|
8
13
|
if (timeout) {
|
|
9
14
|
clearTimeout(timeout);
|
|
10
15
|
}
|
|
@@ -12,5 +17,11 @@ export function watchConfig(onChange) {
|
|
|
12
17
|
console.log('\n↻ Rebuilding...\n');
|
|
13
18
|
onChange();
|
|
14
19
|
}, 100);
|
|
15
|
-
}
|
|
20
|
+
};
|
|
21
|
+
// Watch config
|
|
22
|
+
watch(configPath, triggerRebuild);
|
|
23
|
+
// Watch tokens.json (if present)
|
|
24
|
+
if (existsSync(tokensPath)) {
|
|
25
|
+
watch(tokensPath, triggerRebuild);
|
|
26
|
+
}
|
|
16
27
|
}
|