@mcp-tool-kit/shared 0.0.1 → 0.0.3

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/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import { createProject, installDependencies, sleep } from "./projectSetup.js";
2
+
3
+ export { createProject, installDependencies, sleep };
@@ -0,0 +1,62 @@
1
+ import { setTimeout as sleep } from "timers/promises";
2
+ import { cp, mkdir, readFile, readdir, rename, stat, writeFile } from "fs/promises";
3
+ import path from "path";
4
+ import { spawn } from "child_process";
5
+
6
+ //#region src/projectSetup.ts
7
+ async function renameFiles(currentDir) {
8
+ const renameMap = {
9
+ _env: ".env",
10
+ _gitignore: ".gitignore",
11
+ _git: ".git",
12
+ _nvmrc: ".nvmrc",
13
+ _prettierrc: ".prettierrc",
14
+ _husky: ".husky",
15
+ _github: ".github"
16
+ };
17
+ const items = await readdir(currentDir, { recursive: true });
18
+ for (const item of items) {
19
+ if (!(item in renameMap)) continue;
20
+ await rename(path.join(currentDir, item), path.join(currentDir, renameMap[item]));
21
+ }
22
+ }
23
+ async function replaceVariables(currentDir, replacements) {
24
+ const variables = {
25
+ "{{PROJECT_NAME}}": replacements.projectName,
26
+ "{{YEAR}}": (/* @__PURE__ */ new Date()).getFullYear().toString()
27
+ };
28
+ const items = await readdir(currentDir, { recursive: true });
29
+ for (const item of items) {
30
+ const itemPath = path.join(currentDir, item);
31
+ const itemStat = await stat(itemPath);
32
+ if (itemStat.isDirectory()) continue;
33
+ for (const [key, value] of Object.entries(variables)) {
34
+ const content = await readFile(itemPath, "utf-8");
35
+ const regex = new RegExp(key, "g");
36
+ const newContent = content.replace(regex, value);
37
+ await writeFile(itemPath, newContent, "utf-8");
38
+ }
39
+ }
40
+ }
41
+ function installDependencies(currentDir) {
42
+ return new Promise((resolve, reject) => {
43
+ const npm = spawn("npm", ["install"], {
44
+ cwd: currentDir,
45
+ stdio: "pipe"
46
+ });
47
+ npm.on("close", (code) => {
48
+ if (code === 0) resolve();
49
+ else reject(/* @__PURE__ */ new Error(`npm install failed with code ${code}`));
50
+ });
51
+ npm.on("error", reject);
52
+ });
53
+ }
54
+ async function createProject(targetPath, templatePath, replacements) {
55
+ await mkdir(targetPath, { recursive: true });
56
+ await cp(templatePath, targetPath, { recursive: true });
57
+ await renameFiles(targetPath);
58
+ await replaceVariables(targetPath, replacements);
59
+ }
60
+
61
+ //#endregion
62
+ export { createProject, installDependencies, sleep };
@@ -0,0 +1 @@
1
+ export * from './projectSetup';
@@ -0,0 +1,6 @@
1
+ import { setTimeout as sleep } from 'timers/promises';
2
+ export declare function installDependencies(currentDir: string): Promise<void>;
3
+ export declare function createProject(targetPath: string, templatePath: string, replacements: {
4
+ projectName: string;
5
+ }): Promise<void>;
6
+ export { sleep };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcp-tool-kit/shared",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "mcp tool kit shared",
5
5
  "type": "module",
6
6
  "author": "zhensherlock",
@@ -40,8 +40,6 @@
40
40
  "scripts": {
41
41
  "clean:dist": "rimraf dist",
42
42
  "build:types": "tsc",
43
- "build": "npm run clean:dist && npm run build:types && rolldown -c rolldown.config.ts",
44
- "test": "vitest run",
45
- "coverage": "rimraf coverage && vitest run --coverage"
43
+ "build": "cross-env NODE_ENV=production && npm run clean:dist && npm run build:types && rolldown -c rolldown.config.ts"
46
44
  }
47
45
  }