@salesforce/pwa-kit-mcp
Version:
MCP server that helps you build Salesforce Commerce Cloud PWA Kit Composable Storefront
136 lines (133 loc) • 5.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _zod = require("zod");
var _shelljs = _interopRequireDefault(require("shelljs"));
var _fs = _interopRequireDefault(require("fs"));
var _path = _interopRequireDefault(require("path"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } /*
* Copyright (c) 2025, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
class VersionControlGitTool {
name = 'version_control_git';
description = 'Manages the version control using git';
inputSchema = {
initGit: _zod.z.boolean().describe('Do you want to commit your files locally through git? (yes/no)'),
current_project_directory: _zod.z.string().describe('The absolute path to the current working directory where git actions will be performed.')
};
handler = (() => {
var _this = this;
return function () {
var _ref = _asyncToGenerator(function* (args) {
try {
if (!args || !args.initGit || !args.current_project_directory) {
return {
role: 'system',
content: []
};
}
const {
current_project_directory
} = args;
_this.handleGitVersionControl(current_project_directory);
return {
role: 'system',
content: [{
type: 'text',
text: 'Git version control initialized and committed locally.'
}]
};
} catch (error) {
return {
role: 'system',
content: [{
type: 'text',
text: `Error: ${error.message}`
}]
};
}
});
return function (_x) {
return _ref.apply(this, arguments);
};
}();
})();
/**
* Handles the version control of your project using git.
* If the directory is not a git repo, it creates a basic .gitignore, runs git init, adds all files, and makes an initial commit.
* If already a git repo, it skips initialization and .gitignore creation, and just adds and commits all files locally.
* @param {string} directory - The directory to initialize the git repository in.
*/
handleGitVersionControl(directory) {
if (!_shelljs.default.which('git')) {
throw new Error('git is not installed or not found in PATH. Please install git to initialize a repository.');
}
const isGitRepo = _fs.default.existsSync(_path.default.join(directory, '.git'));
let result;
if (isGitRepo) {
// Already a git repo: only add and commit
result = _shelljs.default.exec('git add .', {
cwd: directory,
silent: true
});
if (result.code !== 0) throw new Error(`git add failed: ${result.stderr || result.stdout}`);
result = _shelljs.default.exec('git commit -m "Initial commit"', {
cwd: directory,
silent: true
});
if (result.code !== 0) throw new Error(`git commit failed: ${result.stderr || result.stdout}`);
} else {
// Not a git repo: create .gitignore, init, add, commit
this.createBasicGitignore(directory);
result = _shelljs.default.exec('git init', {
cwd: directory,
silent: true
});
if (result.code !== 0) throw new Error(`git init failed: ${result.stderr || result.stdout}`);
result = _shelljs.default.exec('git add .', {
cwd: directory,
silent: true
});
if (result.code !== 0) throw new Error(`git add failed: ${result.stderr || result.stdout}`);
result = _shelljs.default.exec('git commit -m "Initial commit"', {
cwd: directory,
silent: true
});
if (result.code !== 0) throw new Error(`git commit failed: ${result.stderr || result.stdout}`);
}
}
/**
* Creates a basic .gitignore file in the given directory.
* @param {string} directory - The directory to create the .gitignore file in.
*/
createBasicGitignore(directory) {
const gitignorePath = _path.default.join(directory, '.gitignore');
if (!_fs.default.existsSync(gitignorePath)) {
_fs.default.writeFileSync(gitignorePath, `# Node
node_modules/
.env
.DS_Store
npm-debug.log
yarn-debug.log
yarn-error.log
coverage/
dist/
build/
.next/
out/
logs/
*.log
.idea/
.vscode/
`);
}
}
}
var _default = exports.default = VersionControlGitTool;