phpxui 0.0.4 → 0.0.6
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/dist/index.js +28 -27
- package/dist/utils/load-config.js +4 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -13,10 +13,8 @@ const ensure_package_1 = require("./generators/ensure-package");
|
|
|
13
13
|
const copy_tailwind_1 = require("./generators/copy-tailwind");
|
|
14
14
|
const load_config_1 = require("./utils/load-config");
|
|
15
15
|
const icons_1 = require("./commands/icons");
|
|
16
|
+
const CORE_COMPONENTS = ["Slot", "Portal"];
|
|
16
17
|
(async () => {
|
|
17
|
-
/* ─────────────────────────────────────────────
|
|
18
|
-
* 1. Parse command & flags
|
|
19
|
-
* ──────────────────────────────────────────── */
|
|
20
18
|
const args = process.argv.slice(2);
|
|
21
19
|
const [command, ...rest] = args;
|
|
22
20
|
if (command !== "add") {
|
|
@@ -38,10 +36,8 @@ const icons_1 = require("./commands/icons");
|
|
|
38
36
|
names.push(tok);
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
|
-
/*
|
|
42
|
-
|
|
43
|
-
* ──────────────────────────────────────────── */
|
|
44
|
-
const config = (0, load_config_1.loadPhpXUIConfig)();
|
|
39
|
+
/* 2) Load config + detect first run */
|
|
40
|
+
const { config, isFirstRun } = (0, load_config_1.loadPhpXUIConfig)();
|
|
45
41
|
if (!config.iconsInstalled) {
|
|
46
42
|
await (0, icons_1.installIcons)([
|
|
47
43
|
"chevron-down",
|
|
@@ -61,27 +57,26 @@ const icons_1 = require("./commands/icons");
|
|
|
61
57
|
"panel-left",
|
|
62
58
|
], config);
|
|
63
59
|
}
|
|
64
|
-
/*
|
|
65
|
-
* 3. Housekeeping steps (always run)
|
|
66
|
-
* ──────────────────────────────────────────── */
|
|
60
|
+
/* 3) Housekeeping */
|
|
67
61
|
(0, ensure_package_1.ensurePackageInstalled)("tw-animate-css");
|
|
68
|
-
|
|
62
|
+
// Tailwind base CSS: only forced on first run
|
|
63
|
+
const cssUpdated = (0, copy_tailwind_1.copyTailwindCss)(isFirstRun /* ignore flags.force here */);
|
|
69
64
|
if (cssUpdated) {
|
|
70
65
|
const relCss = path_1.default
|
|
71
66
|
.relative(process.cwd(), "src/app/css/tailwind.css")
|
|
72
67
|
.replace(/\\/g, "/");
|
|
73
|
-
console.log(chalk_1.default.green(
|
|
68
|
+
console.log(chalk_1.default.green(isFirstRun
|
|
69
|
+
? `✔ Installed base Tailwind CSS → ${relCss}`
|
|
70
|
+
: `✔ Added Tailwind CSS (missing) → ${relCss}`));
|
|
74
71
|
}
|
|
75
|
-
/*
|
|
76
|
-
* 4. Resolve output directory
|
|
77
|
-
* ──────────────────────────────────────────── */
|
|
72
|
+
/* 4) Resolve output directory */
|
|
78
73
|
const targetDir = path_1.default.resolve(config.outputDir || "src/Lib/PHPXUI");
|
|
79
74
|
try {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
75
|
+
// Overwrite policy
|
|
76
|
+
const componentForce = isFirstRun || flags.force;
|
|
77
|
+
/* 5) Bulk mode */
|
|
83
78
|
if (flags.all) {
|
|
84
|
-
const { ok, fail } = await (0, php_components_bulk_1.generateAllComponents)(targetDir,
|
|
79
|
+
const { ok, fail } = await (0, php_components_bulk_1.generateAllComponents)(targetDir, componentForce);
|
|
85
80
|
console.log(chalk_1.default.green(`\n✔ Generated ${ok.length} components in ${path_1.default.relative(process.cwd(), targetDir)}`));
|
|
86
81
|
if (fail.length) {
|
|
87
82
|
console.log(chalk_1.default.red(`✖ ${fail.length} failures:`));
|
|
@@ -89,23 +84,29 @@ const icons_1 = require("./commands/icons");
|
|
|
89
84
|
}
|
|
90
85
|
process.exit(fail.length ? 1 : 0);
|
|
91
86
|
}
|
|
92
|
-
/*
|
|
93
|
-
* 6. Interactive prompt if no names given
|
|
94
|
-
* ───────────────────────────────────────── */
|
|
87
|
+
/* 6) Interactive prompt if no names given */
|
|
95
88
|
if (names.length === 0) {
|
|
96
89
|
const { componentList } = await (0, prompts_1.default)({
|
|
97
90
|
type: "text",
|
|
98
91
|
name: "componentList",
|
|
99
|
-
message: "Which components do you want to add? (space
|
|
92
|
+
message: "Which components do you want to add? (space- or comma-separated)",
|
|
100
93
|
validate: (v) => (v.trim() ? true : "Enter at least one name"),
|
|
101
94
|
});
|
|
102
95
|
names.push(...componentList.split(/[\s,]+/));
|
|
103
96
|
}
|
|
104
|
-
/*
|
|
105
|
-
|
|
106
|
-
|
|
97
|
+
/* 6.5) Ensure core components first on first-run (unless --all) */
|
|
98
|
+
if (isFirstRun && !flags.all) {
|
|
99
|
+
for (const core of CORE_COMPONENTS) {
|
|
100
|
+
const hasCore = names.some((n) => n.toLowerCase() === core.toLowerCase());
|
|
101
|
+
if (!hasCore) {
|
|
102
|
+
// Put each core at the front in the declared order:
|
|
103
|
+
names.unshift(core);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/* 7) Generate each requested component */
|
|
107
108
|
for (const name of names) {
|
|
108
|
-
const saved = await (0, php_component_1.generateComponent)(name, targetDir,
|
|
109
|
+
const saved = await (0, php_component_1.generateComponent)(name, targetDir, componentForce);
|
|
109
110
|
const paths = Array.isArray(saved) ? saved : [saved];
|
|
110
111
|
for (const abs of paths) {
|
|
111
112
|
const rel = path_1.default.relative(process.cwd(), abs).replace(/\\/g, "/");
|
|
@@ -24,14 +24,16 @@ const defaultConfig = {
|
|
|
24
24
|
},
|
|
25
25
|
iconLibrary: "ppicons",
|
|
26
26
|
};
|
|
27
|
+
// ⬇️ CHANGED: return { config, isFirstRun }
|
|
27
28
|
function loadPhpXUIConfig() {
|
|
28
29
|
const configPath = path_1.default.resolve("phpxui.json");
|
|
29
|
-
|
|
30
|
+
const existed = fs_1.default.existsSync(configPath);
|
|
31
|
+
if (!existed) {
|
|
30
32
|
fs_1.default.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));
|
|
31
33
|
console.log("📦 Created default phpxui.json");
|
|
32
34
|
}
|
|
33
35
|
const content = fs_1.default.readFileSync(configPath, "utf-8");
|
|
34
|
-
return JSON.parse(content);
|
|
36
|
+
return { config: JSON.parse(content), isFirstRun: !existed };
|
|
35
37
|
}
|
|
36
38
|
function savePhpXUIConfig(config) {
|
|
37
39
|
const configPath = path_1.default.resolve("phpxui.json");
|