MCPcopy Create free account
hub / github.com/cocos/cocos-engine / executeTemplateTask

Function executeTemplateTask

scripts/native-pack-tool/source/base/default.ts:376–443  ·  view source on GitHub ↗
(tasks: CocosProjectTasks)

Source from the content-addressed store, hash-verified

374 }
375
376 protected async executeTemplateTask(tasks: CocosProjectTasks) {
377 if (tasks.appendFile) {
378 await Promise.all(tasks.appendFile.map((task) => {
379 const dest = cchelper.replaceEnvVariables(task.to);
380 fs.ensureDirSync(ps.dirname(dest));
381 return fs.copy(ps.join(Paths.nativeRoot, task.from), dest);
382 }))
383 delete tasks.appendFile;
384 }
385
386 const replaceFilesDelay: { [key: string]: { reg: string, content: string }[] } = {};
387
388 if (tasks.projectReplaceProjectName) {
389 const cmd = tasks.projectReplaceProjectName;
390
391 cmd.files.forEach((file) => {
392 const fp = cchelper.join(this.paths.buildDir, file);
393 replaceFilesDelay[fp] = replaceFilesDelay[fp] || [];
394 replaceFilesDelay[fp].push({
395 reg: cmd.srcProjectName,
396 content: this.params.projectName,
397 });
398 });
399 delete tasks.projectReplaceProjectName;
400 }
401
402 if (tasks.projectReplaceProjectNameASCII) {
403 const cmd = tasks.projectReplaceProjectNameASCII;
404 if (cmd.srcProjectName !== this.projectNameASCII()) {
405 cmd.files.forEach((file) => {
406 const fp = cchelper.join(this.paths.buildDir, file);
407 replaceFilesDelay[fp] = replaceFilesDelay[fp] || [];
408 replaceFilesDelay[fp].push({
409 reg: cmd.srcProjectName,
410 content: this.projectNameASCII(),
411 });
412 });
413 }
414 delete tasks.projectReplaceProjectNameASCII;
415 }
416
417 if (tasks.projectReplacePackageName) {
418 const cmd = tasks.projectReplacePackageName;
419 const name = cmd.srcPackageName.replace(/\./g, '\\.');
420 cmd.files.forEach((file) => {
421 const fp = cchelper.join(this.paths.buildDir, file);
422 replaceFilesDelay[fp] = replaceFilesDelay[fp] || [];
423 replaceFilesDelay[fp].push({
424 reg: name,
425 content: (this.params.platformParams as any).packageName!,
426 });
427 });
428 delete tasks.projectReplacePackageName;
429 }
430
431 for (const fullpath in replaceFilesDelay) {
432 const cfg = replaceFilesDelay[fullpath];
433 await cchelper.replaceInFile(cfg.map((x) => {

Callers

nothing calls this directly

Calls 10

mapMethod · 0.80
replaceEnvVariablesMethod · 0.80
joinMethod · 0.80
replaceMethod · 0.80
replaceInFileMethod · 0.80
errorMethod · 0.80
copyMethod · 0.65
forEachMethod · 0.65
pushMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected