@ideascol/cli-maker
Version:
A simple library to help create CLIs
133 lines (132 loc) • 5.3 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.createCommand = void 0;
const interfaces_1 = require("../../interfaces");
const commons = __importStar(require("./common"));
const libraries = __importStar(require("../libraries"));
exports.createCommand = {
name: 'create',
description: 'Generate a base project for building a CLI',
params: [
{
name: "name",
description: "The name of the library, ex: @company/awesome-cli",
required: true,
type: interfaces_1.ParamType.Package
},
{
name: "description",
description: "The description of the library to create",
required: true,
type: interfaces_1.ParamType.Text
},
{
name: "author",
description: "The author of the library",
required: true,
type: interfaces_1.ParamType.Text
},
{
name: "email",
description: "The email of the author",
required: true,
type: interfaces_1.ParamType.Email
},
{
name: "package_manager",
description: "Select your preferred package manager",
required: true,
type: interfaces_1.ParamType.List,
options: ['npm', 'bun']
},
{
name: "git_init",
description: "Do you want to initialize a git repository?",
required: true,
type: interfaces_1.ParamType.List,
options: ['yes', 'no']
},
],
action: async (args) => {
const { name, description, author, email, package_manager } = args;
const projectName = name.split('/')[1] || name;
const isValid = await libraries.validateProjectDirectory(projectName);
if (!isValid) {
return;
}
const isEmpty = commons.isFolderEmpty();
if (!isEmpty) {
commons.createNewFolder(projectName);
commons.moveToFolder(projectName);
}
await commons.initializeProject();
await commons.createTsConfigFiles();
await commons.createProjectStructure();
await commons.createGitIgnore();
await commons.generateGithubAction(package_manager);
await commons.generateGreetExample();
await commons.generateLibIndex();
await commons.generateBinTs(name, description);
await commons.generateIndexTs(name, description);
await commons.generateCommandExample();
const newScripts = package_manager === 'bun' ? {
"build": "tsc --emitDeclarationOnly && bun build ./src/index.ts ./src/bin/cli.ts --target=node --outdir ./dist --format cjs",
"build:test": "bun build ./src/tests/*.ts --target=node --outdir dist/tests --format cjs",
"test": "bun test",
"prepublishOnly": "bun run build",
"start": "bun run src/cli.ts"
} : {
"build": "tsc",
"build:test": "tsc -p tsconfig.test.json",
"test": "npm run build:test && find dist/tests -name '*.test.js' -exec node {} \\;",
"prepublishOnly": "npm run build",
"start": "npm run build && node ./dist/cli.js"
};
await libraries.addScriptsToPackageJson(newScripts, name, description, author, email);
await commons.createBinFile();
await commons.createReadmeFile(name, description);
await commons.createCliTestFile(name, description, package_manager);
await commons.createTestLibFile(package_manager);
await libraries.installDependencies(package_manager, name);
if (args.git_init === 'yes') {
await commons.initializeGit();
}
else {
console.log('Skipping git initialization.');
}
console.log('Project initialized successfully.');
}
};