@hemia/lume 0.0.1 → 0.0.2

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.
Files changed (2) hide show
  1. package/dist/index.js +44 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -32,8 +32,8 @@ function getInstallCommand(packageManager) {
32
32
  }
33
33
  function installDependencies(dependencies, options = {}) {
34
34
  if (dependencies.length === 0) return;
35
- const { dev = false, cwd = process.cwd() } = options;
36
- const packageManager = detectPackageManager(cwd);
35
+ const { dev = false, cwd = process.cwd(), packageManager: customPm } = options;
36
+ const packageManager = customPm ?? detectPackageManager(cwd);
37
37
  const installCmd = getInstallCommand(packageManager);
38
38
  const devFlag = dev ? packageManager === "npm" ? "--save-dev" : "-D" : "";
39
39
  const command = `${installCmd} ${dependencies.join(" ")} ${devFlag}`.trim();
@@ -106,6 +106,14 @@ function getFrameworkFromConfig(cwd) {
106
106
  return "vue";
107
107
  }
108
108
  }
109
+ function getPackageManagerFromConfig(cwd) {
110
+ try {
111
+ const config = fs3.readJsonSync(path3.resolve(cwd, "lume.config.json"));
112
+ return config.packageManager ?? "npm";
113
+ } catch {
114
+ return "npm";
115
+ }
116
+ }
109
117
  function log(message, options) {
110
118
  if (!options.silent) {
111
119
  console.log(message);
@@ -134,6 +142,7 @@ async function add(components = [], options = {}) {
134
142
  process.exit(1);
135
143
  }
136
144
  const framework = options.framework ?? getFrameworkFromConfig(cwd);
145
+ const packageManager = getPackageManagerFromConfig(cwd);
137
146
  const frameworkRegistry = resolveRegistryPath(framework);
138
147
  if (!options.silent) {
139
148
  log(pc2.cyan(`
@@ -161,8 +170,13 @@ async function add(components = [], options = {}) {
161
170
  await fs3.ensureDir(targetBase);
162
171
  let copiedCount = 0;
163
172
  for (const componentName of componentsArray) {
164
- const source = path3.join(frameworkRegistry, componentName);
173
+ const sourceDir = path3.join(frameworkRegistry, componentName);
174
+ const sourceFile = path3.join(sourceDir, `${componentName}.vue`);
165
175
  const target = path3.join(targetBase, `${componentName}.vue`);
176
+ if (!await fs3.pathExists(sourceFile)) {
177
+ log(pc2.red(`\u274C Source file not found: ${sourceFile}`), options);
178
+ continue;
179
+ }
166
180
  const targetExists = await fs3.pathExists(target);
167
181
  if (targetExists && !options.overwrite && !options.yes) {
168
182
  const { overwrite } = await prompts({
@@ -177,7 +191,7 @@ async function add(components = [], options = {}) {
177
191
  }
178
192
  }
179
193
  if (options.overwrite || options.yes || !targetExists) {
180
- await fs3.copy(source, target, { overwrite: true });
194
+ await fs3.copy(sourceFile, target, { overwrite: true });
181
195
  copiedCount++;
182
196
  log(pc2.green(` \u2713 ${componentName}`), options);
183
197
  }
@@ -186,11 +200,11 @@ async function add(components = [], options = {}) {
186
200
  const devDeps = Array.from(allDevDependencies);
187
201
  if (deps.length > 0) {
188
202
  log("", options);
189
- installDependencies(deps);
203
+ installDependencies(deps, { packageManager });
190
204
  }
191
205
  if (devDeps.length > 0) {
192
206
  log("", options);
193
- installDependencies(devDeps, { dev: true });
207
+ installDependencies(devDeps, { dev: true, packageManager });
194
208
  }
195
209
  log(pc2.green(`
196
210
  \u2705 Added ${copiedCount} component(s) to ${targetBase}/`), options);
@@ -357,6 +371,7 @@ function getTemplateConfig(framework, template) {
357
371
 
358
372
  // src/commands/init.ts
359
373
  var SUPPORTED_FRAMEWORKS = ["vue", "react", "svelte", "astro"];
374
+ var SUPPORTED_PACKAGE_MANAGERS = ["npm", "bun", "pnpm", "yarn"];
360
375
  function detectFramework() {
361
376
  try {
362
377
  const pkg = fs4.readJsonSync(path4.resolve(process.cwd(), "package.json"));
@@ -445,10 +460,32 @@ async function init(options = {}) {
445
460
  log2(pc3.red("\u274C Framework selection required"), options);
446
461
  process.exit(1);
447
462
  }
463
+ const detectedPm = detectPackageManager(cwd);
464
+ let packageManager;
465
+ if (detectedPm) {
466
+ packageManager = detectedPm;
467
+ info(`Detected package manager: ${detectedPm}`, options);
468
+ } else if (!options.yes) {
469
+ const { pm } = await prompts2({
470
+ type: "select",
471
+ name: "pm",
472
+ message: "Which package manager are you using?",
473
+ choices: SUPPORTED_PACKAGE_MANAGERS.map((pm2) => ({ title: pm2, value: pm2 }))
474
+ });
475
+ packageManager = pm;
476
+ } else {
477
+ packageManager = "npm";
478
+ }
479
+ if (!packageManager) {
480
+ log2(pc3.red("\u274C Package manager selection required"), options);
481
+ process.exit(1);
482
+ }
483
+ const installCmd = getInstallCommand(packageManager);
448
484
  const templateConfig = getTemplateConfig(framework, template);
449
485
  const useCssVariables = options.cssVariables !== false;
450
486
  const config = {
451
487
  framework,
488
+ packageManager,
452
489
  style: useCssVariables ? "css-variables" : "default",
453
490
  template: templateConfig.template,
454
491
  tailwind: {
@@ -529,7 +566,7 @@ async function init(options = {}) {
529
566
  log2("", options);
530
567
  const frameworkPkg = framework === "vue" ? "@hemia/lume-vue" : `@hemia/lume-${framework}`;
531
568
  info(`\u{1F4E6} Installing ${frameworkPkg}...`, options);
532
- log2(pc3.dim(` When published, run: npm install ${frameworkPkg}`), options);
569
+ log2(pc3.dim(` When published, run: ${installCmd} ${frameworkPkg}`), options);
533
570
  }
534
571
  log2("", options);
535
572
  log2(pc3.green("\u{1F389} All done! Run the following to add components:"), options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hemia/lume",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "type": "module",
5
5
  "files": ["dist"],
6
6
  "bin": {