Skip to content

Commit

Permalink
fix(app-builder): add globFiles util
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Oct 31, 2023
1 parent 02f6feb commit 8efe70c
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports[`exports > exports from index.ts 1`] = `
"getFileContents",
"getPlatformDistPath",
"getRelativePath",
"globFiles",
"isEmptyDir",
"isVerbose",
"isVeryVerbose",
Expand Down
9 changes: 4 additions & 5 deletions apps/app-builder/src/commands/copy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import glob from 'fast-glob';
import chalk from 'chalk';
import {
addPlatformToContext,
copyFile,
copyScopedFiles,
executePromises,
getPlatformDistPath,
globFiles,
logPlatforms,
logTargetPath,
resolvePath,
Expand All @@ -14,15 +14,14 @@ import {
import {type PdkBuilderCommand} from '../types';

const copy: PdkBuilderCommand = async (context) => {
const {env, config, args, debug} = context;
const {config, args, debug} = context;

const resolvedSources = resolveStrings(context, config.source);
const files = glob.sync(resolvedSources, {cwd: env.cwd});
const files = globFiles(config.source, context);

debug(
'Copying %s files from %s to %s for platforms %s',
chalk.greenBright(files.length),
chalk.yellow(resolvedSources),
chalk.yellow(resolveStrings(context, config.source)),
logTargetPath(config.outDir, context),
logPlatforms(config.platforms),
);
Expand Down
5 changes: 2 additions & 3 deletions apps/app-builder/src/commands/increment.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import glob from 'fast-glob';
import chalk from 'chalk';
import {isOfType} from '@myparcel/ts-utils';
import {
executePromises,
exists,
getFileContents,
globFiles,
isVerbose,
logSourcePath,
reportFileDoesNotExist,
resolvePath,
resolveStrings,
usesPhpScoper,
writeFile,
} from '../utils';
Expand Down Expand Up @@ -38,7 +37,7 @@ const increment: PdkBuilderCommand = async (context) => {
sources.push(`${config.phpScoper.vendorOutDir}/${source.path}`);
}

return {source, files: glob.sync(resolveStrings(context, sources), {cwd: env.cwd})};
return {source, files: globFiles(sources, context)};
});

await executePromises(
Expand Down
7 changes: 3 additions & 4 deletions apps/app-builder/src/commands/rename.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable max-lines-per-function */
import path from 'path';
import glob from 'fast-glob';
import chalk from 'chalk';
import {
addPlatformToContext,
executePromises,
getPlatformDistPath,
globFiles,
logRelativePath,
renameFile,
replaceCaseSensitive,
Expand All @@ -17,7 +17,7 @@ import {type PdkBuilderCommand} from '../types';
const STRING_TO_REPLACE = 'myparcelnl';

const rename: PdkBuilderCommand = async (context) => {
const {env, config, args, debug} = context;
const {config, args, debug} = context;

debug('Renaming files for platforms %s', chalk.cyanBright(config.platforms.join(', ')));

Expand All @@ -33,9 +33,8 @@ const rename: PdkBuilderCommand = async (context) => {

debug('Renaming files in %s', logRelativePath(platformDistPath, platformContext));

const files = glob.sync(`${platformDistPath}/**/*`, {
const files = globFiles(`${platformDistPath}/**/*`, context, {
ignore: [`${platformDistPath}/node_modules/**/*`, `${platformDistPath}/vendor/**/*`],
cwd: env.cwd,
});

await Promise.all(
Expand Down
5 changes: 2 additions & 3 deletions apps/app-builder/src/commands/transform.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable max-lines-per-function */
import glob from 'fast-glob';
import chalk from 'chalk';
import {
addPlatformToContext,
executePromises,
getFileContents,
getOccurrences,
globFiles,
isVeryVeryVerbose,
logPlatforms,
logSourcePath,
Expand Down Expand Up @@ -44,7 +44,7 @@ const transform: PdkBuilderCommand = async (context) => {

debug('Transforming files in %s', logSourcePath(platformFolderPath, platformContext));

const files = glob.sync(`${platformFolderPath}/**/*`, {
const files = globFiles(`${platformFolderPath}/**/*`, context, {
ignore: [
`${platformFolderPath}/node_modules/**/*`,
`${platformFolderPath}/package.json`,
Expand All @@ -53,7 +53,6 @@ const transform: PdkBuilderCommand = async (context) => {
`${platformFolderPath}/**/*.map`,
`${platformFolderPath}/**/*.d.ts`,
],
cwd: env.cwd,
});

const promises = await Promise.all(
Expand Down
1 change: 1 addition & 0 deletions apps/app-builder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export {
getFileContents,
getPlatformDistPath,
getRelativePath,
globFiles,
isEmptyDir,
isVerbose,
isVeryVerbose,
Expand Down
8 changes: 4 additions & 4 deletions apps/app-builder/src/utils/copyScopedFiles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import glob from 'fast-glob';
import {type PdkBuilderContext} from '../types';
import {usesPhpScoper} from './usesPhpScoper';
import {resolvePath} from './resolvePath';
import {globFiles} from './globFiles';
import {getPlatformDistPath} from './getPlatformDistPath';
import {copyFile} from './fs';
import {executePromises} from './executePromises';
Expand All @@ -13,7 +13,7 @@ export const copyScopedFiles = async (context: PdkBuilderContext): Promise<void>
return;
}

const {env, config, args, debug} = context;
const {config, args, debug} = context;

await executePromises(
args,
Expand All @@ -26,15 +26,15 @@ export const copyScopedFiles = async (context: PdkBuilderContext): Promise<void>
const scopedVendorDir = resolvePath(config.phpScoper.vendorOutDir, context);

await Promise.all([
...glob.sync(`${scopedVendorDir}/**/*`, {cwd: env.cwd}).map(async (file) => {
...globFiles(`${scopedVendorDir}/**/*`, context).map(async (file) => {
await copyFile(
file,
file.replace(scopedVendorDir, resolvePath([platformDistPath, 'vendor'], context)),
context,
);
}),

...glob.sync(`${scopedSourceDir}/**/*`, {cwd: env.cwd}).map(async (file) => {
...globFiles(`${scopedSourceDir}/**/*`, context).map(async (file) => {
await copyFile(file, file.replace(scopedSourceDir, platformDistPath), context);
}),
]);
Expand Down
12 changes: 12 additions & 0 deletions apps/app-builder/src/utils/globFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import glob, {type Options} from 'fast-glob';
import {type OneOrMore} from '@myparcel/ts-utils';
import {type PdkBuilderContext, type StringGenerator} from '../types';
import {resolveStrings} from './resolveStrings';

export const globFiles = (
patterns: OneOrMore<StringGenerator>,
context: PdkBuilderContext,
options: Options = {},
): string[] => {
return glob.sync(resolveStrings(context, patterns), {cwd: context.env.cwd, ...options});
};
1 change: 1 addition & 0 deletions apps/app-builder/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './executePromises';
export * from './fs';
export * from './getPlatformDistPath';
export * from './getRelativePath';
export * from './globFiles';
export * from './mergeDefaultConfig';
export * from './parseJsonFile';
export * from './resolveConfig';
Expand Down

0 comments on commit 8efe70c

Please sign in to comment.