create-middag-ui 0.13.0 → 0.15.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.md +13 -0
- package/cli.js +38 -12
- package/lib/scaffold.js +15 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,6 +18,19 @@ Or specify a custom directory:
|
|
|
18
18
|
npx create-middag-ui mydir
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
### Non-interactive mode
|
|
22
|
+
|
|
23
|
+
Skip all prompts with `--yes` (uses defaults: `ui/`, public registry):
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx create-middag-ui --yes
|
|
27
|
+
|
|
28
|
+
# PRO path (GitHub Packages) without prompts:
|
|
29
|
+
npx create-middag-ui --yes --github
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Host platform and Moodle component are still auto-detected. Only interactive prompts are skipped.
|
|
33
|
+
|
|
21
34
|
Run from your plugin project root. The wizard:
|
|
22
35
|
|
|
23
36
|
1. **Auto-detects your host** — finds `version.php` (Moodle) or `wp-config.php` (WordPress)
|
package/cli.js
CHANGED
|
@@ -54,6 +54,17 @@ const TOTAL_STEPS = 10;
|
|
|
54
54
|
const cwd = process.cwd();
|
|
55
55
|
const startTime = Date.now();
|
|
56
56
|
|
|
57
|
+
// ── Parse CLI flags ─────────────────────────────────────────────────────
|
|
58
|
+
|
|
59
|
+
const argv = process.argv.slice(2);
|
|
60
|
+
const flags = new Set(argv.filter((a) => a.startsWith("-")));
|
|
61
|
+
const positional = argv.filter((a) => !a.startsWith("-"));
|
|
62
|
+
|
|
63
|
+
/** --yes / -y: skip all prompts, use defaults (ui/, public registry). */
|
|
64
|
+
const nonInteractive = flags.has("--yes") || flags.has("-y");
|
|
65
|
+
/** --github: in non-interactive mode, use GitHub Packages instead of public. */
|
|
66
|
+
const forceGitHub = flags.has("--github");
|
|
67
|
+
|
|
57
68
|
blank();
|
|
58
69
|
log("Initializing MIDDAG React UI...\n");
|
|
59
70
|
|
|
@@ -64,6 +75,9 @@ heading(1, TOTAL_STEPS, "Detecting host platform");
|
|
|
64
75
|
let hostKey = detectHost(cwd);
|
|
65
76
|
if (hostKey) {
|
|
66
77
|
success(`Detected: ${HOSTS[hostKey].name} (found ${HOSTS[hostKey].detect})`);
|
|
78
|
+
} else if (nonInteractive) {
|
|
79
|
+
hostKey = "custom";
|
|
80
|
+
success(`Default: ${HOSTS[hostKey].name} (--yes mode)`);
|
|
67
81
|
} else {
|
|
68
82
|
info("Could not auto-detect host platform.");
|
|
69
83
|
hostKey = await select("Select platform", [
|
|
@@ -82,6 +96,9 @@ if (hostKey === "moodle") {
|
|
|
82
96
|
moodleComponent = detectMoodleComponent(cwd);
|
|
83
97
|
if (moodleComponent) {
|
|
84
98
|
success(`Moodle component: ${ moodleComponent }`);
|
|
99
|
+
} else if (nonInteractive) {
|
|
100
|
+
moodleComponent = "local_myplugin";
|
|
101
|
+
success(`Default component: ${ moodleComponent } (--yes mode)`);
|
|
85
102
|
} else {
|
|
86
103
|
info("Could not detect Moodle component from version.php");
|
|
87
104
|
const answer = await ask(" Frankenstyle component (e.g. local_yourplugin): ");
|
|
@@ -94,12 +111,15 @@ if (hostKey === "moodle") {
|
|
|
94
111
|
|
|
95
112
|
heading(2, TOTAL_STEPS, "Target directory");
|
|
96
113
|
|
|
97
|
-
const cliArg =
|
|
114
|
+
const cliArg = positional[0];
|
|
98
115
|
let dirName;
|
|
99
116
|
|
|
100
|
-
if (cliArg
|
|
117
|
+
if (cliArg) {
|
|
101
118
|
dirName = cliArg;
|
|
102
119
|
success(`Using directory from argument: ${dirName}/`);
|
|
120
|
+
} else if (nonInteractive) {
|
|
121
|
+
dirName = "ui";
|
|
122
|
+
success(`Default: ${dirName}/ (--yes mode)`);
|
|
103
123
|
} else {
|
|
104
124
|
const answer = await ask(` Directory name (default: ui): `);
|
|
105
125
|
dirName = answer || "ui";
|
|
@@ -112,18 +132,24 @@ const targetDir = join(cwd, dirName);
|
|
|
112
132
|
|
|
113
133
|
heading(3, TOTAL_STEPS, "Registry configuration");
|
|
114
134
|
|
|
115
|
-
info("@middag-io/react can be installed from:");
|
|
116
|
-
info(" a) GitHub Packages (with source maps, requires token)");
|
|
117
|
-
info(" b) npm public registry (compiled only, no auth needed)");
|
|
118
|
-
blank();
|
|
119
|
-
|
|
120
|
-
const hasGitHubAccess = await confirm("Do you have GitHub access to middag-io?", false);
|
|
121
|
-
|
|
122
135
|
let registryPath = "public";
|
|
123
|
-
|
|
124
|
-
|
|
136
|
+
|
|
137
|
+
if (nonInteractive) {
|
|
138
|
+
registryPath = forceGitHub ? "github" : "public";
|
|
139
|
+
success(`Using ${registryPath === "github" ? "GitHub Packages" : "npm public"} registry (--yes mode)`);
|
|
125
140
|
} else {
|
|
126
|
-
|
|
141
|
+
info("@middag-io/react can be installed from:");
|
|
142
|
+
info(" a) GitHub Packages (with source maps, requires token)");
|
|
143
|
+
info(" b) npm public registry (compiled only, no auth needed)");
|
|
144
|
+
blank();
|
|
145
|
+
|
|
146
|
+
const hasGitHubAccess = await confirm("Do you have GitHub access to middag-io?", false);
|
|
147
|
+
|
|
148
|
+
if (hasGitHubAccess) {
|
|
149
|
+
registryPath = await runTokenFlow();
|
|
150
|
+
} else {
|
|
151
|
+
success("Using npm public registry (no authentication needed)");
|
|
152
|
+
}
|
|
127
153
|
}
|
|
128
154
|
|
|
129
155
|
// ── Step 4: Create directory ─────────────────────────────────────────────
|
package/lib/scaffold.js
CHANGED
|
@@ -14,13 +14,25 @@ import { error, success, warn } from "./ui.js";
|
|
|
14
14
|
|
|
15
15
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
16
16
|
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Read @middag-io/react version from the monorepo root package.json.
|
|
19
|
+
* Falls back to create-middag-ui's own version, then to a safe default.
|
|
20
|
+
*/
|
|
18
21
|
function getLibVersion() {
|
|
22
|
+
// 1. Monorepo root — the authoritative source for @middag-io/react version
|
|
23
|
+
try {
|
|
24
|
+
const rootPkg = JSON.parse(readFileSync(join(__dirname, "..", "..", "..", "package.json"), "utf-8"));
|
|
25
|
+
if (rootPkg.name === "@middag-io/react" && rootPkg.version) {
|
|
26
|
+
return rootPkg.version;
|
|
27
|
+
}
|
|
28
|
+
} catch { /* not in monorepo — fall through */ }
|
|
29
|
+
|
|
30
|
+
// 2. Own package.json (synced from root by CI in published builds)
|
|
19
31
|
try {
|
|
20
32
|
const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8"));
|
|
21
|
-
return pkg.version || "0.
|
|
33
|
+
return pkg.version || "0.14.0";
|
|
22
34
|
} catch {
|
|
23
|
-
return "0.
|
|
35
|
+
return "0.14.0";
|
|
24
36
|
}
|
|
25
37
|
}
|
|
26
38
|
|