Skip to content

Commit 9a84ef0

Browse files
committed
fix(cli): set glob options to support windows paths with special chars
See #1943
1 parent ef1facd commit 9a84ef0

File tree

9 files changed

+46
-34
lines changed

9 files changed

+46
-34
lines changed

packages/cli/generators/controller/index.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,7 @@ module.exports = class ControllerGenerator extends ArtifactGenerator {
236236
debug(`artifactInfo: ${inspect(this.artifactInfo)}`);
237237
debug(`Copying artifact to: ${dest}`);
238238
}
239-
this.fs.copyTpl(
240-
source,
241-
dest,
242-
this.artifactInfo,
243-
{},
244-
{globOptions: {dot: true}},
245-
);
239+
this.copyTemplatedFiles(source, dest, this.artifactInfo);
246240
return;
247241
}
248242

packages/cli/generators/datasource/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ module.exports = class DataSourceGenerator extends ArtifactGenerator {
286286

287287
// Copy Templates
288288
this.fs.writeJSON(jsonPath, ds);
289-
this.fs.copyTpl(classTemplatePath, tsPath, this.artifactInfo);
289+
this.copyTemplatedFiles(classTemplatePath, tsPath, this.artifactInfo);
290290
}
291291

292292
install() {

packages/cli/generators/model/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ module.exports = class ModelGenerator extends ArtifactGenerator {
345345
}
346346
});
347347

348-
this.fs.copyTpl(
348+
this.copyTemplatedFiles(
349349
this.templatePath(MODEL_TEMPLATE_PATH),
350350
tsPath,
351351
this.artifactInfo,

packages/cli/generators/openapi/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ module.exports = class OpenApiGenerator extends BaseGenerator {
126126
if (debug.enabled) {
127127
debug('Copying artifact to: %s', dest);
128128
}
129-
this.fs.copyTpl(source, dest, c, {}, {globOptions: {dot: true}});
129+
this.copyTemplatedFiles(source, dest, c);
130130
}
131131
}
132132

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

packages/cli/generators/repository/index.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -401,13 +401,7 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
401401
debug(`artifactInfo: ${inspect(this.artifactInfo)}`);
402402
debug(`Copying artifact to: ${dest}`);
403403
}
404-
this.fs.copyTpl(
405-
source,
406-
dest,
407-
this.artifactInfo,
408-
{},
409-
{globOptions: {dot: true}},
410-
);
404+
this.copyTemplatedFiles(source, dest, this.artifactInfo);
411405
return;
412406
}
413407

packages/cli/generators/service/index.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,7 @@ module.exports = class ServiceGenerator extends ArtifactGenerator {
233233
debug(`artifactInfo: ${inspect(this.artifactInfo)}`);
234234
debug(`Copying artifact to: ${dest}`);
235235

236-
this.fs.copyTpl(
237-
source,
238-
dest,
239-
this.artifactInfo,
240-
{},
241-
{globOptions: {dot: true}},
242-
);
236+
this.copyTemplatedFiles(source, dest, this.artifactInfo);
243237
return;
244238
}
245239

packages/cli/lib/artifact-generator.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,10 @@ module.exports = class ArtifactGenerator extends BaseGenerator {
7171

7272
// Copy template files from ./templates
7373
// Renaming of the files should be done in the generator inheriting from this one
74-
this.fs.copyTpl(
74+
this.copyTemplatedFiles(
7575
this.templatePath('**/*'),
7676
this.destinationPath(),
7777
this.artifactInfo,
78-
{},
79-
{globOptions: {dot: true}},
8078
);
8179
}
8280

packages/cli/lib/base-generator.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,42 @@ module.exports = class BaseGenerator extends Generator {
267267
this.npmInstall(null, opts, spawnOpts);
268268
}
269269

270+
/**
271+
* Wrapper for mem-fs-editor.copyTpl() to ensure consistent options
272+
*
273+
* See https://github.com/SBoudrias/mem-fs-editor/blob/master/lib/actions/copy-tpl.js
274+
*
275+
* @param {string} from
276+
* @param {string} to
277+
* @param {object} context
278+
* @param {object} templateOptions
279+
* @param {object} copyOptions
280+
*/
281+
copyTemplatedFiles(
282+
from,
283+
to,
284+
context,
285+
templateOptions = {},
286+
copyOptions = {
287+
// See https://github.com/mrmlnc/fast-glob#options-1
288+
globOptions: {
289+
// Allow patterns to match filenames starting with a period (files &
290+
// directories), even if the pattern does not explicitly have a period
291+
// in that spot.
292+
dot: true,
293+
// Disable expansion of brace patterns ({a,b}, {1..3}).
294+
nobrace: true,
295+
// Disable extglob support (patterns like +(a|b)), so that extglobs
296+
// are regarded as literal characters. This flag allows us to support
297+
// Windows paths such as
298+
// `D:\Users\BKU\oliverkarst\AppData(Roaming)\npm\node_modules\@loopback\cli`
299+
noext: true,
300+
},
301+
},
302+
) {
303+
return this.fs.copyTpl(from, to, context, templateOptions, copyOptions);
304+
}
305+
270306
/**
271307
* Checks if current directory is a LoopBack project by checking for
272308
* keyword 'loopback' under 'keywords' attribute in package.json.

packages/cli/lib/project-generator.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,12 @@ module.exports = class ProjectGenerator extends BaseGenerator {
192192
if (this.shouldExit()) return false;
193193

194194
// First copy common files from ../../project/templates
195-
this.fs.copyTpl(
195+
this.copyTemplatedFiles(
196196
this.templatePath('../../project/templates/**/*'),
197197
this.destinationPath(''),
198198
{
199199
project: this.projectInfo,
200200
},
201-
{},
202-
{globOptions: {dot: true}},
203201
);
204202

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

213211
// Copy project type specific files from ./templates
214-
this.fs.copyTpl(
212+
this.copyTemplatedFiles(
215213
this.templatePath('**/*'),
216214
this.destinationPath(''),
217215
{
218216
project: this.projectInfo,
219217
},
220-
{},
221-
{globOptions: {dot: true}},
222218
);
223219

224220
if (!this.projectInfo.tslint) {

0 commit comments

Comments
 (0)