tsc-app 3.1.3 → 3.2.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/README.md +26 -8
- package/index.js +106 -31
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,17 +3,35 @@
|
|
|
3
3
|
A minimal and fast **TypeScript project generator** — spin up a ready-to-use TypeScript + Node.js project with a single command.
|
|
4
4
|
|
|
5
5
|
## ✨ Features
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
6
|
+
|
|
7
|
+
- 📦 Automatic `package.json` creation with sensible defaults
|
|
8
|
+
- ⚙ Clean `tsconfig.json` optimized for Node.js
|
|
9
|
+
- 📂 `src/` folder setup with a starter `index.ts`
|
|
10
|
+
- 🏃 Pre-configured scripts: `start`, `build`, and `dev`
|
|
11
|
+
- ⚡ Supports CommonJS and ES Module formats via the `--module` flag
|
|
12
|
+
- 🖥 No global install required — run instantly via `npx`
|
|
13
|
+
- ✅ Configured with the latest TypeScript best practices
|
|
12
14
|
|
|
13
15
|
---
|
|
14
16
|
|
|
15
17
|
## 🚀 Quick Start
|
|
16
18
|
|
|
17
|
-
###
|
|
19
|
+
### Create a New Project
|
|
18
20
|
```bash
|
|
19
|
-
npx ts-app my-app
|
|
21
|
+
npx ts-app --app-name my-app
|
|
22
|
+
|
|
23
|
+
Output:
|
|
24
|
+
|
|
25
|
+
Folder Structure:
|
|
26
|
+
my-app/
|
|
27
|
+
├── package.json
|
|
28
|
+
├── tsconfig.json
|
|
29
|
+
├── src/
|
|
30
|
+
│ └── index.ts
|
|
31
|
+
└── dist/
|
|
32
|
+
|
|
33
|
+
Build the Project
|
|
34
|
+
=> npm run dev
|
|
35
|
+
|
|
36
|
+
Run Compiled Code
|
|
37
|
+
=> npm start
|
package/index.js
CHANGED
|
@@ -1,33 +1,39 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// Use CommonJS so it works out-of-the-box with npm CLI
|
|
4
2
|
const fs = require("fs");
|
|
5
3
|
const { execSync } = require("child_process");
|
|
4
|
+
const path = require("path");
|
|
6
5
|
|
|
7
|
-
// --- Args ---
|
|
8
6
|
const args = process.argv.slice(2);
|
|
9
|
-
|
|
7
|
+
let projectName = args[0] || "my-ts-app";
|
|
10
8
|
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
// Validate project name
|
|
10
|
+
const namePattern = /^[a-zA-Z][a-zA-Z0-9-]{2,}$/;
|
|
11
|
+
if (!namePattern.test(projectName)) {
|
|
12
|
+
console.error(
|
|
13
|
+
"Invalid project name. Must:\n" +
|
|
14
|
+
"- start with a letter\n" +
|
|
15
|
+
"- be at least 3 characters long\n" +
|
|
16
|
+
"- contain only letters, numbers, and hyphens\n" +
|
|
17
|
+
"- no spaces or special characters"
|
|
18
|
+
);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
14
21
|
|
|
22
|
+
// Defaults
|
|
23
|
+
let packageType = "module";
|
|
15
24
|
|
|
16
25
|
// Parse -m flag
|
|
17
26
|
if (args.includes("-m")) {
|
|
18
27
|
const val = args[args.indexOf("-m") + 1]?.toLowerCase();
|
|
19
|
-
if (["
|
|
20
|
-
packageType = "module";
|
|
21
|
-
tsModuleKind = "esnext";
|
|
22
|
-
} else if (["commonjs", "cjs"].includes(val)) {
|
|
28
|
+
if (["commonjs", "cjs"].includes(val)) {
|
|
23
29
|
packageType = "commonjs";
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
console.warn(`⚠ Unknown module type "${val}", defaulting to module`);
|
|
30
|
+
} else if (!["module", "esm", "esnext"].includes(val)) {
|
|
31
|
+
console.warn(`Unknown module type "${val}", defaulting to "module"`);
|
|
27
32
|
}
|
|
28
33
|
}
|
|
29
34
|
|
|
30
|
-
console.log(`Creating TypeScript app: ${projectName}
|
|
35
|
+
console.log(`Creating TypeScript app: ${projectName}`);
|
|
36
|
+
console.log(` → package.json type = ${packageType}`);
|
|
31
37
|
|
|
32
38
|
// Create project folder
|
|
33
39
|
fs.mkdirSync(projectName);
|
|
@@ -36,30 +42,99 @@ process.chdir(projectName);
|
|
|
36
42
|
// Init package.json
|
|
37
43
|
execSync("npm init -y", { stdio: "inherit" });
|
|
38
44
|
|
|
39
|
-
// Install dev
|
|
40
|
-
execSync("npm i -D typescript ts-node @types/node", {
|
|
45
|
+
// Install dev dependencies (latest)
|
|
46
|
+
execSync("npm i -D typescript@latest ts-node@latest @types/node@latest concurrently@latest nodemon@latest", {
|
|
47
|
+
stdio: "inherit",
|
|
48
|
+
});
|
|
41
49
|
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
// Create tsconfig.json
|
|
51
|
+
const tsconfig = {
|
|
52
|
+
compilerOptions: {
|
|
53
|
+
rootDir: "./src",
|
|
54
|
+
outDir: "./dist",
|
|
55
|
+
module: "nodenext",
|
|
56
|
+
target: "esnext",
|
|
57
|
+
types: ["node"],
|
|
58
|
+
sourceMap: true,
|
|
59
|
+
declaration: true,
|
|
60
|
+
declarationMap: true,
|
|
61
|
+
noUncheckedIndexedAccess: true,
|
|
62
|
+
exactOptionalPropertyTypes: true,
|
|
63
|
+
strict: true,
|
|
64
|
+
verbatimModuleSyntax: true,
|
|
65
|
+
isolatedModules: true,
|
|
66
|
+
moduleDetection: "force",
|
|
67
|
+
skipLibCheck: true,
|
|
68
|
+
esModuleInterop: true,
|
|
69
|
+
forceConsistentCasingInFileNames: true,
|
|
70
|
+
moduleResolution: "nodenext"
|
|
71
|
+
},
|
|
72
|
+
include: ["src/**/*.ts"],
|
|
73
|
+
exclude: ["node_modules", "dist"]
|
|
74
|
+
};
|
|
75
|
+
fs.writeFileSync("tsconfig.json", JSON.stringify(tsconfig, null, 2));
|
|
47
76
|
|
|
48
|
-
// Create src +
|
|
77
|
+
// Create src folder + entry file
|
|
49
78
|
fs.mkdirSync("src");
|
|
50
|
-
fs.writeFileSync(
|
|
79
|
+
fs.writeFileSync(
|
|
80
|
+
"src/index.ts",
|
|
81
|
+
`export function hello(name: string) {
|
|
82
|
+
return \`Hello, \${name}!\`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
console.log(hello("World"));`
|
|
86
|
+
);
|
|
51
87
|
|
|
52
|
-
// Update package.json scripts
|
|
88
|
+
// Update package.json scripts
|
|
53
89
|
const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
|
|
54
90
|
pkg.type = packageType;
|
|
55
91
|
pkg.scripts = {
|
|
56
|
-
|
|
92
|
+
dev: 'concurrently "tsc -w" "nodemon dist/index.js"',
|
|
57
93
|
build: "tsc",
|
|
58
|
-
|
|
94
|
+
start: "node dist/index.js"
|
|
59
95
|
};
|
|
96
|
+
pkg.main = "./dist/index.js";
|
|
97
|
+
pkg.types = "./dist/index.d.ts";
|
|
60
98
|
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 2));
|
|
61
99
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
100
|
+
// Create .gitignore
|
|
101
|
+
fs.writeFileSync(
|
|
102
|
+
".gitignore",
|
|
103
|
+
`node_modules
|
|
104
|
+
dist
|
|
105
|
+
.env
|
|
106
|
+
*.log
|
|
107
|
+
.DS_Store
|
|
108
|
+
`
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
// Create README.md
|
|
112
|
+
fs.writeFileSync(
|
|
113
|
+
"README.md",
|
|
114
|
+
`# ${projectName}
|
|
115
|
+
|
|
116
|
+
> Generated with init-ts-app
|
|
117
|
+
|
|
118
|
+
## Quick Start
|
|
119
|
+
\`\`\`bash
|
|
120
|
+
npm install
|
|
121
|
+
npm run dev
|
|
122
|
+
\`\`\`
|
|
123
|
+
|
|
124
|
+
## Scripts
|
|
125
|
+
- \`npm run dev\` — watch + rebuild + run dist/index.js
|
|
126
|
+
- \`npm run build\` — compile TypeScript to dist/
|
|
127
|
+
`
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
// Init Git repo
|
|
131
|
+
execSync("git init", { stdio: "inherit" });
|
|
132
|
+
execSync("git add .", { stdio: "inherit" });
|
|
133
|
+
execSync("git commit -m 'Initial commit: generated by init-ts-app'", {
|
|
134
|
+
stdio: "inherit",
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
console.log("\n=> Project setup complete!");
|
|
138
|
+
console.log(`=> cd ${projectName}`);
|
|
139
|
+
console.log("=> npm run dev");
|
|
140
|
+
|