@morda-dev/create-sdk 1.1.3 → 1.2.0

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.
@@ -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,19 +1,25 @@
1
1
  {
2
2
  "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
3
 
4
- "mainEntryPointFilePath": "./dist/index.d.ts",
4
+ "projectFolder": ".",
5
+
6
+ "mainEntryPointFilePath": "<projectFolder>/dist/index.d.ts",
7
+
8
+ "dtsRollup": {
9
+ "enabled": false
10
+ },
5
11
 
6
12
  "apiReport": {
7
13
  "enabled": true,
8
- "reportFileName": "project-template.api.md",
9
- "reportFolder": "./etc"
14
+ "reportFolder": "<projectFolder>/api",
15
+ "reportFileName": "api-report.md"
10
16
  },
11
17
 
12
18
  "docModel": {
13
19
  "enabled": false
14
20
  },
15
21
 
16
- "dtsRollup": {
22
+ "tsdocMetadata": {
17
23
  "enabled": false
18
24
  },
19
25
 
@@ -23,7 +29,6 @@
23
29
  "logLevel": "warning"
24
30
  }
25
31
  },
26
-
27
32
  "extractorMessageReporting": {
28
33
  "default": {
29
34
  "logLevel": "warning"
@@ -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,27 +5,26 @@
5
5
  "license": "ISC",
6
6
  "type": "module",
7
7
 
8
+ "sideEffects": false,
9
+
10
+ "engines": {
11
+ "node": ">=18"
12
+ },
13
+
8
14
  "main": "./dist/index.js",
9
15
  "types": "./dist/index.d.ts",
10
16
 
11
17
  "exports": {
12
18
  ".": {
13
- "import": "./dist/index.js",
14
- "types": "./dist/index.d.ts"
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
15
21
  }
16
22
  },
17
23
 
18
24
  "files": [
19
- "dist",
20
- "etc"
25
+ "dist"
21
26
  ],
22
27
 
23
- "sideEffects": false,
24
-
25
- "engines": {
26
- "node": ">=18"
27
- },
28
-
29
28
  "repository": {
30
29
  "type": "git",
31
30
  "url": "https://github.com/mordaHQ/project-template.git"
@@ -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
+ }