(
url: string,
code: string,
resourceType: string,
)
| 124 | } |
| 125 | |
| 126 | public async logScript( |
| 127 | url: string, |
| 128 | code: string, |
| 129 | resourceType: string, |
| 130 | ): Promise<void> { |
| 131 | if (this.urlToScriptMap.has(url)) { |
| 132 | return; |
| 133 | } |
| 134 | const metaFile = fileManager.getWebSourceMetaFile(); |
| 135 | const file = path.join( |
| 136 | fileManager.getWebSourceDir(), |
| 137 | `${++this.fileId}${this.resourceTypeToSuffix(resourceType)}`, |
| 138 | ); |
| 139 | const scriptInfo: ScriptInfo = { |
| 140 | url, |
| 141 | fileId: this.fileId, |
| 142 | codePath: file, |
| 143 | resourceType, |
| 144 | }; |
| 145 | this.urlToScriptMap.set(url, scriptInfo); |
| 146 | this.scriptInfos.push(scriptInfo); |
| 147 | fs.writeFile(file, code, {encoding: 'utf8'}, () => { |
| 148 | // async write, do nothing here |
| 149 | }); |
| 150 | // only write the latest version of the meta file state |
| 151 | this.debounce(() => { |
| 152 | fs.writeFileSync(metaFile, JSON.stringify(this.scriptInfos, void 0, 2), { |
| 153 | encoding: 'utf8', |
| 154 | }); |
| 155 | }, 1000); |
| 156 | } |
| 157 | |
| 158 | private debounce(callback: AnyFunction, timeout: number): void { |
| 159 | if (this.metaFileWriteTimeout) { |
no test coverage detected