Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/cli/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface CLIArgs {
listPlans?: boolean;
env?: string[];
envFile?: string[];
ignore?: string[];
'ignore-pattern'?: string[];
quiet?: boolean;
verbose?: boolean;
json?: boolean;
Expand Down Expand Up @@ -106,7 +106,6 @@ const optionsDefinition: ArgumentConfig<CLIArgs> = {
},
inspect: {
type: parseInspectFormat,
alias: 'i',
optional: true
},
delete: {
Expand Down Expand Up @@ -148,13 +147,13 @@ const optionsDefinition: ArgumentConfig<CLIArgs> = {
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,
Expand Down
28 changes: 26 additions & 2 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,34 @@ export const deployPackage = async (
const deploy = async (additionalJsons: MetaCallJSON[]) => {
const descriptor = await generatePackage(rootPath);

const defaultIgnores: Record<string, string[]> = {
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) {
Expand Down
14 changes: 7 additions & 7 deletions src/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ Environment Variables:
--envFile <path> Load environment variables from file (can be repeated)

File Filtering:
-I, --ignore <pattern> Ignore files matching pattern (can be repeated)
Examples: -I "*.log" -I "node_modules"
-i, --ignore-pattern <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
Expand All @@ -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
`;
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
Expand Down
25 changes: 25 additions & 0 deletions src/test/package.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
21 changes: 19 additions & 2 deletions src/test/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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']);
});
});