diff --git a/src/cli/args.ts b/src/cli/args.ts index ca1dcbc..ed7a9f9 100644 --- a/src/cli/args.ts +++ b/src/cli/args.ts @@ -28,7 +28,7 @@ interface CLIArgs { listPlans?: boolean; env?: string[]; envFile?: string[]; - ignore?: string[]; + 'ignore-pattern'?: string[]; quiet?: boolean; verbose?: boolean; json?: boolean; @@ -106,7 +106,6 @@ const optionsDefinition: ArgumentConfig = { }, inspect: { type: parseInspectFormat, - alias: 'i', optional: true }, delete: { @@ -148,13 +147,13 @@ const optionsDefinition: ArgumentConfig = { description: 'Path to .env file (can be used multiple times): --envFile .env.production' }, - ignore: { + 'ignore-pattern': { type: String, - alias: 'I', + alias: 'i', optional: true, multiple: true, description: - 'Ignore pattern for files (can be used multiple times): -I "*.log" -I "node_modules"' + 'Ignore pattern for files (can be used multiple times): -i "*.log" -i "node_modules"' }, quiet: { type: Boolean, diff --git a/src/deploy.ts b/src/deploy.ts index 8f60350..0877439 100644 --- a/src/deploy.ts +++ b/src/deploy.ts @@ -45,10 +45,34 @@ export const deployPackage = async ( const deploy = async (additionalJsons: MetaCallJSON[]) => { const descriptor = await generatePackage(rootPath); + const defaultIgnores: Record = { + node: ['node_modules'], + python: ['__pycache__', '*.pyc'], + ruby: ['vendor'], + php: ['vendor'], + csharp: ['bin', 'obj'], + fsharp: ['bin', 'obj'], + cobol: ['bin', 'obj'], + file: [], + rust: ['target'] + }; + + const languageIgnores = descriptor.runners.flatMap( + runner => defaultIgnores[runner] || [] + ); + + const combinedIgnores = [ + ...(args['ignore-pattern'] || []), + ...languageIgnores + ]; + // Apply ignore patterns if specified - const filesToDeploy = filterFiles(descriptor.files, args['ignore']); + const filesToDeploy = filterFiles( + descriptor.files, + combinedIgnores + ); - if (args['ignore']?.length) { + if (combinedIgnores.length > 0) { const ignoredCount = descriptor.files.length - filesToDeploy.length; if (ignoredCount > 0) { diff --git a/src/help.ts b/src/help.ts index 37252b5..f8e66eb 100644 --- a/src/help.ts +++ b/src/help.ts @@ -24,14 +24,14 @@ Environment Variables: --envFile Load environment variables from file (can be repeated) File Filtering: - -I, --ignore Ignore files matching pattern (can be repeated) - Examples: -I "*.log" -I "node_modules" + -i, --ignore-pattern Ignore files matching pattern (can be repeated) + Examples: -i "*.log" -i "node_modules" Output Options: -q, --quiet Suppress non-essential output -V, --verbose Show detailed debug output --json Output results in JSON format (for scripting) - -i, --inspect [format] List deployments (Table | Raw | OpenAPIv3) + --inspect [format] List deployments (Table | Raw | OpenAPIv3) Management: -D, --delete Interactively select and delete a deployment @@ -52,11 +52,11 @@ Examples: $ metacall-deploy -a https://github.com/... Deploy from repository $ metacall-deploy -E DB_HOST=localhost Deploy with environment variable $ metacall-deploy --envFile .env.prod Deploy with env file - $ metacall-deploy -I "*.test.js" -I ".git" Deploy ignoring test files + $ metacall-deploy -i "*.test.js" -i ".git" Deploy ignoring test files $ metacall-deploy --dryRun Preview deployment without deploying - $ metacall-deploy -i List all deployments - $ metacall-deploy -i Raw List deployments in raw format - $ metacall-deploy --json -i List deployments as JSON + $ metacall-deploy --inspect List all deployments + $ metacall-deploy --inspect Raw List deployments in raw format + $ metacall-deploy --json --inspect List deployments as JSON For more information, visit: https://github.com/metacall/deploy `; diff --git a/src/index.ts b/src/index.ts index cf179dc..bfaf2fd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -153,8 +153,8 @@ void (async () => { if (args['envFile']?.length) { info(`Environment files: ${args['envFile'].join(', ')}`); } - if (args['ignore']?.length) { - info(`Ignore patterns: ${args['ignore'].join(', ')}`); + if (args['ignore-pattern']?.length) { + info(`Ignore patterns: ${args['ignore-pattern'].join(', ')}`); } jsonOutput({ dryRun: true, @@ -165,7 +165,7 @@ void (async () => { fileCount: files.length, envCount: args['env']?.length || 0, envFiles: args['envFile'] || [], - ignorePatterns: args['ignore'] || [] + ignorePatterns: args['ignore-pattern'] || [] }); return; } diff --git a/src/test/package.integration.spec.ts b/src/test/package.integration.spec.ts index 56de1e7..d3a7da4 100644 --- a/src/test/package.integration.spec.ts +++ b/src/test/package.integration.spec.ts @@ -34,4 +34,29 @@ describe('Integration Package', function () { deepStrictEqual(files, archiveFiles); }); + + it('Should ignore files when ignorePatterns are provided', async () => { + const rootPath = join( + process.cwd(), + 'src', + 'test', + 'resources', + 'integration', + 'folder-hierarchy' + ); + + const descriptor = await generatePackage(rootPath); + const archiveFiles: string[] = []; + + await zip( + rootPath, + descriptor.files, + undefined, + name => archiveFiles.push(name), + undefined, + ['*.md', 'src'] + ); + + deepStrictEqual(['metacall-py.json'], archiveFiles); + }); }); diff --git a/src/test/utils.spec.ts b/src/test/utils.spec.ts index 40defc8..eef3451 100644 --- a/src/test/utils.spec.ts +++ b/src/test/utils.spec.ts @@ -1,5 +1,5 @@ -import { ok } from 'assert'; -import { opt } from '../utils'; +import { deepStrictEqual, ok } from 'assert'; +import { filterFiles, opt } from '../utils'; describe('Unit Utils Opt', () => { it('Should call a function with the provided string', () => { @@ -9,3 +9,20 @@ describe('Unit Utils Opt', () => { ok(opt(x => x, null) === ''); }); }); + +describe('Unit Utils filterFiles', () => { + it('Should correctly filter files based on ignore patterns', () => { + const files = [ + 'src/index.js', + 'node_modules/express/index.js', + 'package.json', + 'test.log', + 'foo/bar/test.log' + ]; + + const ignorePatterns = ['node_modules', '*.log']; + const filtered = filterFiles(files, ignorePatterns); + + deepStrictEqual(filtered, ['src/index.js', 'package.json']); + }); +});