-
Notifications
You must be signed in to change notification settings - Fork 28
feat(VEG-4340): Bootstrap a new package to onboard CLI commands for Connector SDK #308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
saikambaiyyagari
merged 6 commits into
master
from
skambaiyyagari/introduce-connector-commands
Jan 21, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
99c7b35
feat(VEG-4340): Bootstrap a new package to onboard CLI commands for C…
saikambaiyyagari 2822f16
Add the manifest generator logic to generate the connector manifest
saikambaiyyagari 16d1587
Introduce the connector bundle logic to create the minified JS output
saikambaiyyagari dea5d1c
Add codeowners
saikambaiyyagari 5c56bb4
Refactor and structure the code
saikambaiyyagari f004b76
Merge pull request #309 from zendesk/skambaiyyagari/add-bundle-command
saikambaiyyagari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,3 +10,6 @@ | |
|
|
||
| # Shared | ||
| yarn.lock @zendesk/wattle @zendesk/vikings | ||
|
|
||
| # Connectors | ||
| /packages/zcli-connectors/ @zendesk/vegemite | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Change Log | ||
|
|
||
| All notable changes to this project will be documented in this file. | ||
| See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
|
|
||
| # [1.0.0-beta.1](https://github.com/zendesk/zcli/compare/v1.0.0-beta.0...v1.0.0-beta.1) (2026-01-12) | ||
|
|
||
| **Note:** Initial version for zcli-connectors package |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| const oclif = require('@oclif/core') | ||
|
|
||
| oclif.run().catch(require('@oclif/core/handle')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| @echo off | ||
|
|
||
| node "%~dp0\run" %* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| { | ||
| "name": "@zendesk/zcli-connectors", | ||
| "description": "zcli connectors commands live here", | ||
| "version": "1.0.0-beta.1", | ||
| "author": "@vegemite", | ||
| "npmRegistry": "https://registry.npmjs.org", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "bin": { | ||
| "zcli-connectors": "./bin/run" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsc", | ||
| "prepack": "tsc && ../../scripts/prepack.sh", | ||
| "postpack": "rm -f oclif.manifest.json npm-shrinkwrap.json && rm -rf ./dist && git checkout ./package.json", | ||
| "type:check": "tsc" | ||
| }, | ||
| "dependencies": { | ||
| "adm-zip": "0.5.10", | ||
| "archiver": "^5.3.1", | ||
| "axios": "^1.7.5", | ||
| "chalk": "^4.1.2", | ||
| "fs-extra": "^10.0.0", | ||
| "rimraf": "^3.0.2", | ||
| "tslib": "^2.4.0", | ||
| "@rollup/plugin-babel": "^6.0.0", | ||
| "@rollup/plugin-commonjs": "^25.0.0", | ||
| "@rollup/plugin-node-resolve": "^15.0.0", | ||
| "vite": "^7.1.3" | ||
| }, | ||
| "devDependencies": { | ||
| "@oclif/test": "=2.1.0", | ||
| "@types/adm-zip": "^0.5.5", | ||
| "@types/archiver": "^5.3.1", | ||
| "@types/chai": "^4", | ||
| "@types/mocha": "^9.1.1", | ||
| "@types/rimraf": "^3.0.2", | ||
| "@types/sinon-chai": "^4.0.0", | ||
| "chai": "^4", | ||
| "eslint": "^8.18.0", | ||
| "eslint-config-oclif": "^4.0.0", | ||
| "eslint-config-oclif-typescript": "^1.0.2", | ||
| "lerna": "^5.6.2", | ||
| "mocha": "^10.8.2", | ||
| "sinon": "^14.0.0", | ||
| "sinon-chai": "^4.0.1", | ||
| "ora": "^5.4.1" | ||
| }, | ||
saikambaiyyagari marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "files": [ | ||
| "/bin", | ||
| "/dist", | ||
| "/oclif.manifest.json", | ||
| "/npm-shrinkwrap.json" | ||
| ], | ||
| "keywords": [ | ||
| "zcli", | ||
| "zendesk", | ||
| "cli", | ||
| "command" | ||
| ], | ||
| "license": "MIT", | ||
| "main": "src/index.js", | ||
saikambaiyyagari marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "oclif": { | ||
| "commands": "./src/commands", | ||
| "bin": "zcli-connectors" | ||
| }, | ||
| "types": "lib/index.d.ts" | ||
saikambaiyyagari marked this conversation as resolved.
Show resolved
Hide resolved
saikambaiyyagari marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
164 changes: 164 additions & 0 deletions
164
packages/zcli-connectors/src/commands/connectors/bundle.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| import { Command, Flags } from '@oclif/core' | ||
| import { existsSync, mkdirSync } from 'fs' | ||
| import { join, resolve } from 'path' | ||
| import * as chalk from 'chalk' | ||
| import { ViteConfigBuilder, ViteRunner } from '../../lib/vite' | ||
| import * as ora from 'ora' | ||
|
|
||
| export default class Bundle extends Command { | ||
| static examples = [ | ||
| '<%= config.bin %> <%= command.id %> ./example-connector', | ||
| '<%= config.bin %> <%= command.id %> ./example-connector --output ./bundled', | ||
| '<%= config.bin %> <%= command.id %> --input ./src --output ./bundle' | ||
| ] | ||
|
|
||
| static flags = { | ||
| help: Flags.help({ char: 'h' }), | ||
| input: Flags.string({ | ||
| char: 'i', | ||
| description: 'input directory containing connector source files', | ||
| default: '.' | ||
| }), | ||
| output: Flags.string({ | ||
| char: 'o', | ||
| description: 'output directory for bundled files' | ||
| }), | ||
| verbose: Flags.boolean({ | ||
| char: 'v', | ||
| description: 'verbose output', | ||
| default: false | ||
| }), | ||
| watch: Flags.boolean({ | ||
| char: 'w', | ||
| description: 'watch for changes and rebuild', | ||
| default: false | ||
| }) | ||
| } | ||
|
|
||
| static args = [ | ||
| { | ||
| name: 'path', | ||
| description: 'path to connector directory (will use src/ folder inside)' | ||
| } | ||
| ] | ||
|
|
||
| async run (): Promise<void> { | ||
| const { args, flags } = await this.parse(Bundle) | ||
|
|
||
| let inputPath: string | ||
| if (args.path) { | ||
| inputPath = resolve(join(args.path, 'src')) | ||
| } else { | ||
| inputPath = resolve(flags.input) | ||
| } | ||
|
|
||
| const outputPath = flags.output ? resolve(flags.output) : resolve('dist') | ||
| if (!existsSync(outputPath)) { | ||
| mkdirSync(outputPath, { recursive: true }) | ||
| if (flags.verbose) { | ||
| this.log(chalk.cyan(`Created output directory: ${outputPath}`)) | ||
| } | ||
| } | ||
|
|
||
| if (flags.verbose) { | ||
| this.log(chalk.cyan('Verbose mode enabled')) | ||
| this.log(chalk.cyan(`Resolved Input path: ${inputPath}`)) | ||
| this.log(chalk.cyan(`Resolved Output path: ${outputPath}`)) | ||
| this.log(chalk.cyan(`Watch mode: ${flags.watch ? 'enabled' : 'disabled'}`)) | ||
| } | ||
|
|
||
| const spinner = ora( | ||
| `Bundling connector from ${inputPath} to ${outputPath}...` | ||
| ).start() | ||
|
|
||
| try { | ||
| await this.generateViteBundle(inputPath, outputPath, flags, spinner) | ||
|
|
||
| if (flags.watch) { | ||
| spinner.succeed( | ||
| chalk.green('Watching for changes... (Press Ctrl+C to stop)') | ||
| ) | ||
| } else { | ||
| spinner.succeed(chalk.green('Bundle created successfully!')) | ||
| } | ||
| } catch (error) { | ||
| spinner.fail(chalk.red('Failed to bundle the connector')) | ||
|
|
||
| const errorMessage = (error instanceof Error) ? error.message : String(error) | ||
| if (flags.verbose) { | ||
| this.log('\n' + chalk.red('Error Details:')) | ||
| this.log(errorMessage) | ||
| } | ||
|
|
||
| this.error(errorMessage, { exit: 1 }) | ||
| } | ||
| } | ||
|
|
||
| private async generateViteBundle ( | ||
| inputPath: string, | ||
| outputPath: string, | ||
| flags: { watch: boolean; verbose: boolean }, | ||
| spinner: ora.Ora | ||
| ): Promise<void> { | ||
| const { watch, verbose } = flags | ||
|
|
||
| if (verbose) { | ||
| this.log(chalk.cyan('Creating Vite configuration...')) | ||
| } | ||
|
|
||
| const viteConfig = ViteConfigBuilder.createConfig( | ||
| { | ||
| inputPath, | ||
| outputPath, | ||
| watch | ||
| } | ||
| ) | ||
|
|
||
| if (verbose) { | ||
| spinner.stop() | ||
| this.log(chalk.cyan('Vite configuration created successfully')) | ||
| this.log(chalk.cyan('Starting build process...')) | ||
| spinner.start() | ||
| } | ||
|
|
||
| spinner.text = watch | ||
| ? 'Building connector and watching for changes...' | ||
| : 'Building connector...' | ||
| const stats = await ViteRunner.run(viteConfig) | ||
|
|
||
| if (stats.hasErrors()) { | ||
| spinner.fail(chalk.red('Bundle failed with errors!')) | ||
|
|
||
| const errors = stats.toJson().errors || [] | ||
| this.log(chalk.cyan(`Found ${errors.length} error(s)`)) | ||
| errors.forEach((error: any) => { | ||
| this.log(chalk.red(`Error: ${error.message}`)) | ||
| }) | ||
|
|
||
| throw new Error('Connector build failed') | ||
| } | ||
|
|
||
| if (verbose) { | ||
| const buildInfo = stats.toJson() | ||
| if (buildInfo.assets && buildInfo.assets.length > 0) { | ||
| this.log(chalk.cyan(`Generated ${buildInfo.assets.length} asset(s)`)) | ||
| buildInfo.assets.forEach((asset: any) => { | ||
| this.log(chalk.cyan(` - ${asset.name} (${(asset.size / 1024).toFixed(2)} KB)`)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| if (stats.hasWarnings()) { | ||
| const warnings = stats.toJson().warnings || [] | ||
| if (verbose) { | ||
| this.log(chalk.cyan(`Found ${warnings.length} warning(s)`)) | ||
| } | ||
| this.log(chalk.yellow('\nWarnings:')) | ||
| warnings.forEach((warning: any) => { | ||
| this.log(chalk.yellow(` - ${warning.message}`)) | ||
| }) | ||
| } else if (verbose) { | ||
| this.log(chalk.cyan('No warnings found')) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const DEFAULT_CONNECTORS_CONFIG_FILE = 'zcli.connectors.config.json' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export default {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.