UNPKG

@ideascol/cli-maker

Version:
217 lines (190 loc) 4.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.tsconfigTestTemplate = exports.tsconfigBaseTemplate = exports.tsconfigTemplate = exports.githubactionBunTemplate = exports.githubactionNpmTemplate = exports.templateCommand = exports.templateBin = exports.templateGreet = exports.templateReadme = exports.template = exports.templateIndex = void 0; exports.templateIndex = `export * from './lib'; `; exports.template = `import { CLI } from '@ideascol/cli-maker'; import CommandGreet from './commands/greetCommand'; const cli = new CLI('{{cliName}}', '{{cliDescription}}', { interactive: true, version: '1.0.0', introAnimation: { enabled: true, preset: 'retro-space', // Change to other presets or override fields below title: '{{cliName}}', subtitle: '{{cliDescription}}', }, }); cli.command(CommandGreet); cli.parse(process.argv); export { cli }; `; exports.templateReadme = `# {{cliName}} {{cliDescription}} ## Quick start \`\`\`bash # Using npm npx {{cliName}} # Using bun bunx {{cliName}} \`\`\` ## Installation \`\`\`bash # Using npm npm install -g {{cliName}} # Using bun bun install -g {{cliName}} \`\`\` ## Usage as cli \`\`\`bash # Using npm npm link # to test the cli locally # Using bun bun link # to test the cli locally {{binName}} greet --name=John \`\`\` ## Usage as library \`\`\`ts import { Greet } from '{{cliName}}'; Greet('John'); // should print 'Hello, John!' \`\`\` `; exports.templateGreet = `// Greet example const Greet = (name: string) => { const message = \`Hello, \${name}!\`; console.log(message); return message; } export { Greet }; `; exports.templateBin = `#!/usr/bin/env node require('../cli.js'); `; exports.templateCommand = `import { Command, ParamType } from '@ideascol/cli-maker'; import { Greet } from '../lib'; let commandGreet: Command = { name: 'greet', description: 'Greet the user', params: [ { name: 'name', description: 'The name of the user to greet', required: true, type: ParamType.Text }], action: (args) => { const name = args.name; Greet(name); } } export default commandGreet; `; exports.githubactionNpmTemplate = `on: push: branches: main pull_request: branches: main jobs: test: if: github.event_name == 'push' || github.event_name == 'pull_request' runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - uses: actions/setup-node@v4 with: node-version: "24" - run: npm ci - run: npm test publish: if: github.ref == 'refs/heads/main' && github.event_name == 'push' runs-on: ubuntu-latest needs: test steps: - uses: actions/checkout@v6 - uses: actions/setup-node@v4 with: node-version: "24" - run: npm ci - run: npm run build - name: Update version in cli.ts run: | VERSION=$(node -p "require('./package.json').version") sed -i "s/version: '[^']*'/version: '$VERSION'/" src/bin/cli.ts - uses: JS-DevTools/npm-publish@v3 with: token: \${{ secrets.NPM_TOKEN }} access: public `; exports.githubactionBunTemplate = `on: push: branches: main pull_request: branches: main jobs: test: if: github.event_name == 'push' || github.event_name == 'pull_request' runs-on: ubuntu-slim steps: - uses: actions/checkout@v6 - uses: oven-sh/setup-bun@v2 with: bun-version: 1.3.3 - run: bun install - run: bun test publish: if: github.ref == 'refs/heads/main' && github.event_name == 'push' runs-on: ubuntu-slim needs: test steps: - uses: actions/checkout@v6 - uses: oven-sh/setup-bun@v2 with: bun-version: 1.3.3 - run: bun install - name: Update version in cli.ts run: | VERSION=$(node -p "require('./package.json').version") sed -i "s/version: '[^']*'/version: '$VERSION'/" src/bin/cli.ts - run: bun run build - uses: JS-DevTools/npm-publish@v3 with: token: \${{ secrets.NPM_TOKEN }} access: public `; exports.tsconfigTemplate = `{ "extends": "./tsconfig.base.json", "compilerOptions": { "rootDir": "./src", "declaration": true, "declarationMap": false }, "include": ["src/**/*.ts"], "exclude": [ "src/tests/**/*" ] } `; exports.tsconfigBaseTemplate = `{ "compilerOptions": { "target": "ES2020", "module": "commonjs", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "outDir": "./dist", "declaration": true, "declarationMap": true, "declarationDir": "./dist" }, "exclude": ["node_modules"] } `; exports.tsconfigTestTemplate = `{ "extends": "./tsconfig.base.json", "compilerOptions": { "rootDir": "./src" }, "include": ["tests/**/*.ts", "src/**/*.ts"] } `;