Skip to content

Commit

Permalink
fix(cli): set glob options to support windows paths with special chars
Browse files Browse the repository at this point in the history
See #1943
  • Loading branch information
raymondfeng committed Nov 1, 2018
1 parent ef1facd commit 9a84ef0
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 34 deletions.
8 changes: 1 addition & 7 deletions packages/cli/generators/controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,7 @@ module.exports = class ControllerGenerator extends ArtifactGenerator {
debug(`artifactInfo: ${inspect(this.artifactInfo)}`);
debug(`Copying artifact to: ${dest}`);
}
this.fs.copyTpl(
source,
dest,
this.artifactInfo,
{},
{globOptions: {dot: true}},
);
this.copyTemplatedFiles(source, dest, this.artifactInfo);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/generators/datasource/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ module.exports = class DataSourceGenerator extends ArtifactGenerator {

// Copy Templates
this.fs.writeJSON(jsonPath, ds);
this.fs.copyTpl(classTemplatePath, tsPath, this.artifactInfo);
this.copyTemplatedFiles(classTemplatePath, tsPath, this.artifactInfo);
}

install() {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/generators/model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ module.exports = class ModelGenerator extends ArtifactGenerator {
}
});

this.fs.copyTpl(
this.copyTemplatedFiles(
this.templatePath(MODEL_TEMPLATE_PATH),
tsPath,
this.artifactInfo,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/generators/openapi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ module.exports = class OpenApiGenerator extends BaseGenerator {
if (debug.enabled) {
debug('Copying artifact to: %s', dest);
}
this.fs.copyTpl(source, dest, c, {}, {globOptions: {dot: true}});
this.copyTemplatedFiles(source, dest, c);
}
}

Expand All @@ -144,7 +144,7 @@ module.exports = class OpenApiGenerator extends BaseGenerator {
debug('Copying artifact to: %s', dest);
}
const source = m.kind === 'class' ? modelSource : typeSource;
this.fs.copyTpl(source, dest, m, {}, {globOptions: {dot: true}});
this.copyTemplatedFiles(source, dest, m);
}
}

Expand Down
8 changes: 1 addition & 7 deletions packages/cli/generators/repository/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,7 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
debug(`artifactInfo: ${inspect(this.artifactInfo)}`);
debug(`Copying artifact to: ${dest}`);
}
this.fs.copyTpl(
source,
dest,
this.artifactInfo,
{},
{globOptions: {dot: true}},
);
this.copyTemplatedFiles(source, dest, this.artifactInfo);
return;
}

Expand Down
8 changes: 1 addition & 7 deletions packages/cli/generators/service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,7 @@ module.exports = class ServiceGenerator extends ArtifactGenerator {
debug(`artifactInfo: ${inspect(this.artifactInfo)}`);
debug(`Copying artifact to: ${dest}`);

this.fs.copyTpl(
source,
dest,
this.artifactInfo,
{},
{globOptions: {dot: true}},
);
this.copyTemplatedFiles(source, dest, this.artifactInfo);
return;
}

Expand Down
4 changes: 1 addition & 3 deletions packages/cli/lib/artifact-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,10 @@ module.exports = class ArtifactGenerator extends BaseGenerator {

// Copy template files from ./templates
// Renaming of the files should be done in the generator inheriting from this one
this.fs.copyTpl(
this.copyTemplatedFiles(
this.templatePath('**/*'),
this.destinationPath(),
this.artifactInfo,
{},
{globOptions: {dot: true}},
);
}

Expand Down
36 changes: 36 additions & 0 deletions packages/cli/lib/base-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,42 @@ module.exports = class BaseGenerator extends Generator {
this.npmInstall(null, opts, spawnOpts);
}

/**
* Wrapper for mem-fs-editor.copyTpl() to ensure consistent options
*
* See https://github.com/SBoudrias/mem-fs-editor/blob/master/lib/actions/copy-tpl.js
*
* @param {string} from
* @param {string} to
* @param {object} context
* @param {object} templateOptions
* @param {object} copyOptions
*/
copyTemplatedFiles(
from,
to,
context,
templateOptions = {},
copyOptions = {
// See https://github.com/mrmlnc/fast-glob#options-1
globOptions: {
// Allow patterns to match filenames starting with a period (files &
// directories), even if the pattern does not explicitly have a period
// in that spot.
dot: true,
// Disable expansion of brace patterns ({a,b}, {1..3}).
nobrace: true,
// Disable extglob support (patterns like +(a|b)), so that extglobs
// are regarded as literal characters. This flag allows us to support
// Windows paths such as
// `D:\Users\BKU\oliverkarst\AppData(Roaming)\npm\node_modules\@loopback\cli`
noext: true,
},
},
) {
return this.fs.copyTpl(from, to, context, templateOptions, copyOptions);
}

/**
* Checks if current directory is a LoopBack project by checking for
* keyword 'loopback' under 'keywords' attribute in package.json.
Expand Down
8 changes: 2 additions & 6 deletions packages/cli/lib/project-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,12 @@ module.exports = class ProjectGenerator extends BaseGenerator {
if (this.shouldExit()) return false;

// First copy common files from ../../project/templates
this.fs.copyTpl(
this.copyTemplatedFiles(
this.templatePath('../../project/templates/**/*'),
this.destinationPath(''),
{
project: this.projectInfo,
},
{},
{globOptions: {dot: true}},
);

// Rename `_.gitignore` back to `.gitignore`.
Expand All @@ -211,14 +209,12 @@ module.exports = class ProjectGenerator extends BaseGenerator {
);

// Copy project type specific files from ./templates
this.fs.copyTpl(
this.copyTemplatedFiles(
this.templatePath('**/*'),
this.destinationPath(''),
{
project: this.projectInfo,
},
{},
{globOptions: {dot: true}},
);

if (!this.projectInfo.tslint) {
Expand Down

0 comments on commit 9a84ef0

Please sign in to comment.