@editora/cli 1.0.2 → 1.0.3
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 +75 -0
- package/bin/editora.js +154 -38
- package/dist/index.cjs +3 -0
- package/dist/index.mjs +16 -0
- package/package.json +18 -3
package/README.md
CHANGED
|
@@ -7,6 +7,71 @@
|
|
|
7
7
|
|
|
8
8
|
Official CLI for quickly adding Editora packages.
|
|
9
9
|
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Install globally (makes the `editora` command available system-wide):
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install -g @editora/cli
|
|
16
|
+
# or
|
|
17
|
+
pnpm add -g @editora/cli
|
|
18
|
+
# or
|
|
19
|
+
yarn global add @editora/cli
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
One-off usage without installing (recommended for CI or quick runs):
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npx @editora/cli add button
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Verify the CLI is available:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
editora --version
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Shortcuts
|
|
35
|
+
|
|
36
|
+
- **Add multiple components:** `npx @editora/cli add button modal toast`
|
|
37
|
+
- **Dry run:** `npx @editora/cli add editor --dry-run` (prints the install command)
|
|
38
|
+
- **Force package manager:** `npx @editora/cli add button --package-manager pnpm`
|
|
39
|
+
- **Make a quick alias (optional):** install globally and add an alias to your shell:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install -g @editora/cli
|
|
43
|
+
echo "alias ed='editora'" >> ~/.zshrc # or ~/.bashrc
|
|
44
|
+
source ~/.zshrc
|
|
45
|
+
ed add button
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Boilerplates
|
|
49
|
+
|
|
50
|
+
Common usage examples and what they install:
|
|
51
|
+
|
|
52
|
+
- Install a single UI component (React wrappers):
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npx @editora/cli add button
|
|
56
|
+
# installs: @editora/ui-react
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
- Install the full React editor stack:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npx @editora/cli add editor
|
|
63
|
+
# installs: @editora/react @editora/plugins @editora/themes
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- Install everything used by the React + UI stack:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npx @editora/cli add all
|
|
70
|
+
# installs: @editora/ui-react @editora/toast @editora/react @editora/plugins @editora/themes @editora/react-icons @editora/light-code-editor
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Use `--dry-run` to verify the exact command before executing, and `--package-manager` to force `npm`, `pnpm`, `yarn`, or `bun`.
|
|
74
|
+
|
|
10
75
|
## Usage
|
|
11
76
|
|
|
12
77
|
```bash
|
|
@@ -26,6 +91,16 @@ npx @editora/cli add react-icons
|
|
|
26
91
|
npx @editora/cli add light-code-editor
|
|
27
92
|
npx @editora/cli add all
|
|
28
93
|
npx @editora/cli add editor --dry-run
|
|
94
|
+
npx @editora/cli add button --package-manager pnpm
|
|
95
|
+
npx @editora/cli --help
|
|
96
|
+
npx @editora/cli --version
|
|
29
97
|
```
|
|
30
98
|
|
|
31
99
|
Any exported `@editora/ui-react` component name is accepted by `editora add`.
|
|
100
|
+
|
|
101
|
+
## Notes
|
|
102
|
+
|
|
103
|
+
- `--dry-run` prints the install command without executing it.
|
|
104
|
+
- `--package-manager <npm|pnpm|yarn|bun>` forces the package manager.
|
|
105
|
+
- `--help` shows usage instructions.
|
|
106
|
+
- `--version` prints the CLI version.
|
package/bin/editora.js
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
/* eslint-disable no-console */
|
|
4
4
|
const { spawnSync } = require("child_process");
|
|
5
|
+
const packageJson = require("../package.json");
|
|
5
6
|
|
|
6
7
|
const helpText = `
|
|
7
8
|
Editora CLI
|
|
8
9
|
|
|
9
10
|
Usage:
|
|
10
|
-
editora add <feature> [feature...] [--dry-run]
|
|
11
|
+
editora add <feature> [feature...] [--dry-run] [--package-manager <npm|pnpm|yarn|bun>]
|
|
11
12
|
|
|
12
13
|
Examples:
|
|
13
14
|
npx @editora/cli add button
|
|
@@ -18,6 +19,12 @@ Examples:
|
|
|
18
19
|
npx @editora/cli add accordion avatar select
|
|
19
20
|
npx @editora/cli add ui-accordion ui-select
|
|
20
21
|
npx @editora/cli add button modal toast
|
|
22
|
+
|
|
23
|
+
Options:
|
|
24
|
+
--dry-run Print the generated install command without executing it
|
|
25
|
+
--package-manager <pm> Force a specific package manager (npm, pnpm, yarn, bun)
|
|
26
|
+
-h, --help Show this help text
|
|
27
|
+
--version Print CLI version
|
|
21
28
|
`;
|
|
22
29
|
|
|
23
30
|
const uiReactComponents = [
|
|
@@ -157,15 +164,8 @@ function normalizeTarget(value) {
|
|
|
157
164
|
.replace(/[^a-z0-9]/g, "");
|
|
158
165
|
}
|
|
159
166
|
|
|
160
|
-
const uiReactLookup = new Map();
|
|
161
|
-
|
|
162
|
-
uiReactLookup.set(normalizeTarget(name), name);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const specialLookup = new Map();
|
|
166
|
-
for (const name of Object.keys(specialRegistry)) {
|
|
167
|
-
specialLookup.set(normalizeTarget(name), name);
|
|
168
|
-
}
|
|
167
|
+
const uiReactLookup = new Map(uiReactComponents.map((name) => [normalizeTarget(name), name]));
|
|
168
|
+
const specialLookup = new Map(Object.keys(specialRegistry).map((name) => [normalizeTarget(name), name]));
|
|
169
169
|
|
|
170
170
|
function resolveTarget(rawTarget) {
|
|
171
171
|
const isExplicitUiTarget = /^ui[-_]/i.test(rawTarget.trim());
|
|
@@ -203,6 +203,8 @@ function resolveTarget(rawTarget) {
|
|
|
203
203
|
return null;
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
+
const SUPPORTED_PACKAGE_MANAGERS = new Set(["npm", "pnpm", "yarn", "bun"]);
|
|
207
|
+
|
|
206
208
|
function detectPackageManager() {
|
|
207
209
|
const userAgent = process.env.npm_config_user_agent || "";
|
|
208
210
|
if (userAgent.startsWith("pnpm")) return "pnpm";
|
|
@@ -218,45 +220,139 @@ function installCommand(pm, packages) {
|
|
|
218
220
|
return ["npm", ["install", ...packages]];
|
|
219
221
|
}
|
|
220
222
|
|
|
221
|
-
function
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
223
|
+
function parseArgs(argv) {
|
|
224
|
+
const parsed = {
|
|
225
|
+
command: null,
|
|
226
|
+
targets: [],
|
|
227
|
+
dryRun: false,
|
|
228
|
+
packageManager: undefined,
|
|
229
|
+
help: false,
|
|
230
|
+
version: false,
|
|
231
|
+
unknownOptions: []
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
if (!argv || argv.length === 0) {
|
|
235
|
+
return parsed;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (argv[0] === "-h" || argv[0] === "--help") {
|
|
239
|
+
parsed.help = true;
|
|
240
|
+
return parsed;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (argv[0] === "--version") {
|
|
244
|
+
parsed.version = true;
|
|
245
|
+
return parsed;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
parsed.command = argv[0];
|
|
249
|
+
|
|
250
|
+
let index = 1;
|
|
251
|
+
while (index < argv.length) {
|
|
252
|
+
const arg = argv[index];
|
|
253
|
+
|
|
254
|
+
if (arg === "--dry-run") {
|
|
255
|
+
parsed.dryRun = true;
|
|
256
|
+
index += 1;
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (arg === "-h" || arg === "--help") {
|
|
261
|
+
parsed.help = true;
|
|
262
|
+
index += 1;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (arg === "--version") {
|
|
267
|
+
parsed.version = true;
|
|
268
|
+
index += 1;
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (arg.startsWith("--package-manager")) {
|
|
273
|
+
const [flag, value] = arg.split("=");
|
|
274
|
+
if (value) {
|
|
275
|
+
parsed.packageManager = value;
|
|
276
|
+
index += 1;
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const next = argv[index + 1];
|
|
281
|
+
if (next && !next.startsWith("-")) {
|
|
282
|
+
parsed.packageManager = next;
|
|
283
|
+
index += 2;
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
parsed.unknownOptions.push(arg);
|
|
288
|
+
index += 1;
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (arg.startsWith("--")) {
|
|
293
|
+
parsed.unknownOptions.push(arg);
|
|
294
|
+
index += 1;
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
parsed.targets.push(arg);
|
|
299
|
+
index += 1;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return parsed;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function formatHelpText() {
|
|
306
|
+
return helpText.trim();
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function getVersion() {
|
|
310
|
+
return packageJson.version;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function run(argv) {
|
|
314
|
+
const args = parseArgs(argv);
|
|
315
|
+
|
|
316
|
+
if (args.help || !argv || argv.length === 0) {
|
|
317
|
+
console.log(formatHelpText());
|
|
318
|
+
return 0;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (args.version) {
|
|
322
|
+
console.log(getVersion());
|
|
323
|
+
return 0;
|
|
226
324
|
}
|
|
227
325
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
326
|
+
if (args.unknownOptions.length > 0) {
|
|
327
|
+
console.error(`Unknown option(s): ${args.unknownOptions.join(", ")}`);
|
|
328
|
+
console.log(formatHelpText());
|
|
329
|
+
return 1;
|
|
330
|
+
}
|
|
231
331
|
|
|
232
|
-
if (command !== "add") {
|
|
233
|
-
console.error(`Unknown command: ${command}`);
|
|
234
|
-
console.log(
|
|
235
|
-
|
|
332
|
+
if (args.command !== "add") {
|
|
333
|
+
console.error(`Unknown command: ${args.command || "<missing>"}`);
|
|
334
|
+
console.log(formatHelpText());
|
|
335
|
+
return 1;
|
|
236
336
|
}
|
|
237
337
|
|
|
238
|
-
|
|
239
|
-
if (targets.length === 0) {
|
|
338
|
+
if (args.targets.length === 0) {
|
|
240
339
|
console.error("Missing feature name(s).");
|
|
241
|
-
console.log(
|
|
242
|
-
|
|
340
|
+
console.log(formatHelpText());
|
|
341
|
+
return 1;
|
|
243
342
|
}
|
|
244
343
|
|
|
245
|
-
const resolvedTargets = targets.map((target) => ({
|
|
344
|
+
const resolvedTargets = args.targets.map((target) => ({
|
|
246
345
|
input: target,
|
|
247
346
|
resolved: resolveTarget(target)
|
|
248
347
|
}));
|
|
249
348
|
|
|
250
|
-
const unknown = resolvedTargets
|
|
251
|
-
.filter((item) => !item.resolved)
|
|
252
|
-
.map((item) => item.input);
|
|
253
|
-
|
|
349
|
+
const unknown = resolvedTargets.filter((item) => !item.resolved).map((item) => item.input);
|
|
254
350
|
if (unknown.length > 0) {
|
|
255
351
|
console.error(`Unknown feature(s): ${unknown.join(", ")}`);
|
|
256
352
|
console.error("Supported:");
|
|
257
353
|
console.error("- all exported @editora/ui-react component names");
|
|
258
354
|
console.error(`- special: ${Object.keys(specialRegistry).sort().join(", ")}`);
|
|
259
|
-
|
|
355
|
+
return 1;
|
|
260
356
|
}
|
|
261
357
|
|
|
262
358
|
const packageSet = new Set();
|
|
@@ -265,22 +361,42 @@ function main() {
|
|
|
265
361
|
}
|
|
266
362
|
const packages = Array.from(packageSet);
|
|
267
363
|
|
|
268
|
-
const pm = detectPackageManager();
|
|
364
|
+
const pm = args.packageManager || detectPackageManager();
|
|
365
|
+
if (!SUPPORTED_PACKAGE_MANAGERS.has(pm)) {
|
|
366
|
+
console.error(`Unsupported package manager: ${pm}`);
|
|
367
|
+
return 1;
|
|
368
|
+
}
|
|
369
|
+
|
|
269
370
|
const [cmd, cmdArgs] = installCommand(pm, packages);
|
|
270
371
|
|
|
271
|
-
console.log(`\nEditora add targets: ${targets.join(", ")}`);
|
|
372
|
+
console.log(`\nEditora add targets: ${args.targets.join(", ")}`);
|
|
272
373
|
for (const item of resolvedTargets) {
|
|
273
374
|
console.log(`- ${item.resolved.canonicalName}: ${item.resolved.entry.note}`);
|
|
274
375
|
}
|
|
275
376
|
console.log(`\nInstalling with ${pm}: ${[cmd, ...cmdArgs].join(" ")}`);
|
|
276
377
|
|
|
277
|
-
if (dryRun) {
|
|
378
|
+
if (args.dryRun) {
|
|
278
379
|
console.log("\nDry run enabled. No packages were installed.");
|
|
279
|
-
|
|
380
|
+
return 0;
|
|
280
381
|
}
|
|
281
382
|
|
|
282
383
|
const result = spawnSync(cmd, cmdArgs, { stdio: "inherit" });
|
|
283
|
-
|
|
384
|
+
return result.status == null ? 1 : result.status;
|
|
284
385
|
}
|
|
285
386
|
|
|
286
|
-
main
|
|
387
|
+
if (require.main === module) {
|
|
388
|
+
process.exit(run(process.argv.slice(2)));
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
module.exports = {
|
|
392
|
+
normalizeTarget,
|
|
393
|
+
resolveTarget,
|
|
394
|
+
detectPackageManager,
|
|
395
|
+
installCommand,
|
|
396
|
+
parseArgs,
|
|
397
|
+
run,
|
|
398
|
+
getVersion,
|
|
399
|
+
formatHelpText,
|
|
400
|
+
uiReactComponents,
|
|
401
|
+
specialRegistry
|
|
402
|
+
};
|
package/dist/index.cjs
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// ESM programmatic entrypoint — load the existing CommonJS implementation
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
const cli = require('../bin/editora.js');
|
|
5
|
+
|
|
6
|
+
export const run = cli.run;
|
|
7
|
+
export const parseArgs = cli.parseArgs;
|
|
8
|
+
export const resolveTarget = cli.resolveTarget;
|
|
9
|
+
export const detectPackageManager = cli.detectPackageManager;
|
|
10
|
+
export const installCommand = cli.installCommand;
|
|
11
|
+
export const getVersion = cli.getVersion;
|
|
12
|
+
export const formatHelpText = cli.formatHelpText;
|
|
13
|
+
export const uiReactComponents = cli.uiReactComponents;
|
|
14
|
+
export const specialRegistry = cli.specialRegistry;
|
|
15
|
+
|
|
16
|
+
export default cli;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@editora/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Official Editora CLI for quickly adding UI components, editor packages, and SaaS-ready building blocks.",
|
|
5
5
|
"author": "Ajay Kumar <ajaykr089@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/ajaykr089/Editora.git",
|
|
9
|
+
"url": "git+https://github.com/ajaykr089/Editora.git",
|
|
10
10
|
"directory": "packages/cli"
|
|
11
11
|
},
|
|
12
12
|
"homepage": "https://editora-ecosystem.netlify.app/docs/reference/cli",
|
|
@@ -16,15 +16,27 @@
|
|
|
16
16
|
"bin": {
|
|
17
17
|
"editora": "bin/editora.js"
|
|
18
18
|
},
|
|
19
|
+
"main": "dist/index.cjs",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"require": "./dist/index.cjs",
|
|
23
|
+
"import": "./dist/index.mjs",
|
|
24
|
+
"default": "./dist/index.cjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"preferGlobal": true,
|
|
19
28
|
"files": [
|
|
20
29
|
"bin",
|
|
30
|
+
"dist",
|
|
21
31
|
"README.md"
|
|
22
32
|
],
|
|
23
33
|
"scripts": {
|
|
24
34
|
"build": "node -e \"console.log('editora cli: no build step required')\"",
|
|
25
35
|
"dev": "node -e \"console.log('editora cli: no dev server')\"",
|
|
26
36
|
"clean": "node -e \"console.log('editora cli: no artifacts to clean')\"",
|
|
27
|
-
"
|
|
37
|
+
"lint": "node --check ./bin/editora.js",
|
|
38
|
+
"test": "node --test ./test/cli.test.js",
|
|
39
|
+
"prepublishOnly": "npm test"
|
|
28
40
|
},
|
|
29
41
|
"keywords": [
|
|
30
42
|
"editora",
|
|
@@ -41,5 +53,8 @@
|
|
|
41
53
|
"publishConfig": {
|
|
42
54
|
"access": "public"
|
|
43
55
|
},
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=16.0.0"
|
|
58
|
+
},
|
|
44
59
|
"gitHead": "7883627e823aa99dd5ecb66a5201116df972f88b"
|
|
45
60
|
}
|