(environment: Environment, options: Options)
| 54 | } |
| 55 | |
| 56 | async function writeFiles(environment: Environment, options: Options) { |
| 57 | const templateFileFromContent = createTemplateFile(environment, options) |
| 58 | |
| 59 | async function writeFileBundle(bundle: FileBundleHandler) { |
| 60 | const files = await bundle.getFiles() |
| 61 | |
| 62 | for (const file of files) { |
| 63 | const contents = await bundle.getFileContents(file) |
| 64 | |
| 65 | if (isBase64(contents)) { |
| 66 | await environment.writeFileBase64( |
| 67 | joinPaths(options.targetDir, file), |
| 68 | contents, |
| 69 | ) |
| 70 | } else { |
| 71 | await templateFileFromContent(file, contents) |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | const deletedFiles = await bundle.getDeletedFiles() |
| 76 | for (const file of deletedFiles) { |
| 77 | await environment.deleteFile(joinPaths(options.targetDir, file)) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | environment.startStep({ |
| 82 | id: 'write-framework-files', |
| 83 | type: 'file', |
| 84 | message: 'Writing framework files...', |
| 85 | }) |
| 86 | await writeFileBundle(options.framework) |
| 87 | environment.finishStep('write-framework-files', 'Framework files written') |
| 88 | |
| 89 | let wroteAddonFiles = false |
| 90 | for (const type of ['add-on', 'example', 'toolchain', 'deployment']) { |
| 91 | for (const phase of ['setup', 'add-on', 'example']) { |
| 92 | for (const addOn of options.chosenAddOns.filter( |
| 93 | (addOn) => addOn.phase === phase && addOn.type === type, |
| 94 | )) { |
| 95 | environment.startStep({ |
| 96 | id: 'write-addon-files', |
| 97 | type: 'file', |
| 98 | message: `Writing ${addOn.name} files...`, |
| 99 | }) |
| 100 | await writeFileBundle(addOn) |
| 101 | wroteAddonFiles = true |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | if (wroteAddonFiles) { |
| 106 | environment.finishStep('write-addon-files', 'Add-on files written') |
| 107 | } |
| 108 | |
| 109 | if (options.starter) { |
| 110 | environment.startStep({ |
| 111 | id: 'write-starter-files', |
| 112 | type: 'file', |
| 113 | message: 'Writing starter files...', |
no test coverage detected