create-sense-app 1.0.2 → 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.
- package/bin/cli.ts +20 -15
- package/dist/cli.js +32 -18
- package/package.json +1 -1
package/bin/cli.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
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 "
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 (
|
|
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,26 +1,40 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
2
|
-
// @bun
|
|
1
|
+
#!/usr/bin/env node
|
|
3
2
|
|
|
4
3
|
// bin/cli.ts
|
|
5
|
-
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
6
|
-
import { join } from "path";
|
|
7
|
-
|
|
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";
|
|
8
8
|
var projectName = process.argv[2] || "sense-app";
|
|
9
|
-
var
|
|
10
|
-
var projectDir = join(currentDir, projectName);
|
|
9
|
+
var projectDir = join(process.cwd(), projectName);
|
|
11
10
|
console.log(`
|
|
12
|
-
|
|
11
|
+
Creating a new Sense app in ${projectName}...
|
|
13
12
|
`);
|
|
13
|
+
if (fs.existsSync(projectDir)) {
|
|
14
|
+
console.error(`Error: Directory ${projectName} already exists.`);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
14
17
|
await mkdir(projectDir, { recursive: true });
|
|
15
|
-
var repo = "github:ommgh/
|
|
16
|
-
var
|
|
17
|
-
|
|
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
|
+
});
|
|
18
30
|
});
|
|
19
|
-
|
|
20
|
-
if (degit.exitCode !== 0) {
|
|
21
|
-
console.error("Failed to download template.");
|
|
31
|
+
if (exitCode !== 0) {
|
|
22
32
|
process.exit(1);
|
|
23
33
|
}
|
|
34
|
+
var lockfilePath = join(projectDir, "bun.lockb");
|
|
35
|
+
if (fs.existsSync(lockfilePath)) {
|
|
36
|
+
await rm(lockfilePath);
|
|
37
|
+
}
|
|
24
38
|
var pkgPath = join(projectDir, "package.json");
|
|
25
39
|
var pkgStr = await readFile(pkgPath, "utf-8");
|
|
26
40
|
var pkg = JSON.parse(pkgStr);
|
|
@@ -28,8 +42,8 @@ pkg.name = projectName;
|
|
|
28
42
|
pkg.dependencies["@ommishra/sense"] = "latest";
|
|
29
43
|
await writeFile(pkgPath, JSON.stringify(pkg, null, 2));
|
|
30
44
|
console.log(`
|
|
31
|
-
Done!
|
|
32
|
-
cd ${projectName}
|
|
33
|
-
bun install
|
|
34
|
-
bun dev
|
|
45
|
+
Done! Now run:
|
|
35
46
|
`);
|
|
47
|
+
console.log(` cd ${projectName}`);
|
|
48
|
+
console.log(` npm install # or pnpm install, yarn, bun install`);
|
|
49
|
+
console.log(` npm run dev # or pnpm dev, yarn dev, bun dev`);
|