Fix: build async bug
This commit is contained in:
		
							parent
							
								
									fdbf369454
								
							
						
					
					
						commit
						8bad0cffff
					
				
							
								
								
									
										154
									
								
								build.js
									
									
									
									
									
								
							
							
						
						
									
										154
									
								
								build.js
									
									
									
									
									
								
							@ -83,89 +83,93 @@ function dateFormat(fmt, date) {
 | 
			
		||||
  return fmt;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const t = new Date();
 | 
			
		||||
const buildTime = dateFormat("YYYY-mm-dd HH:MM:SS", t);
 | 
			
		||||
const buildDir = "builds";
 | 
			
		||||
async function main() {
 | 
			
		||||
  const t = new Date();
 | 
			
		||||
  const buildTime = dateFormat("YYYY-mm-dd HH:MM:SS", t);
 | 
			
		||||
  const buildDir = "builds";
 | 
			
		||||
 | 
			
		||||
console.log(
 | 
			
		||||
  `[Build] BUILD_DIR=${buildDir}, VERSION=${version}, BUILD_TIME=${buildTime}`
 | 
			
		||||
);
 | 
			
		||||
  console.log(
 | 
			
		||||
    `[Build] BUILD_DIR=${buildDir}, VERSION=${version}, BUILD_TIME=${buildTime}`
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
clearFolder(buildDir);
 | 
			
		||||
  clearFolder(buildDir);
 | 
			
		||||
 | 
			
		||||
copyFolderRecursiveSync("addon", buildDir);
 | 
			
		||||
  copyFolderRecursiveSync("addon", buildDir);
 | 
			
		||||
 | 
			
		||||
esbuild
 | 
			
		||||
  .build({
 | 
			
		||||
    entryPoints: ["src/index.ts"],
 | 
			
		||||
    bundle: true,
 | 
			
		||||
    // Entry should be the same as addon/chrome/content/overlay.xul
 | 
			
		||||
    outfile: path.join(buildDir, "addon/chrome/content/scripts/index.js"),
 | 
			
		||||
    // minify: true,
 | 
			
		||||
  })
 | 
			
		||||
  .catch(() => process.exit(1));
 | 
			
		||||
  await esbuild
 | 
			
		||||
    .build({
 | 
			
		||||
      entryPoints: ["src/index.ts"],
 | 
			
		||||
      bundle: true,
 | 
			
		||||
      // Entry should be the same as addon/chrome/content/overlay.xul
 | 
			
		||||
      outfile: path.join(buildDir, "addon/chrome/content/scripts/index.js"),
 | 
			
		||||
      // minify: true,
 | 
			
		||||
    })
 | 
			
		||||
    .catch(() => process.exit(1));
 | 
			
		||||
 | 
			
		||||
console.log("[Build] Run esbuild OK");
 | 
			
		||||
  console.log("[Build] Run esbuild OK");
 | 
			
		||||
 | 
			
		||||
const optionsAddon = {
 | 
			
		||||
  files: [
 | 
			
		||||
    path.join(buildDir, "**/*.rdf"),
 | 
			
		||||
    path.join(buildDir, "**/*.dtd"),
 | 
			
		||||
    path.join(buildDir, "**/*.xul"),
 | 
			
		||||
    path.join(buildDir, "**/*.manifest"),
 | 
			
		||||
    path.join(buildDir, "addon/defaults", "**/*.js"),
 | 
			
		||||
    "update.rdf",
 | 
			
		||||
  ],
 | 
			
		||||
  from: [
 | 
			
		||||
    /__author__/g,
 | 
			
		||||
    /__description__/g,
 | 
			
		||||
    /__homepage__/g,
 | 
			
		||||
    /__releasepage__/g,
 | 
			
		||||
    /__updaterdf__/g,
 | 
			
		||||
    /__addonName__/g,
 | 
			
		||||
    /__addonID__/g,
 | 
			
		||||
    /__addonRef__/g,
 | 
			
		||||
    /__buildVersion__/g,
 | 
			
		||||
    /__buildTime__/g,
 | 
			
		||||
    /<em:version>\S*<\/em:version>/g,
 | 
			
		||||
  ],
 | 
			
		||||
  to: [
 | 
			
		||||
    author,
 | 
			
		||||
    description,
 | 
			
		||||
    homepage,
 | 
			
		||||
    releasepage,
 | 
			
		||||
    updaterdf,
 | 
			
		||||
    addonName,
 | 
			
		||||
    addonID,
 | 
			
		||||
    addonRef,
 | 
			
		||||
    version,
 | 
			
		||||
    buildTime,
 | 
			
		||||
    `<em:version>${version}</em:version>`,
 | 
			
		||||
  ],
 | 
			
		||||
  countMatches: true,
 | 
			
		||||
};
 | 
			
		||||
  const optionsAddon = {
 | 
			
		||||
    files: [
 | 
			
		||||
      path.join(buildDir, "**/*.rdf"),
 | 
			
		||||
      path.join(buildDir, "**/*.dtd"),
 | 
			
		||||
      path.join(buildDir, "**/*.xul"),
 | 
			
		||||
      path.join(buildDir, "**/*.manifest"),
 | 
			
		||||
      path.join(buildDir, "addon/defaults", "**/*.js"),
 | 
			
		||||
      "update.rdf",
 | 
			
		||||
    ],
 | 
			
		||||
    from: [
 | 
			
		||||
      /__author__/g,
 | 
			
		||||
      /__description__/g,
 | 
			
		||||
      /__homepage__/g,
 | 
			
		||||
      /__releasepage__/g,
 | 
			
		||||
      /__updaterdf__/g,
 | 
			
		||||
      /__addonName__/g,
 | 
			
		||||
      /__addonID__/g,
 | 
			
		||||
      /__addonRef__/g,
 | 
			
		||||
      /__buildVersion__/g,
 | 
			
		||||
      /__buildTime__/g,
 | 
			
		||||
      /<em:version>\S*<\/em:version>/g,
 | 
			
		||||
    ],
 | 
			
		||||
    to: [
 | 
			
		||||
      author,
 | 
			
		||||
      description,
 | 
			
		||||
      homepage,
 | 
			
		||||
      releasepage,
 | 
			
		||||
      updaterdf,
 | 
			
		||||
      addonName,
 | 
			
		||||
      addonID,
 | 
			
		||||
      addonRef,
 | 
			
		||||
      version,
 | 
			
		||||
      buildTime,
 | 
			
		||||
      `<em:version>${version}</em:version>`,
 | 
			
		||||
    ],
 | 
			
		||||
    countMatches: true,
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
_ = replace.sync(optionsAddon);
 | 
			
		||||
console.log(
 | 
			
		||||
  "[Build] Run replace in ",
 | 
			
		||||
  _.filter((f) => f.hasChanged).map(
 | 
			
		||||
    (f) => `${f.file} : ${f.numReplacements} / ${f.numMatches}`
 | 
			
		||||
  )
 | 
			
		||||
);
 | 
			
		||||
  _ = replace.sync(optionsAddon);
 | 
			
		||||
  console.log(
 | 
			
		||||
    "[Build] Run replace in ",
 | 
			
		||||
    _.filter((f) => f.hasChanged).map(
 | 
			
		||||
      (f) => `${f.file} : ${f.numReplacements} / ${f.numMatches}`
 | 
			
		||||
    )
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
console.log("[Build] Replace OK");
 | 
			
		||||
  console.log("[Build] Replace OK");
 | 
			
		||||
 | 
			
		||||
console.log("[Build] Addon prepare OK");
 | 
			
		||||
  console.log("[Build] Addon prepare OK");
 | 
			
		||||
 | 
			
		||||
compressing.zip.compressDir(
 | 
			
		||||
  path.join(buildDir, "addon"),
 | 
			
		||||
  path.join(buildDir, `${name}.xpi`),
 | 
			
		||||
  {
 | 
			
		||||
    ignoreBase: true,
 | 
			
		||||
  }
 | 
			
		||||
);
 | 
			
		||||
  compressing.zip.compressDir(
 | 
			
		||||
    path.join(buildDir, "addon"),
 | 
			
		||||
    path.join(buildDir, `${name}.xpi`),
 | 
			
		||||
    {
 | 
			
		||||
      ignoreBase: true,
 | 
			
		||||
    }
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
console.log("[Build] Addon pack OK");
 | 
			
		||||
console.log(
 | 
			
		||||
  `[Build] Finished in ${(new Date().getTime() - t.getTime()) / 1000} s.`
 | 
			
		||||
);
 | 
			
		||||
  console.log("[Build] Addon pack OK");
 | 
			
		||||
  console.log(
 | 
			
		||||
    `[Build] Finished in ${(new Date().getTime() - t.getTime()) / 1000} s.`
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
main();
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user