@mcp-tool-kit/shared 0.1.5 → 1.0.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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 Watermark Design
3
+ Copyright (c) 2026 my-mcp-hub
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,12 +1 @@
1
- import Handlebars from "handlebars";
2
-
3
- //#region src/handlebars/register.ts
4
- function registerHandlebarsHelpers() {
5
- Handlebars.registerHelper("includes", (array, value) => array && Array.isArray(array) && array.includes(value));
6
- Handlebars.registerHelper("and", (a, b) => a && b);
7
- Handlebars.registerHelper("or", (a, b) => a || b);
8
- Handlebars.registerHelper("eq", (a, b) => a === b);
9
- }
10
-
11
- //#endregion
12
- export { registerHandlebarsHelpers };
1
+ import e from"handlebars";function r(){e.registerHelper("includes",(e,r)=>e&&Array.isArray(e)&&e.includes(r)),e.registerHelper("and",(e,r)=>e&&r),e.registerHelper("or",(e,r)=>e||r),e.registerHelper("eq",(e,r)=>e===r)}export{r as registerHandlebarsHelpers};
package/dist/index.js CHANGED
@@ -1,3 +1 @@
1
- import { createProject, fileExists, installDependencies, sleep } from "./projectSetup.js";
2
-
3
- export { createProject, fileExists, installDependencies, sleep };
1
+ import{createProject as o,fileExists as p,installDependencies as r,sleep as t}from"./projectSetup.js";export{o as createProject,p as fileExists,r as installDependencies,t as sleep};
@@ -1,83 +1 @@
1
- import { registerHandlebarsHelpers } from "./handlebars/register.js";
2
- import { spawn } from "node:child_process";
3
- import { access, constants, cp, mkdir, readFile, readdir, rename, rmdir, stat, unlink, writeFile } from "node:fs/promises";
4
- import { join } from "node:path";
5
- import { setTimeout as sleep } from "node:timers/promises";
6
- import Handlebars from "handlebars";
7
-
8
- //#region src/projectSetup.ts
9
- registerHandlebarsHelpers();
10
- async function renameFiles(currentDir) {
11
- const renameMap = {
12
- _git: ".git",
13
- _husky: ".husky",
14
- _github: ".github"
15
- };
16
- const items = await readdir(currentDir, { recursive: true });
17
- for (const item of items) {
18
- if (!(item in renameMap)) continue;
19
- await rename(join(currentDir, item), join(currentDir, renameMap[item]));
20
- }
21
- }
22
- async function compileTemplateFiles(currentDir, templateData) {
23
- const items = await readdir(currentDir, { recursive: true });
24
- for (const item of items) {
25
- const itemPath = join(currentDir, item);
26
- const itemStat = await stat(itemPath);
27
- if (itemStat.isDirectory()) continue;
28
- const content = await readFile(itemPath, "utf-8");
29
- const template = Handlebars.compile(content);
30
- const newContent = template(templateData);
31
- if (newContent.trim() === "") {
32
- await unlink(itemPath);
33
- continue;
34
- }
35
- if (itemPath.endsWith(".hbs")) {
36
- const newItemPath = itemPath.slice(0, -4);
37
- await writeFile(newItemPath, newContent, "utf-8");
38
- await unlink(itemPath);
39
- } else await writeFile(itemPath, newContent, "utf-8");
40
- }
41
- }
42
- async function removeEmptyDirectories(currentDir) {
43
- const items = await readdir(currentDir, {
44
- recursive: true,
45
- withFileTypes: true
46
- });
47
- const directories = items.filter((item) => item.isDirectory()).map((item) => join(item.parentPath || currentDir, item.name)).sort((a, b) => b.split("/").length - a.split("/").length);
48
- for (const dirPath of directories) try {
49
- const dirItems = await readdir(dirPath);
50
- if (dirItems.length === 0) await rmdir(dirPath);
51
- } catch {}
52
- }
53
- async function fileExists(path) {
54
- try {
55
- await access(path, constants.F_OK);
56
- return true;
57
- } catch {
58
- return false;
59
- }
60
- }
61
- function installDependencies(currentDir) {
62
- return new Promise((resolve, reject) => {
63
- const npm = spawn("npm", ["install"], {
64
- cwd: currentDir,
65
- stdio: "pipe"
66
- });
67
- npm.on("close", (code) => {
68
- if (code === 0) resolve();
69
- else reject(/* @__PURE__ */ new Error(`npm install failed with code ${code}`));
70
- });
71
- npm.on("error", reject);
72
- });
73
- }
74
- async function createProject(targetPath, templatePath, templateData) {
75
- await mkdir(targetPath, { recursive: true });
76
- await cp(templatePath, targetPath, { recursive: true });
77
- await renameFiles(targetPath);
78
- await compileTemplateFiles(targetPath, templateData);
79
- await removeEmptyDirectories(targetPath);
80
- }
81
-
82
- //#endregion
83
- export { createProject, fileExists, installDependencies, sleep };
1
+ import{registerHandlebarsHelpers as t}from"./handlebars/register.js";import{spawn as i}from"node:child_process";import{access as r,constants as a,cp as o,mkdir as n,readFile as e,readdir as s,rename as c,rmdir as f,stat as m,unlink as u,writeFile as w}from"node:fs/promises";import{join as p}from"node:path";import{setTimeout as h}from"node:timers/promises";import l from"handlebars";async function d(t){try{return await r(t,a.F_OK),!0}catch{return!1}}function y(t){return new Promise((r,a)=>{const o=i("npm",["install"],{cwd:t,stdio:"pipe"});o.on("close",t=>{0===t?r():a(new Error(`npm install failed with code ${t}`))}),o.on("error",a)})}async function g(t,i,r){await n(t,{recursive:!0}),await o(i,t,{recursive:!0}),await async function(t){const i={_git:".git",_husky:".husky",_github:".github"},r=await s(t,{recursive:!0});for(const a of r)a in i&&await c(p(t,a),p(t,i[a]))}(t),await async function(t,i){const r=await s(t,{recursive:!0});for(const a of r){const r=p(t,a);if((await m(r)).isDirectory())continue;const o=await e(r,"utf-8"),n=l.compile(o)(i);""!==n.trim()?r.endsWith(".hbs")?(await w(r.slice(0,-4),n,"utf-8"),await u(r)):await w(r,n,"utf-8"):await u(r)}}(t,r),await async function(t){const i=(await s(t,{recursive:!0,withFileTypes:!0})).filter(t=>t.isDirectory()).map(i=>p(i.parentPath||t,i.name)).sort((t,i)=>i.split("/").length-t.split("/").length);for(const t of i)try{0===(await s(t)).length&&await f(t)}catch{}}(t)}t();export{g as createProject,d as fileExists,y as installDependencies,h as sleep};
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@mcp-tool-kit/shared",
3
- "version": "0.1.5",
3
+ "version": "1.0.0",
4
4
  "description": "A CLI tool to create MCP (Model Context Protocol) applications with ease.",
5
5
  "type": "module",
6
6
  "author": "zhensherlock",
7
- "homepage": "https://github.com/my-mcp-hub/mcp-kit/tree/master/packages/shared#readme",
7
+ "homepage": "https://my-mcp-hub.github.io/mcp-kit/",
8
8
  "keywords": [
9
9
  "mcp",
10
10
  "mcp server",
@@ -46,7 +46,8 @@
46
46
  },
47
47
  "scripts": {
48
48
  "clean:dist": "rimraf dist",
49
+ "dev": "rolldown -c rolldown.config.ts --watch --no-clear-screen",
49
50
  "build:types": "tsc",
50
- "build": "cross-env NODE_ENV=production && npm run clean:dist && npm run build:types && rolldown -c rolldown.config.ts"
51
+ "build": "npm run clean:dist && npm run build:types && rolldown -c rolldown.config.ts"
51
52
  }
52
53
  }