Skip to content

Commit b7726c4

Browse files
committed
Add gitignore copying for template, add npmignore, switch to ESM
1 parent b97aaaa commit b7726c4

File tree

10 files changed

+75
-11
lines changed

10 files changed

+75
-11
lines changed

packages/create-mcp-ts/.npmignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.mcp-ts/
2+
node_modules/
3+
4+
# System
5+
.DS_Store
6+
.idea/
7+
.vscode/

packages/create-mcp-ts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"cli",
1919
"generator"
2020
],
21+
"type": "module",
2122
"bin": "./dist/index.js",
2223
"scripts": {
2324
"build": "tsup src/index.ts --dts --clean",

packages/create-mcp-ts/src/index.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
printUsingTemplate,
1616
templateDescriptionString,
1717
usageString,
18-
} from "./utils";
18+
} from "./utils.js";
1919

2020
// Load package.json for version and name information
2121
const packageJson = require("../package.json") as any;
@@ -37,6 +37,15 @@ const program = new Command(packageJson.name)
3737

3838
const options = program.opts();
3939

40+
// Helper function to handle special file names during template copying
41+
function getDestinationFileName(srcFileName: string): string {
42+
// Handle special cases for template files
43+
if (srcFileName === "gitignore") {
44+
return ".gitignore";
45+
}
46+
return srcFileName;
47+
}
48+
4049
async function run() {
4150
// Clean up project directory string input
4251
if (typeof projectDir === "string") {
@@ -93,7 +102,19 @@ async function run() {
93102
);
94103
process.exit(1);
95104
}
96-
fs.copySync(localTemplatePath, resolvedProjectPath);
105+
// Copy files with special file name handling
106+
const templateFiles = fs
107+
.readdirSync(localTemplatePath)
108+
.filter((file) => !["node_modules", ".git"].includes(file));
109+
110+
templateFiles.forEach((file) => {
111+
const srcPath = path.join(localTemplatePath, file);
112+
const destPath = path.join(
113+
resolvedProjectPath,
114+
getDestinationFileName(file)
115+
);
116+
fs.copySync(srcPath, destPath);
117+
});
97118
} else {
98119
// For npm packages, first create a package.json
99120
const tempPackageJson = {
@@ -120,10 +141,13 @@ async function run() {
120141
.readdirSync(templatePath)
121142
.filter((file) => !["node_modules", ".git"].includes(file));
122143

123-
// Copy each file/directory from the template
144+
// Copy each file/directory from the template with special file name handling
124145
templateFiles.forEach((file) => {
125146
const srcPath = path.join(templatePath, file);
126-
const destPath = path.join(resolvedProjectPath, file);
147+
const destPath = path.join(
148+
resolvedProjectPath,
149+
getDestinationFileName(file)
150+
);
127151
fs.copySync(srcPath, destPath);
128152
});
129153

packages/mcp-scripts/.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/
2+
3+
# System
4+
.DS_Store
5+
.idea/
6+
.vscode/

packages/mcp-scripts/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
"url": "https://github.com/stephencme/create-mcp-ts.git",
1010
"directory": "packages/mcp-ts-template-default"
1111
},
12+
"type": "module",
1213
"bin": "./dist/index.js",
1314
"scripts": {
14-
"build": "tsup src/index.ts src/setup.ts src/eject.js --dts --clean"
15+
"build": "tsup src/index.ts src/setup.ts src/eject.js --format esm --dts --clean"
1516
},
1617
"dependencies": {
1718
"@types/node": "^22.13.13",

packages/mcp-scripts/src/eject.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
const fs = require("fs");
2-
const path = require("path");
1+
#!/usr/bin/env node
2+
3+
import fs from "fs";
4+
import path from "path";
5+
import { fileURLToPath } from "url";
6+
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = path.dirname(__filename);
39

410
console.log("Ejecting from mcp-scripts...");
511

@@ -127,11 +133,11 @@ try {
127133
let scriptsUpdated = false;
128134

129135
if (freshProjectScripts.dev === "mcp-scripts dev") {
130-
freshProjectScripts.dev = "tsup src/index.ts --dts --watch";
136+
freshProjectScripts.dev = "tsup src/index.ts --format esm --dts --watch";
131137
scriptsUpdated = true;
132138
}
133139
if (freshProjectScripts.build === "mcp-scripts build") {
134-
freshProjectScripts.build = "tsup src/index.ts --dts --clean";
140+
freshProjectScripts.build = "tsup src/index.ts --format esm --dts --clean";
135141
scriptsUpdated = true;
136142
}
137143
if (freshProjectScripts.setup === "mcp-scripts setup") {

packages/mcp-scripts/src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
import { spawn } from "child_process";
44
import { join } from "path";
5+
import { fileURLToPath } from "url";
6+
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = fileURLToPath(new URL(".", import.meta.url));
59

610
// Define commands
711
const commands = {
8-
dev: "tsup src/index.ts --dts --watch",
9-
build: "tsup src/index.ts --dts --clean",
12+
dev: "tsup src/index.ts --format esm --dts --watch",
13+
build: "tsup src/index.ts --format esm --dts --clean",
1014
setup: `node ${join(__dirname, "setup.js")}`,
1115
eject: `node ${join(__dirname, "eject.js")}`,
1216
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dist/
2+
node_modules/
3+
4+
# System
5+
.DS_Store
6+
.idea/
7+
.vscode/
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dist/
2+
node_modules/
3+
4+
# System
5+
.DS_Store
6+
.idea/
7+
.vscode/

packages/mcp-ts-template-default/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"url": "https://github.com/stephencme/create-mcp-ts.git",
1010
"directory": "packages/mcp-ts-template-default"
1111
},
12+
"type": "module",
1213
"bin": "./dist/index.js",
1314
"scripts": {
1415
"dev": "mcp-scripts dev",

0 commit comments

Comments
 (0)