diff --git a/packages/generators/src/addon-generator.ts b/packages/generators/src/addon-generator.ts index 9a2e417f451..67fcd56159e 100644 --- a/packages/generators/src/addon-generator.ts +++ b/packages/generators/src/addon-generator.ts @@ -2,7 +2,6 @@ import fs from 'fs'; import path from 'path'; import Generator from 'yeoman-generator'; -import { generatorCopy, generatorCopyTpl } from './utils/copy-utils'; import { List } from './utils/scaffold-utils'; /** @@ -101,11 +100,14 @@ const addonGenerator = ( // eslint-disable-next-line @typescript-eslint/no-var-requires this.fs.extendJSON(this.destinationPath('package.json'), require(packageJsonTemplatePath)(this.props.name)); - this.copy = generatorCopy(this, this.resolvedTemplatePath); - this.copyTpl = generatorCopyTpl(this, this.resolvedTemplatePath, templateFn(this)); + copyFiles.forEach((filePath) => + this.fs.copyTpl(path.join(this.resolvedTemplatePath, filePath), this.destinationPath(filePath.replace('.tpl', ''))), + ); - copyFiles.forEach(this.copy); - copyTemplateFiles.forEach(this.copyTpl); + copyTemplateFiles.forEach((filePath) => { + const destFilePath = filePath.replace('_', '').replace('.tpl', ''); + this.fs.copyTpl(path.join(this.resolvedTemplatePath, filePath), this.destinationPath(destFilePath), templateFn(this)); + }); } public install(): void { diff --git a/packages/generators/src/utils/copy-utils.ts b/packages/generators/src/utils/copy-utils.ts deleted file mode 100644 index 25dd6fda949..00000000000 --- a/packages/generators/src/utils/copy-utils.ts +++ /dev/null @@ -1,50 +0,0 @@ -import path from 'path'; - -/** - * Takes in a file path in the `./templates` directory. Copies that - * file to the destination, with the `.tpl` extension stripped. - * - * @param {Generator} generator A Yeoman Generator instance - * @param {string} templateDir Absolute path to template directory - * @returns {Function} A curried function that takes a file path and copies it - */ -// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -export const generatorCopy = (generator: any, templateDir: string): ((filePath: string) => void) => (filePath: string): void => { - const sourceParts = templateDir.split(path.delimiter); - - sourceParts.push(...filePath.split('/')); - - const targetParts = path.dirname(filePath).split('/'); - - targetParts.push(path.basename(filePath, '.tpl')); - - generator.fs.copy(path.join(...sourceParts), generator.destinationPath(path.join.apply(null, targetParts))); -}; - -/** - * Takes in a file path in the `./templates` directory. Copies that - * file to the destination, with the `.tpl` extension and `_` prefix - * stripped. Passes `this.props` to the template. - * - * @param {Generator} generator A Yeoman Generator instance - * @param {string} templateDir Absolute path to template directory - * @param {any} templateData An object containing the data passed to - * the template files. - * @returns {Function} A curried function that takes a file path and copies it - */ -export const generatorCopyTpl = ( - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any - generator: any, - templateDir: string, - templateData: Record, -): ((filePath: string) => void) => (filePath: string): void => { - const sourceParts = templateDir.split(path.delimiter); - - sourceParts.push(...filePath.split('/')); - - const targetParts = path.dirname(filePath).split('/'); - - targetParts.push(path.basename(filePath, '.tpl').slice(1)); - - generator.fs.copyTpl(path.join(...sourceParts), generator.destinationPath(path.join.apply(null, targetParts)), templateData); -};