@morda-dev/create-sdk 1.1.3 → 1.1.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 CHANGED
@@ -1,123 +1,123 @@
1
- # create-sdk
2
- ![npm](https://img.shields.io/npm/v/@morda-dev/create-sdk)
3
- ![npm downloads](https://img.shields.io/npm/dm/@morda-dev/create-sdk)
4
- ![CI](https://github.com/mordaHQ/create-sdk/actions/workflows/ci.yml/badge.svg)
5
-
6
- > Scaffold a **production-ready TypeScript SDK** with a **strict public API**.
7
-
8
- `create-sdk` is a CLI tool that bootstraps a modern TypeScript SDK with
9
- **ESM-first setup**, **API Extractor**, and **CI-ready structure** — so you
10
- can focus on features, not boilerplate.
11
-
12
- ---
13
-
14
- ## ✨ Features
15
-
16
- - ⚡ **Interactive CLI** (or fully automated with flags)
17
- - 📦 **ESM-first TypeScript setup**
18
- - 🔒 **Strict public API** via API Extractor
19
- - 🧪 **CI-verified & smoke-tested**
20
- - 🧱 Clean, scalable project structure
21
- - 🚫 No hidden magic, no vendor lock-in
22
-
23
- ---
24
-
25
- ## 🚀 Quick start
26
-
27
- This creates a clean SDK with a strict public API enforced by API Extractor.
28
-
29
- ```bash
30
- npx @morda-dev/create-sdk my-sdk
31
- cd my-sdk
32
- npm install
33
- npm run build
34
- ```
35
-
36
- That’s it. You now have a production-ready SDK.
37
-
38
- ## 📘 Example SDK
39
-
40
- See a minimal, production-style SDK generated with **create-sdk**:
41
-
42
- 👉 https://github.com/mordaHQ/example-sdk
43
-
44
- This example demonstrates:
45
- - a single, explicit public API entrypoint (`src/index.ts`)
46
- - API Extractor–controlled surface
47
- - ESM-first configuration
48
- - CI-ready setup
49
- - safe evolution without accidental breaking changes
50
-
51
- Use it as a reference for structuring real-world SDKs.
52
-
53
- ## ❓ Why create-sdk?
54
-
55
- Most SDK starters fall into one of two traps:
56
-
57
- - ❌ too minimal — no real production setup
58
- - ❌ too complex — opinionated, hard to extend
59
-
60
- **create-sdk** sits in the middle:
61
-
62
- > Strict where it matters. Flexible where it should be.
63
-
64
- You get:
65
-
66
- - a clearly defined public API
67
- - predictable build & release flow
68
- - freedom to grow the SDK your way
69
-
70
- ## 🧩 What’s included
71
-
72
- - TypeScript project with strict config
73
- - API Extractor setup
74
- - Ready-to-use CI workflow
75
- - Clean module-based structure
76
- - Example public API and types
77
-
78
- ## 🛠 CLI options
79
-
80
- ```bash
81
- npx @morda-dev/create-sdk <name> [options]
82
- ```
83
-
84
- ### Options
85
-
86
- - `--yes` — skip all prompts
87
- - `--no-install` — skip dependency installation
88
- - `--no-git` — skip git initialization
89
-
90
- ### Example
91
-
92
- ```bash
93
- npx @morda-dev/create-sdk my-sdk --yes --no-install
94
- ```
95
-
96
- ## 📦 Requirements
97
-
98
- - Node.js >= 18
99
- - npm / pnpm / yarn
100
-
101
- ## ✅ Used in production
102
-
103
- This template is used to scaffold and maintain real-world TypeScript SDKs.
104
-
105
-
106
- ## 🧭 Roadmap
107
-
108
- - Custom templates
109
- - Optional monorepo mode
110
- - Plugin system
111
- - SDK release automation helpers
112
-
113
- ## 🤝 Contributing
114
-
115
- Issues and PRs are welcome.
116
- This project is intentionally kept small, clean, and well-documented.
117
-
118
- ## 📄 License
119
-
120
- ISC
121
-
122
-
123
- ---
1
+ # create-sdk
2
+ ![npm](https://img.shields.io/npm/v/@morda-dev/create-sdk)
3
+ ![npm downloads](https://img.shields.io/npm/dm/@morda-dev/create-sdk)
4
+ ![CI](https://github.com/mordaHQ/create-sdk/actions/workflows/ci.yml/badge.svg)
5
+
6
+ > Scaffold a **production-ready TypeScript SDK** with a **strict public API**.
7
+
8
+ `create-sdk` is a CLI tool that bootstraps a modern TypeScript SDK with
9
+ **ESM-first setup**, **API Extractor**, and **CI-ready structure** — so you
10
+ can focus on features, not boilerplate.
11
+
12
+ ---
13
+
14
+ ## ✨ Features
15
+
16
+ - ⚡ **Interactive CLI** (or fully automated with flags)
17
+ - 📦 **ESM-first TypeScript setup**
18
+ - 🔒 **Strict public API** via API Extractor
19
+ - 🧪 **CI-verified & smoke-tested**
20
+ - 🧱 Clean, scalable project structure
21
+ - 🚫 No hidden magic, no vendor lock-in
22
+
23
+ ---
24
+
25
+ ## 🚀 Quick start
26
+
27
+ This creates a clean SDK with a strict public API enforced by API Extractor.
28
+
29
+ ```bash
30
+ npx @morda-dev/create-sdk my-sdk
31
+ cd my-sdk
32
+ npm install
33
+ npm run build
34
+ ```
35
+
36
+ That’s it. You now have a production-ready SDK.
37
+
38
+ ## 📘 Example SDK
39
+
40
+ See a minimal, production-style SDK generated with **create-sdk**:
41
+
42
+ 👉 https://github.com/mordaHQ/example-sdk
43
+
44
+ This example demonstrates:
45
+ - a single, explicit public API entrypoint (`src/index.ts`)
46
+ - API Extractor–controlled surface
47
+ - ESM-first configuration
48
+ - CI-ready setup
49
+ - safe evolution without accidental breaking changes
50
+
51
+ Use it as a reference for structuring real-world SDKs.
52
+
53
+ ## ❓ Why create-sdk?
54
+
55
+ Most SDK starters fall into one of two traps:
56
+
57
+ - ❌ too minimal — no real production setup
58
+ - ❌ too complex — opinionated, hard to extend
59
+
60
+ **create-sdk** sits in the middle:
61
+
62
+ > Strict where it matters. Flexible where it should be.
63
+
64
+ You get:
65
+
66
+ - a clearly defined public API
67
+ - predictable build & release flow
68
+ - freedom to grow the SDK your way
69
+
70
+ ## 🧩 What’s included
71
+
72
+ - TypeScript project with strict config
73
+ - API Extractor setup
74
+ - Ready-to-use CI workflow
75
+ - Clean module-based structure
76
+ - Example public API and types
77
+
78
+ ## 🛠 CLI options
79
+
80
+ ```bash
81
+ npx @morda-dev/create-sdk <name> [options]
82
+ ```
83
+
84
+ ### Options
85
+
86
+ - `--yes` — skip all prompts
87
+ - `--no-install` — skip dependency installation
88
+ - `--no-git` — skip git initialization
89
+
90
+ ### Example
91
+
92
+ ```bash
93
+ npx @morda-dev/create-sdk my-sdk --yes --no-install
94
+ ```
95
+
96
+ ## 📦 Requirements
97
+
98
+ - Node.js >= 18
99
+ - npm / pnpm / yarn
100
+
101
+ ## ✅ Used in production
102
+
103
+ This template is used to scaffold and maintain real-world TypeScript SDKs.
104
+
105
+
106
+ ## 🧭 Roadmap
107
+
108
+ - Custom templates
109
+ - Optional monorepo mode
110
+ - Plugin system
111
+ - SDK release automation helpers
112
+
113
+ ## 🤝 Contributing
114
+
115
+ Issues and PRs are welcome.
116
+ This project is intentionally kept small, clean, and well-documented.
117
+
118
+ ## 📄 License
119
+
120
+ ISC
121
+
122
+
123
+ ---
package/bin/create-sdk.js CHANGED
@@ -1,261 +1,95 @@
1
- #!/usr/bin/env node
2
-
3
- import fs from "fs";
4
- import path from "path";
5
- import process from "process";
6
- import { fileURLToPath } from "url";
7
- import { execSync } from "child_process";
8
- import prompts from "prompts";
9
-
10
- /* ============================================================================
11
- * Environment checks
12
- * ============================================================================
13
- */
14
-
15
- const REQUIRED_NODE_MAJOR = 18;
16
- const CURRENT_NODE_MAJOR = Number(process.versions.node.split(".")[0]);
17
-
18
- if (CURRENT_NODE_MAJOR < REQUIRED_NODE_MAJOR) {
19
- console.error(
20
- `❌ Node.js ${REQUIRED_NODE_MAJOR}+ is required.\n` +
21
- ` You are using Node.js ${process.versions.node}`
22
- );
23
- process.exit(1);
24
- }
25
-
26
- /* ============================================================================
27
- * CLI args & flags
28
- * ============================================================================
29
- */
30
-
31
- const rawArgs = process.argv.slice(2);
32
-
33
- const flags = {
34
- yes: rawArgs.includes("--yes"),
35
- noGit: rawArgs.includes("--no-git"),
36
- noInstall: rawArgs.includes("--no-install"),
37
- };
38
-
39
- if (rawArgs.includes("--version") || rawArgs.includes("-v")) {
40
- console.log("create-sdk v1.1.0");
41
- process.exit(0);
42
- }
43
-
44
- if (rawArgs.includes("--help") || rawArgs.includes("-h")) {
45
- console.log(`
46
- create-sdk scaffold a production-ready TypeScript SDK
47
-
48
- Usage:
49
- npx @morda-dev/create-sdk <project-name>
50
-
51
- Options:
52
- --yes Skip prompts and use defaults
53
- --no-git Do not initialize git repository
54
- --no-install Do not install dependencies
55
- --help, -h Show this help
56
- --version, -v Show version
57
-
58
- Example:
59
- npx @morda-dev/create-sdk my-sdk
60
- npx @morda-dev/create-sdk my-sdk --yes --no-install
61
- `);
62
- process.exit(0);
63
- }
64
-
65
- /* ============================================================================
66
- * Paths
67
- * ============================================================================
68
- */
69
-
70
- const __filename = fileURLToPath(import.meta.url);
71
- const __dirname = path.dirname(__filename);
72
- const templateDir = path.resolve(__dirname, "../template");
73
-
74
- /* ============================================================================
75
- * Project name & interactive flow
76
- * ============================================================================
77
- */
78
-
79
- const argProjectName = rawArgs.find((a) => !a.startsWith("-"));
80
-
81
- let projectName;
82
- let initGit = !flags.noGit;
83
- let installDeps = !flags.noInstall;
84
-
85
- if (flags.yes && argProjectName) {
86
- projectName = argProjectName;
87
- } else if (!argProjectName) {
88
- const answers = await prompts(
89
- [
90
- {
91
- type: "text",
92
- name: "name",
93
- message: "Project name:",
94
- validate: (v) => (v ? true : "Project name is required"),
95
- },
96
- {
97
- type: "confirm",
98
- name: "initGit",
99
- message: "Initialize git repository?",
100
- initial: true,
101
- },
102
- {
103
- type: "confirm",
104
- name: "installDeps",
105
- message: "Install dependencies now?",
106
- initial: false,
107
- },
108
- ],
109
- {
110
- onCancel: () => {
111
- console.log("\n❌ Cancelled");
112
- process.exit(1);
113
- },
114
- }
115
- );
116
-
117
- projectName = answers.name;
118
- initGit = answers.initGit;
119
- installDeps = answers.installDeps;
120
- } else {
121
- projectName = argProjectName;
122
- }
123
-
124
- if (!projectName) {
125
- console.error("❌ Project name is required");
126
- process.exit(1);
127
- }
128
-
129
- /* ============================================================================
130
- * Target directory
131
- * ============================================================================
132
- */
133
-
134
- const dirName = projectName.startsWith("@")
135
- ? projectName.split("/")[1]
136
- : projectName;
137
-
138
- const targetDir = path.resolve(process.cwd(), dirName);
139
-
140
- /* ============================================================================
141
- * Safety checks
142
- * ============================================================================
143
- */
144
-
145
- if (!fs.existsSync(templateDir)) {
146
- console.error("❌ Template directory not found:", templateDir);
147
- process.exit(1);
148
- }
149
-
150
- if (fs.existsSync(targetDir)) {
151
- console.error(`❌ Directory "${dirName}" already exists`);
152
- process.exit(1);
153
- }
154
-
155
- /* ============================================================================
156
- * Scaffold project
157
- * ============================================================================
158
- */
159
-
160
- console.log("🚀 Creating SDK:", projectName);
161
-
162
- copyDir(templateDir, targetDir);
163
-
164
- /* ============================================================================
165
- * Update package.json
166
- * ============================================================================
167
- */
168
-
169
- const pkgPath = path.join(targetDir, "package.json");
170
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
171
-
172
- pkg.name = projectName;
173
- pkg.version = "0.1.0";
174
- delete pkg.private;
175
-
176
- fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
177
-
178
- /* ============================================================================
179
- * Update README title
180
- * ============================================================================
181
- */
182
-
183
- const readmePath = path.join(targetDir, "README.md");
184
-
185
- if (fs.existsSync(readmePath)) {
186
- const updated = fs
187
- .readFileSync(readmePath, "utf8")
188
- .replace(/^# .*/m, `# ${projectName}`);
189
-
190
- fs.writeFileSync(readmePath, updated);
191
- }
192
-
193
- /* ============================================================================
194
- * Git init
195
- * ============================================================================
196
- */
197
-
198
- if (initGit) {
199
- try {
200
- execSync("git init", { cwd: targetDir, stdio: "ignore" });
201
- } catch {}
202
- }
203
-
204
- /* ============================================================================
205
- * Install dependencies
206
- * ============================================================================
207
- */
208
-
209
- if (installDeps) {
210
- try {
211
- execSync("npm install", { cwd: targetDir, stdio: "inherit" });
212
- } catch {
213
- console.warn("⚠️ Failed to install dependencies");
214
- }
215
- }
216
-
217
- /* ============================================================================
218
- * Done
219
- * ============================================================================
220
- */
221
-
222
- console.log("");
223
- console.log("🎉 SDK scaffolded successfully!");
224
- console.log("");
225
- console.log("Next steps:");
226
- console.log(` cd ${dirName}`);
227
- if (!installDeps) console.log(" npm install");
228
- console.log(" npm run build");
229
- console.log("");
230
- console.log("Happy hacking 🚀");
231
-
232
- /* ============================================================================
233
- * Helpers
234
- * ============================================================================
235
- */
236
-
237
- function copyDir(src, dest) {
238
- fs.mkdirSync(dest, { recursive: true });
239
-
240
- for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
241
- if (shouldIgnore(entry.name)) continue;
242
-
243
- const srcPath = path.join(src, entry.name);
244
- const destPath = path.join(dest, entry.name);
245
-
246
- if (entry.isDirectory()) {
247
- copyDir(srcPath, destPath);
248
- } else {
249
- fs.copyFileSync(srcPath, destPath);
250
- }
251
- }
252
- }
253
-
254
- function shouldIgnore(name) {
255
- return (
256
- name === "node_modules" ||
257
- name === ".git" ||
258
- name === "dist" ||
259
- name === ".DS_Store"
260
- );
261
- }
1
+ #!/usr/bin/env node
2
+ import process from "process";
3
+ import prompts from "prompts";
4
+ import { scaffold } from "../src/cli/scaffold.js";
5
+
6
+ /* ============================================================================
7
+ * Node version check
8
+ * ============================================================================
9
+ */
10
+ const REQUIRED_NODE_MAJOR = 18;
11
+ const CURRENT_NODE_MAJOR = Number(process.versions.node.split(".")[0]);
12
+
13
+ if (CURRENT_NODE_MAJOR < REQUIRED_NODE_MAJOR) {
14
+ console.error(
15
+ `❌ Node.js ${REQUIRED_NODE_MAJOR}+ is required.\n` +
16
+ ` You are using Node.js ${process.versions.node}`
17
+ );
18
+ process.exit(1);
19
+ }
20
+
21
+ /* ============================================================================
22
+ * Args parsing
23
+ * ============================================================================
24
+ */
25
+ const rawArgs = process.argv.slice(2);
26
+
27
+ const flags = {
28
+ yes: rawArgs.includes("--yes"),
29
+ noGit: rawArgs.includes("--no-git"),
30
+ noInstall: rawArgs.includes("--no-install"),
31
+ dryRun: rawArgs.includes("--dry-run"),
32
+ force: rawArgs.includes("--force"),
33
+ };
34
+
35
+ const projectName = rawArgs.find((a) => !a.startsWith("-"));
36
+
37
+ /* ============================================================================
38
+ * Interactive mode
39
+ * ============================================================================
40
+ */
41
+ let name = projectName;
42
+ let initGit = !flags.noGit;
43
+ let installDeps = !flags.noInstall;
44
+
45
+ if (!flags.yes && !name) {
46
+ const answers = await prompts(
47
+ [
48
+ {
49
+ type: "text",
50
+ name: "name",
51
+ message: "Project name:",
52
+ validate: (v) => (v ? true : "Project name is required"),
53
+ },
54
+ {
55
+ type: "confirm",
56
+ name: "initGit",
57
+ message: "Initialize git repository?",
58
+ initial: true,
59
+ },
60
+ {
61
+ type: "confirm",
62
+ name: "installDeps",
63
+ message: "Install dependencies now?",
64
+ initial: false,
65
+ },
66
+ ],
67
+ {
68
+ onCancel: () => {
69
+ console.log("\n❌ Cancelled");
70
+ process.exit(1);
71
+ },
72
+ }
73
+ );
74
+
75
+ name = answers.name;
76
+ initGit = answers.initGit;
77
+ installDeps = answers.installDeps;
78
+ }
79
+
80
+ if (!name) {
81
+ console.error("❌ Project name is required");
82
+ process.exit(1);
83
+ }
84
+
85
+ /* ============================================================================
86
+ * Execute scaffold
87
+ * ============================================================================
88
+ */
89
+ await scaffold({
90
+ projectName: name,
91
+ initGit,
92
+ installDeps,
93
+ dryRun: flags.dryRun,
94
+ force: flags.force,
95
+ });
package/package.json CHANGED
@@ -1,27 +1,36 @@
1
1
  {
2
2
  "name": "@morda-dev/create-sdk",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "CLI to scaffold a production-ready TypeScript SDK with a strict public API",
5
+ "license": "ISC",
5
6
  "type": "module",
7
+
6
8
  "bin": {
7
9
  "create-sdk": "./bin/create-sdk.js"
8
10
  },
11
+
9
12
  "files": [
10
13
  "bin",
14
+ "src",
11
15
  "template",
12
- "README.md"
16
+ "README.md",
17
+ "LICENSE"
13
18
  ],
19
+
14
20
  "engines": {
15
21
  "node": ">=18"
16
22
  },
23
+
17
24
  "repository": {
18
25
  "type": "git",
19
26
  "url": "https://github.com/mordaHQ/create-sdk.git"
20
27
  },
28
+
21
29
  "homepage": "https://github.com/mordaHQ/create-sdk",
22
30
  "bugs": {
23
31
  "url": "https://github.com/mordaHQ/create-sdk/issues"
24
32
  },
33
+
25
34
  "keywords": [
26
35
  "create-sdk",
27
36
  "typescript",
@@ -29,21 +38,21 @@
29
38
  "cli",
30
39
  "scaffold",
31
40
  "api-extractor",
32
- "library"
41
+ "library",
42
+ "esm",
43
+ "developer-tools"
33
44
  ],
45
+
34
46
  "scripts": {
35
- "test:smoke": "node ./bin/create-sdk.js __tmp-smoke-sdk --yes --no-install --no-git && node -e \"import('fs').then(fs => fs.rmSync('__tmp-smoke-sdk', { recursive: true, force: true }))\"",
36
- "changeset": "changeset",
37
- "version": "changeset version",
38
- "release": "changeset publish"
47
+ "test:smoke": "node ./bin/create-sdk.js __tmp-smoke-sdk --yes --no-install --no-git && node -e \"import('fs').then(fs => fs.rmSync('__tmp-smoke-sdk', { recursive: true, force: true }))\""
39
48
  },
49
+
40
50
  "dependencies": {
41
51
  "prompts": "^2.4.2"
42
52
  },
53
+
43
54
  "devDependencies": {
44
- "@changesets/cli": "^2.29.8",
45
55
  "@types/node": "^18.19.0",
46
56
  "undici-types": "^7.16.0"
47
- },
48
- "license": "ISC"
57
+ }
49
58
  }
@@ -0,0 +1,14 @@
1
+ export function parseArgs(rawArgs) {
2
+ const flags = {
3
+ yes: rawArgs.includes("--yes"),
4
+ noGit: rawArgs.includes("--no-git"),
5
+ noInstall: rawArgs.includes("--no-install"),
6
+ };
7
+
8
+ const projectName = rawArgs.find((a) => !a.startsWith("-"));
9
+
10
+ return {
11
+ projectName,
12
+ flags,
13
+ };
14
+ }
@@ -0,0 +1,2 @@
1
+ // reserved for future prompt extensions
2
+ export {};
package/src/cli/run.js ADDED
@@ -0,0 +1,80 @@
1
+ import prompts from "prompts";
2
+ import { parseArgs } from "./args.js";
3
+ import { scaffold } from "./scaffold.js";
4
+
5
+ export async function run(rawArgs) {
6
+ const { projectName, flags } = parseArgs(rawArgs);
7
+
8
+ const dryRun = flags.dryRun === true;
9
+
10
+ // ─────────────────────────────────────────────
11
+ // DRY-RUN MODE — NO INTERACTION, NO SIDE EFFECTS
12
+ // ─────────────────────────────────────────────
13
+ if (dryRun && !projectName) {
14
+ throw new Error("Project name is required when using --dry-run");
15
+ }
16
+
17
+ let name = projectName;
18
+ let initGit = !flags.noGit;
19
+ let installDeps = !flags.noInstall;
20
+ const force = flags.force === true;
21
+
22
+ // ❗❗❗ DRY-RUN MUST OVERRIDE EVERYTHING
23
+ if (dryRun) {
24
+ initGit = false;
25
+ installDeps = false;
26
+ }
27
+
28
+ // ─────────────────────────────────────────────
29
+ // Interactive mode (ONLY if not dry-run)
30
+ // ─────────────────────────────────────────────
31
+ if (!dryRun && !flags.yes && !projectName) {
32
+ const answers = await prompts(
33
+ [
34
+ {
35
+ type: "text",
36
+ name: "name",
37
+ message: "Project name:",
38
+ validate: (v) => (v ? true : "Project name is required"),
39
+ },
40
+ {
41
+ type: "confirm",
42
+ name: "initGit",
43
+ message: "Initialize git repository?",
44
+ initial: true,
45
+ },
46
+ {
47
+ type: "confirm",
48
+ name: "installDeps",
49
+ message: "Install dependencies now?",
50
+ initial: false,
51
+ },
52
+ ],
53
+ {
54
+ onCancel: () => {
55
+ console.log("\n❌ Cancelled");
56
+ process.exit(1);
57
+ },
58
+ }
59
+ );
60
+
61
+ name = answers.name;
62
+ initGit = answers.initGit;
63
+ installDeps = answers.installDeps;
64
+ }
65
+
66
+ if (!name) {
67
+ throw new Error("Project name is required");
68
+ }
69
+
70
+ // ─────────────────────────────────────────────
71
+ // Scaffold (SINGLE ENTRY POINT)
72
+ // ─────────────────────────────────────────────
73
+ await scaffold({
74
+ projectName: name,
75
+ initGit,
76
+ installDeps,
77
+ dryRun,
78
+ force,
79
+ });
80
+ }
@@ -0,0 +1,107 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { execSync } from "child_process";
4
+ import { fileURLToPath } from "url";
5
+ import { copyDir } from "./utils.js";
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
9
+ const templateDir = path.resolve(__dirname, "../../template");
10
+
11
+ export async function scaffold({
12
+ projectName,
13
+ initGit = true,
14
+ installDeps = false,
15
+ dryRun = false,
16
+ force = false,
17
+ }) {
18
+ if (!projectName) {
19
+ throw new Error("Project name is required");
20
+ }
21
+
22
+ const dirName = projectName.startsWith("@")
23
+ ? projectName.split("/")[1]
24
+ : projectName;
25
+
26
+ const targetDir = path.resolve(process.cwd(), dirName);
27
+
28
+ // ─────────────────────────────────────────────
29
+ // 🧪 DRY-RUN — ABSOLUTE NO-SIDE-EFFECT MODE
30
+ // ─────────────────────────────────────────────
31
+ if (dryRun) {
32
+ console.log("🧪 [dry-run] Creating SDK:", projectName);
33
+ console.log("🧪 [dry-run] Target directory:", path.join("<cwd>", dirName));
34
+ console.log("🧪 [dry-run] Would copy template from:", templateDir);
35
+ if (initGit) console.log("🧪 [dry-run] Would init git");
36
+ if (installDeps) console.log("🧪 [dry-run] Would install dependencies");
37
+ console.log("🧪 [dry-run] Done (NO filesystem changes)");
38
+ return;
39
+ }
40
+
41
+ // ─────────────────────────────────────────────
42
+ // REAL MODE — FILESYSTEM IS TOUCHED ONLY HERE
43
+ // ─────────────────────────────────────────────
44
+ if (!fs.existsSync(templateDir)) {
45
+ throw new Error(`Template directory not found: ${templateDir}`);
46
+ }
47
+
48
+ if (fs.existsSync(targetDir)) {
49
+ if (!force) {
50
+ throw new Error(`Directory "${dirName}" already exists`);
51
+ }
52
+ fs.rmSync(targetDir, { recursive: true, force: true });
53
+ }
54
+
55
+ console.log("🚀 Creating SDK:", projectName);
56
+
57
+ // copy template
58
+ copyDir(templateDir, targetDir);
59
+
60
+ // package.json
61
+ const pkgPath = path.join(targetDir, "package.json");
62
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
63
+
64
+ pkg.name = projectName;
65
+ pkg.version = "0.1.0";
66
+
67
+ // шаблон НЕ должен быть private
68
+ delete pkg.private;
69
+
70
+ // exports добавляются ТОЛЬКО тут
71
+ pkg.main = "./dist/index.js";
72
+ pkg.types = "./dist/index.d.ts";
73
+ pkg.exports = {
74
+ ".": {
75
+ import: "./dist/index.js",
76
+ types: "./dist/index.d.ts",
77
+ },
78
+ };
79
+
80
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
81
+
82
+ // README
83
+ const readmePath = path.join(targetDir, "README.md");
84
+ if (fs.existsSync(readmePath)) {
85
+ const updated = fs
86
+ .readFileSync(readmePath, "utf8")
87
+ .replace(/^# .*/m, `# ${projectName}`);
88
+ fs.writeFileSync(readmePath, updated);
89
+ }
90
+
91
+ // git
92
+ if (initGit) {
93
+ try {
94
+ execSync("git init", { cwd: targetDir, stdio: "ignore" });
95
+ } catch {}
96
+ }
97
+
98
+ // deps
99
+ if (installDeps) {
100
+ execSync("npm install", {
101
+ cwd: targetDir,
102
+ stdio: "inherit",
103
+ });
104
+ }
105
+
106
+ console.log("🎉 SDK scaffolded successfully!");
107
+ }
@@ -0,0 +1,28 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ export function copyDir(src, dest) {
5
+ fs.mkdirSync(dest, { recursive: true });
6
+
7
+ for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
8
+ if (shouldIgnore(entry.name)) continue;
9
+
10
+ const srcPath = path.join(src, entry.name);
11
+ const destPath = path.join(dest, entry.name);
12
+
13
+ if (entry.isDirectory()) {
14
+ copyDir(srcPath, destPath);
15
+ } else {
16
+ fs.copyFileSync(srcPath, destPath);
17
+ }
18
+ }
19
+ }
20
+
21
+ function shouldIgnore(name) {
22
+ return (
23
+ name === "node_modules" ||
24
+ name === ".git" ||
25
+ name === "dist" ||
26
+ name === ".DS_Store"
27
+ );
28
+ }
@@ -1,30 +1,30 @@
1
- name: CI
2
-
3
- on:
4
- pull_request:
5
- branches: [ main ]
6
- push:
7
- branches: [ main ]
8
-
9
- jobs:
10
- build-and-api-check:
11
- runs-on: ubuntu-latest
12
-
13
- steps:
14
- - name: Checkout repo
15
- uses: actions/checkout@v4
16
-
17
- - name: Setup Node
18
- uses: actions/setup-node@v4
19
- with:
20
- node-version: 20
21
- cache: npm
22
-
23
- - name: Install dependencies
24
- run: npm ci
25
-
26
- - name: Build
27
- run: npm run build
28
-
29
- - name: API Extractor check
30
- run: npm run api:check
1
+ name: CI
2
+
3
+ on:
4
+ pull_request:
5
+ branches: [ main ]
6
+ push:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ build-and-api-check:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - name: Checkout repo
15
+ uses: actions/checkout@v4
16
+
17
+ - name: Setup Node
18
+ uses: actions/setup-node@v4
19
+ with:
20
+ node-version: 20
21
+ cache: npm
22
+
23
+ - name: Install dependencies
24
+ run: npm ci
25
+
26
+ - name: Build
27
+ run: npm run build
28
+
29
+ - name: API Extractor check
30
+ run: npm run api:check
package/template/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Morda Dev
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
- IN THE SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Morda Dev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
+ IN THE SOFTWARE.
@@ -1,49 +1,49 @@
1
- # @morda-dev/project-template
2
-
3
- Production-ready TypeScript SDK template with a strict public API, ESM-first setup,
4
- and best practices baked in.
5
-
6
- This package can be used as:
7
- - a base for building your own SDK
8
- - a reference for ESM + TypeScript library architecture
9
- - a starting point for production-ready npm packages
10
-
11
- ---
12
-
13
- ## Installation
14
-
15
- ```bash
16
- npm install @morda-dev/project-template
17
- ```
18
-
19
- ## Usage
20
-
21
- ```ts
22
- import { getUser, sumAges } from '@morda-dev/project-template';
23
-
24
- const user = getUser(1);
25
- console.log(user);
26
-
27
- const totalAge = sumAges([
28
- { id: 1, name: 'Alice', age: 20 },
29
- { id: 2, name: 'Bob', age: 30 },
30
- ]);
31
-
32
- console.log(totalAge);
33
- ```
34
-
35
- ## API
36
- ### getUser(id: number)
37
-
38
- Returns a user wrapped in `ApiResult`.
39
-
40
- ### sumAges(users: User[])
41
-
42
- Returns the sum of all user ages.
43
-
44
- ## License
45
-
46
- ISC
47
-
48
-
49
- ---
1
+ # @morda-dev/project-template
2
+
3
+ Production-ready TypeScript SDK template with a strict public API, ESM-first setup,
4
+ and best practices baked in.
5
+
6
+ This package can be used as:
7
+ - a base for building your own SDK
8
+ - a reference for ESM + TypeScript library architecture
9
+ - a starting point for production-ready npm packages
10
+
11
+ ---
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @morda-dev/project-template
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```ts
22
+ import { getUser, sumAges } from '@morda-dev/project-template';
23
+
24
+ const user = getUser(1);
25
+ console.log(user);
26
+
27
+ const totalAge = sumAges([
28
+ { id: 1, name: 'Alice', age: 20 },
29
+ { id: 2, name: 'Bob', age: 30 },
30
+ ]);
31
+
32
+ console.log(totalAge);
33
+ ```
34
+
35
+ ## API
36
+ ### getUser(id: number)
37
+
38
+ Returns a user wrapped in `ApiResult`.
39
+
40
+ ### sumAges(users: User[])
41
+
42
+ Returns the sum of all user ages.
43
+
44
+ ## License
45
+
46
+ ISC
47
+
48
+
49
+ ---
@@ -1,32 +1,32 @@
1
- ## API Report File for "@morda-dev/project-template"
2
-
3
- > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4
-
5
- ```ts
6
-
7
- // @public
8
- export type ApiResult<T> = {
9
- success: true;
10
- data: T;
11
- } | {
12
- success: false;
13
- error: string;
14
- };
15
-
16
- // @public
17
- export function getUser(id: number): ApiResult<User>;
18
-
19
- // @public
20
- export function sumAges(users: User[]): number;
21
-
22
- // @public
23
- export interface User {
24
- // (undocumented)
25
- age: number;
26
- // (undocumented)
27
- id: number;
28
- // (undocumented)
29
- name: string;
30
- }
31
-
32
- ```
1
+ ## API Report File for "@morda-dev/project-template"
2
+
3
+ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4
+
5
+ ```ts
6
+
7
+ // @public
8
+ export type ApiResult<T> = {
9
+ success: true;
10
+ data: T;
11
+ } | {
12
+ success: false;
13
+ error: string;
14
+ };
15
+
16
+ // @public
17
+ export function getUser(id: number): ApiResult<User>;
18
+
19
+ // @public
20
+ export function sumAges(users: User[]): number;
21
+
22
+ // @public
23
+ export interface User {
24
+ // (undocumented)
25
+ age: number;
26
+ // (undocumented)
27
+ id: number;
28
+ // (undocumented)
29
+ name: string;
30
+ }
31
+
32
+ ```
@@ -5,21 +5,6 @@
5
5
  "license": "ISC",
6
6
  "type": "module",
7
7
 
8
- "main": "./dist/index.js",
9
- "types": "./dist/index.d.ts",
10
-
11
- "exports": {
12
- ".": {
13
- "import": "./dist/index.js",
14
- "types": "./dist/index.d.ts"
15
- }
16
- },
17
-
18
- "files": [
19
- "dist",
20
- "etc"
21
- ],
22
-
23
8
  "sideEffects": false,
24
9
 
25
10
  "engines": {
@@ -1,25 +1,25 @@
1
- /**
2
- * @packageDocumentation
3
- *
4
- * Production-ready TypeScript SDK template.
5
- *
6
- * This file defines the public API surface of the package.
7
- * Only symbols exported from this file are considered stable
8
- * and part of the public contract.
9
- */
10
-
11
- /* ============================================================================
12
- * Types (Public)
13
- * ============================================================================
14
- */
15
-
16
- /** @public */
17
- export type { User, ApiResult } from "./types/user.js";
18
-
19
- /* ============================================================================
20
- * Functions (Public)
21
- * ============================================================================
22
- */
23
-
24
- /** @public */
25
- export { getUser, sumAges } from "./modules/user.js";
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * Production-ready TypeScript SDK template.
5
+ *
6
+ * This file defines the public API surface of the package.
7
+ * Only symbols exported from this file are considered stable
8
+ * and part of the public contract.
9
+ */
10
+
11
+ /* ============================================================================
12
+ * Types (Public)
13
+ * ============================================================================
14
+ */
15
+
16
+ /** @public */
17
+ export type { User, ApiResult } from "./types/user.js";
18
+
19
+ /* ============================================================================
20
+ * Functions (Public)
21
+ * ============================================================================
22
+ */
23
+
24
+ /** @public */
25
+ export { getUser, sumAges } from "./modules/user.js";
@@ -1,31 +1,31 @@
1
- import { ApiResult, User } from "../types/user.js";
2
-
3
- /**
4
- * @public
5
- * Get a user by id
6
- */
7
- export function getUser(id: number): ApiResult<User> {
8
- if (id <= 0) {
9
- return {
10
- success: false,
11
- error: "Invalid user id",
12
- };
13
- }
14
-
15
- return {
16
- success: true,
17
- data: {
18
- id,
19
- name: "John Doe",
20
- age: 30,
21
- },
22
- };
23
- }
24
-
25
- /**
26
- * @public
27
- * Sum ages of users
28
- */
29
- export function sumAges(users: User[]): number {
30
- return users.reduce((sum, user) => sum + user.age, 0);
31
- }
1
+ import { ApiResult, User } from "../types/user.js";
2
+
3
+ /**
4
+ * @public
5
+ * Get a user by id
6
+ */
7
+ export function getUser(id: number): ApiResult<User> {
8
+ if (id <= 0) {
9
+ return {
10
+ success: false,
11
+ error: "Invalid user id",
12
+ };
13
+ }
14
+
15
+ return {
16
+ success: true,
17
+ data: {
18
+ id,
19
+ name: "John Doe",
20
+ age: 30,
21
+ },
22
+ };
23
+ }
24
+
25
+ /**
26
+ * @public
27
+ * Sum ages of users
28
+ */
29
+ export function sumAges(users: User[]): number {
30
+ return users.reduce((sum, user) => sum + user.age, 0);
31
+ }
@@ -1,17 +1,17 @@
1
- /**
2
- * @public
3
- * User entity
4
- */
5
- export interface User {
6
- id: number;
7
- name: string;
8
- age: number;
9
- }
10
-
11
- /**
12
- * @public
13
- * Generic API result
14
- */
15
- export type ApiResult<T> =
16
- | { success: true; data: T }
17
- | { success: false; error: string };
1
+ /**
2
+ * @public
3
+ * User entity
4
+ */
5
+ export interface User {
6
+ id: number;
7
+ name: string;
8
+ age: number;
9
+ }
10
+
11
+ /**
12
+ * @public
13
+ * Generic API result
14
+ */
15
+ export type ApiResult<T> =
16
+ | { success: true; data: T }
17
+ | { success: false; error: string };