create-sense-app 1.0.3 → 1.0.4

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 (3) hide show
  1. package/bin/cli.ts +20 -15
  2. package/dist/cli.js +21 -12
  3. package/package.json +2 -2
package/bin/cli.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { cp, mkdir, readFile, writeFile, rm } from "node:fs/promises";
1
+ #!/usr/bin/env node
2
+ import { mkdir, readFile, writeFile, rm } from "node:fs/promises";
2
3
  import { join } from "node:path";
3
- import { spawn } from "bun";
4
+ import { spawn } from "node:child_process";
4
5
  import fs from "node:fs";
5
6
 
6
7
  const projectName = process.argv[2] || "sense-app";
@@ -8,21 +9,30 @@ const projectDir = join(process.cwd(), projectName);
8
9
 
9
10
  console.log(`\n Creating a new Sense app in ${projectName}...\n`);
10
11
 
11
-
12
12
  if (fs.existsSync(projectDir)) {
13
13
  console.error(`Error: Directory ${projectName} already exists.`);
14
14
  process.exit(1);
15
15
  }
16
16
  await mkdir(projectDir, { recursive: true });
17
17
 
18
+ const repo = "github:ommgh/sense/packages/sense-template";
19
+
20
+ const exitCode = await new Promise<number>((resolve) => {
21
+ const degit = spawn("npx", ["degit", repo, projectName], {
22
+ stdio: ["ignore", "inherit", "inherit"],
23
+ shell: true,
24
+ });
18
25
 
19
- const repo = "github:ommishra/sense/packages/sense-template";
20
- const degit = spawn(["npx", "degit", repo, projectName], {
21
- stdio: ["ignore", "inherit", "inherit"],
26
+ degit.on("close", (code) => {
27
+ resolve(code ?? 1);
28
+ });
29
+
30
+ degit.on("error", () => {
31
+ resolve(1);
32
+ });
22
33
  });
23
- await degit.exited;
24
34
 
25
- if (degit.exitCode !== 0) {
35
+ if (exitCode !== 0) {
26
36
  process.exit(1);
27
37
  }
28
38
 
@@ -31,22 +41,17 @@ if (fs.existsSync(lockfilePath)) {
31
41
  await rm(lockfilePath);
32
42
  }
33
43
 
34
-
35
44
  const pkgPath = join(projectDir, "package.json");
36
45
  const pkgStr = await readFile(pkgPath, "utf-8");
37
46
  const pkg = JSON.parse(pkgStr);
38
47
 
39
-
40
48
  pkg.name = projectName;
41
49
 
42
-
43
50
  pkg.dependencies["@ommishra/sense"] = "latest";
44
51
 
45
-
46
52
  await writeFile(pkgPath, JSON.stringify(pkg, null, 2));
47
53
 
48
-
49
54
  console.log(`\nDone! Now run:\n`);
50
55
  console.log(` cd ${projectName}`);
51
- console.log(` bun install`);
52
- console.log(` bun dev`);
56
+ console.log(` npm install # or pnpm install, yarn, bun install`);
57
+ console.log(` npm run dev # or pnpm dev, yarn dev, bun dev`);
package/dist/cli.js CHANGED
@@ -1,9 +1,10 @@
1
- // @bun
1
+ #!/usr/bin/env node
2
+
2
3
  // bin/cli.ts
3
- import { mkdir, readFile, writeFile, rm } from "fs/promises";
4
- import { join } from "path";
5
- var {spawn } = globalThis.Bun;
6
- import fs from "fs";
4
+ import { mkdir, readFile, writeFile, rm } from "node:fs/promises";
5
+ import { join } from "node:path";
6
+ import { spawn } from "node:child_process";
7
+ import fs from "node:fs";
7
8
  var projectName = process.argv[2] || "sense-app";
8
9
  var projectDir = join(process.cwd(), projectName);
9
10
  console.log(`
@@ -14,12 +15,20 @@ if (fs.existsSync(projectDir)) {
14
15
  process.exit(1);
15
16
  }
16
17
  await mkdir(projectDir, { recursive: true });
17
- var repo = "github:ommishra/sense/packages/sense-template";
18
- var degit = spawn(["npx", "degit", repo, projectName], {
19
- stdio: ["ignore", "inherit", "inherit"]
18
+ var repo = "github:ommgh/sense/packages/sense-template";
19
+ var exitCode = await new Promise((resolve) => {
20
+ const degit = spawn("npx", ["degit", repo, projectName], {
21
+ stdio: ["ignore", "inherit", "inherit"],
22
+ shell: true
23
+ });
24
+ degit.on("close", (code) => {
25
+ resolve(code ?? 1);
26
+ });
27
+ degit.on("error", () => {
28
+ resolve(1);
29
+ });
20
30
  });
21
- await degit.exited;
22
- if (degit.exitCode !== 0) {
31
+ if (exitCode !== 0) {
23
32
  process.exit(1);
24
33
  }
25
34
  var lockfilePath = join(projectDir, "bun.lockb");
@@ -36,5 +45,5 @@ console.log(`
36
45
  Done! Now run:
37
46
  `);
38
47
  console.log(` cd ${projectName}`);
39
- console.log(` bun install`);
40
- console.log(` bun dev`);
48
+ console.log(` npm install # or pnpm install, yarn, bun install`);
49
+ console.log(` npm run dev # or pnpm dev, yarn dev, bun dev`);
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "create-sense-app",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "bin": "./dist/cli.js",
5
5
  "scripts": {
6
- "build": "bun build ./bin/cli.ts --outfile ./dist/cli.js --target bun"
6
+ "build": "bun build ./bin/cli.ts --outfile ./dist/cli.js --target node"
7
7
  },
8
8
  "module": "index.ts",
9
9
  "type": "module",