create-lingcode 0.1.0 → 0.1.1

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.
@@ -2,7 +2,7 @@
2
2
  // npm create lingcode@latest [directory] [--template <name>] [--no-install]
3
3
 
4
4
  import { spawnSync } from 'node:child_process';
5
- import { existsSync, readdirSync } from 'node:fs';
5
+ import { existsSync, readdirSync, realpathSync } from 'node:fs';
6
6
  import { cp, readFile, rename, writeFile } from 'node:fs/promises';
7
7
  import { basename, join, relative, resolve } from 'node:path';
8
8
  import { createInterface } from 'node:readline/promises';
@@ -88,7 +88,19 @@ async function main(argv) {
88
88
  console.log(`\nNext steps:\n${steps.map(([cmd, note]) => ` ${note ? cmd.padEnd(width) + note : cmd}`).join('\n')}\n`);
89
89
  }
90
90
 
91
- if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
91
+ // Run when invoked as the CLI. npm installs the bin as a symlink in
92
+ // node_modules/.bin, so compare REAL paths (realpath resolves the symlink) —
93
+ // a plain path compare fails under `npm create`/`npx` and silently does nothing.
94
+ function isCliEntry() {
95
+ if (!process.argv[1]) return false;
96
+ try {
97
+ return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
98
+ } catch (_) {
99
+ return resolve(process.argv[1]) === fileURLToPath(import.meta.url);
100
+ }
101
+ }
102
+
103
+ if (isCliEntry()) {
92
104
  main(process.argv.slice(2)).catch((err) => {
93
105
  console.error(`Error: ${err.message}`);
94
106
  process.exitCode = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-lingcode",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Create a new app on LingCode Cloud: `npm create lingcode@latest`.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -16,7 +16,12 @@
16
16
  "scripts": {
17
17
  "test": "node --test test/*.test.mjs"
18
18
  },
19
- "keywords": ["lingcode", "create", "template", "backend"],
19
+ "keywords": [
20
+ "lingcode",
21
+ "create",
22
+ "template",
23
+ "backend"
24
+ ],
20
25
  "homepage": "https://lingcode.dev/docs/cloud/",
21
26
  "repository": {
22
27
  "type": "git",