MCPcopy Index your code
hub / github.com/prettydiff/prettydiff / appendFile

Function appendFile

services.ts:1250–1306  ·  view source on GitHub ↗
(filePath:string)

Source from the content-addressed store, hash-verified

1248 libFiles.push(`${projectPath}node_modules${sep}file-saver${sep}FileSaver.min.js`);
1249 libFiles.push(`${projectPath}node_modules${sep}sparser${sep}js${sep}browser.js`);
1250 const appendFile = function node_apps_build_libraries_libraryFiles_appendFile(filePath:string):void {
1251 node.fs.readFile(filePath, "utf8", function node_apps_build_libraries_libraryFiles_appendFile_read(errr:Error, filedata:string):void {
1252 const filenames:string[] = filePath.split(sep),
1253 filename:string = filenames[filenames.length - 1];
1254 if (errr !== null) {
1255 apps.errout([errr.toString()]);
1256 return;
1257 }
1258 if (filename === "FileSaver.min.js" && filePath.indexOf(filename) === filePath.length - filename.length) {
1259 filedata = filedata
1260 .replace(/var\s+saveAs\s*=\s*saveAs\s*\|\|\s*function\(/, `// eslint-disable-next-line${node.os.EOL}prettydiff.saveAs=function prettydiff_saveAs(`)
1261 .replace(/(\{|\}|;|(\*\/))\s*var\s/g, function node_apps_build_libraries_libraryFiles_appendFile_read_saveAsFix(str:string):string {
1262 return str.replace("var", "let");
1263 });
1264 saveas = filedata;
1265 } else if (filePath === `${projectPath}node_modules${sep}sparser${sep}js${sep}browser.js`) {
1266 // both sparser and prettydiff contain a browser.js file, so it is important to target the correct one
1267 filedata = filedata
1268 .replace(/\s*("|')use strict("|');/g, "")
1269 .replace(/\s*const\s+parser/, `"use strict";const parser`)
1270 .replace(/window\.sparser/g, "sparser")
1271 .replace(/sparser\s*=\s*sparser;\s*\}\(\)\);(prettydiff\.beautify=\{\};)?(prettydiff\.api=\{\};)?(prettydiff\.minify=\{\};)?/, "")
1272 .replace(/\s*sparser\.libs\.language\s*=\s*language;/, "sparser.libs.language=language;prettydiff.api.language=language;");
1273 parser = filedata;
1274 } else {
1275 filedata = filedata
1276 .replace(/(\/\*global\s+global(,\s*options)?(,\s*prettydiff)?\s*\*\/\s*)/, "")
1277 .replace(/global\s*\.\s*prettydiff\s*\./g, "prettydiff.")
1278 .replace(/\s*("|')use strict("|');/, "");
1279 if (filename === "mode.js" && filePath.indexOf(filename) === filePath.length - filename.length) {
1280 mode = filedata
1281 .replace(/\/\*\s*global\s+prettydiff\s*\*\//, "")
1282 .replace(/\s+/, "")
1283 .replace(/\s+$/, ";")
1284 .replace(/global(API)?\./g, "")
1285 .replace(/globalAPI\.sparser/g, "sparser")
1286 .replace(/globalAPI\s*=\s*\(options\.api\s*===\s*"dom"\)\s*\?\s*window\s*:\s*global,/, "")
1287 .replace(/if\s*\(options\.api\s*===\s*"dom"\)\s*\{\s*globalAPI\s*=\s*window;\s*\}/, "")
1288 .replace(/,\s*\/\/\s*prettydiff file insertion start\s+prettydiff\s*=\s*\{\};/, ";")
1289 .replace(/\s*mode\(\);/, "")
1290 .replace(/\s*prettydiff\s*=\s*prettydiff;/, "") + `prettydiff.api={};prettydiff.beautify={};prettydiff.end=0;prettydiff.iterator=0;prettydiff.meta={error:"",lang:["","",""],time:"",insize:0,outsize:0,difftotal:0,difflines:0};prettydiff.minify={};prettydiff.options=${defaults};prettydiff.scopes=[];prettydiff.start=0;`;
1291 } else if (filename !== "prettydiff-webtool.js") {
1292 libraries = libraries + filedata.replace(/\s*global\s*\.\s*prettydiff/, "prettydiff");
1293 }
1294 }
1295 a = a + 1;
1296 if (a === filelen) {
1297 const inject = function node_apps_build_libraries_appendFile_inject(version:string):string {
1298 return `${version.slice(0, version.length - 1)},prettydiff=${mode}`;
1299 };
1300 complete = `${parser.replace(/version:\{date:"\d+\s+\w+\s+\d{4}",number:"\d+\.\d+\.\d+"\}\s*\};/, inject) + libraries}prettydiff.sparser=sparser;prettydiff.version=${JSON.stringify(prettydiff.version)};`;
1301 modifyFile(`${projectPath}index.xhtml`, "html");
1302 modifyFile(`${js}api${sep}prettydiff-webtool.js`, "webtool");
1303 modifyFile(`${projectPath}documentation.xhtml`, "documentation");
1304 }
1305 });
1306 },
1307 stat = function node_apps_build_libraries_libraryFiles_stat(pathitem:string) {

Callers 1

statFunction · 0.85

Calls 1

modifyFileFunction · 0.85

Tested by

no test coverage detected