Skip to content

Commit

Permalink
feat(config): Add .yfmignore file. Ignore node_modules in build
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3k0 authored and 3y3 committed Jul 11, 2023
1 parent 718727f commit 9d1babc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import yargs, {Arguments} from 'yargs';
import glob from 'glob';
import shell from 'shelljs';
import {resolve, join} from 'path';
import 'threads/register';
Expand Down Expand Up @@ -195,7 +196,7 @@ async function main(args: Arguments<any>) {
resources,
} = ArgvService.getConfig();

preparingTemporaryFolders(args, userOutputFolder, tmpInputFolder, tmpOutputFolder);
preparingTemporaryFolders(userOutputFolder);

await processServiceFiles();
processExcludedFiles();
Expand Down Expand Up @@ -263,21 +264,19 @@ async function main(args: Arguments<any>) {
}
}

function preparingTemporaryFolders(
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
args: Arguments<any>,
userOutputFolder: string,
tmpInputFolder: string,
tmpOutputFolder: string) {
function preparingTemporaryFolders(userOutputFolder: string) {
const args = ArgvService.getConfig();

shell.mkdir('-p', userOutputFolder);

// Create temporary input/output folders
shell.rm('-rf', tmpInputFolder, tmpOutputFolder);
shell.mkdir(tmpInputFolder, tmpOutputFolder);
shell.rm('-rf', args.input, args.output);
shell.mkdir(args.input, args.output);
shell.chmod('-R', 'u+w', args.input);

// Copy all user' files to the temporary folder to avoid user' file changing.
// Please, change files only in temporary folders.
shell.cp('-rL', resolve(args.input, '*'), tmpInputFolder);
shell.chmod('-R', 'u+w', tmpInputFolder);
copyFiles(args.rootInput, args.input, glob.sync('**', {
cwd: args.rootInput,
nodir: true,
ignore: args.ignore,
}));
}
14 changes: 14 additions & 0 deletions src/services/argv.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {YfmArgv} from '../models';
import {join} from 'path';
import {readFileSync} from 'fs';

let _argv!: YfmArgv;

Expand All @@ -13,6 +15,18 @@ function init(argv: any) {
ignore: Array.isArray(argv.ignore) ? argv.ignore : [],
vars: JSON.parse(argv.vars),
} as YfmArgv;

try {
const ignorefile = readFileSync(join(_argv.rootInput, '.yfmignore'), 'utf8');
const ignore = ignorefile.split('\n');

_argv.ignore = _argv.ignore.concat(ignore);
} catch {}

_argv.ignore = _argv.ignore.concat([
'node_modules/**',
'*/node_modules/**',
]);
}

function set(argv: YfmArgv) {
Expand Down

0 comments on commit 9d1babc

Please sign in to comment.