add: support beta (prerelease) auto update
This commit is contained in:
		
							parent
							
								
									25990fd552
								
							
						
					
					
						commit
						23ffc5fdf8
					
				@ -12,7 +12,7 @@
 | 
			
		||||
  "applications": {
 | 
			
		||||
    "zotero": {
 | 
			
		||||
      "id": "__addonID__",
 | 
			
		||||
      "update_url": "__updaterdf__",
 | 
			
		||||
      "update_url": "__updateURL__",
 | 
			
		||||
      "strict_min_version": "6.999",
 | 
			
		||||
      "strict_max_version": "7.0.*"
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -8,8 +8,9 @@
 | 
			
		||||
    "addonRef": "addontemplate",
 | 
			
		||||
    "addonInstance": "AddonTemplate",
 | 
			
		||||
    "prefsPrefix": "extensions.zotero.addontemplate",
 | 
			
		||||
    "releasepage": "https://github.com/windingwind/zotero-addon-template/releases/latest/download/zotero-addon-template.xpi",
 | 
			
		||||
    "updaterdf": "https://raw.githubusercontent.com/windingwind/zotero-addon-template/main/update.json"
 | 
			
		||||
    "releasePage": "https://github.com/windingwind/zotero-addon-template/releases",
 | 
			
		||||
    "updateJSON": "https://raw.githubusercontent.com/windingwind/zotero-addon-template/main/update.json",
 | 
			
		||||
    "updateBetaJSON": "https://raw.githubusercontent.com/windingwind/zotero-addon-template/main/update-beta.json"
 | 
			
		||||
  },
 | 
			
		||||
  "main": "src/index.ts",
 | 
			
		||||
  "scripts": {
 | 
			
		||||
 | 
			
		||||
@ -24,6 +24,14 @@ const buildDir = "build";
 | 
			
		||||
 | 
			
		||||
const isPreRelease = version.includes("-");
 | 
			
		||||
 | 
			
		||||
// If it is a pre-release, use update-beta.json
 | 
			
		||||
config.updateURL = isPreRelease ? config.updateJSONBeta : config.updateBetaJSON;
 | 
			
		||||
 | 
			
		||||
const updateJSONFile = isPreRelease ? "update-beta.json" : "update.json";
 | 
			
		||||
const updateLink = isPreRelease
 | 
			
		||||
  ? `${config.releasePage}/download/v${version}/${name}.xpi`
 | 
			
		||||
  : `${config.releasePage}/latest/download/${name}.xpi`;
 | 
			
		||||
 | 
			
		||||
function copyFileSync(source, target) {
 | 
			
		||||
  var targetFile = target;
 | 
			
		||||
 | 
			
		||||
@ -122,8 +130,16 @@ function replaceString() {
 | 
			
		||||
    /__homepage__/g,
 | 
			
		||||
    /__buildVersion__/g,
 | 
			
		||||
    /__buildTime__/g,
 | 
			
		||||
    /__updateLink__/g,
 | 
			
		||||
  ];
 | 
			
		||||
  const replaceTo = [
 | 
			
		||||
    author,
 | 
			
		||||
    description,
 | 
			
		||||
    homepage,
 | 
			
		||||
    version,
 | 
			
		||||
    buildTime,
 | 
			
		||||
    updateLink,
 | 
			
		||||
  ];
 | 
			
		||||
  const replaceTo = [author, description, homepage, version, buildTime];
 | 
			
		||||
 | 
			
		||||
  replaceFrom.push(
 | 
			
		||||
    ...Object.keys(config).map((k) => new RegExp(`__${k}__`, "g")),
 | 
			
		||||
@ -144,9 +160,7 @@ function replaceString() {
 | 
			
		||||
    countMatches: true,
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  if (!isPreRelease) {
 | 
			
		||||
    optionsAddon.files.push("update.json");
 | 
			
		||||
  }
 | 
			
		||||
  optionsAddon.files.push(updateJSONFile);
 | 
			
		||||
 | 
			
		||||
  const replaceResult = replaceInFileSync(optionsAddon);
 | 
			
		||||
 | 
			
		||||
@ -237,13 +251,7 @@ async function main() {
 | 
			
		||||
 | 
			
		||||
  copyFolderRecursiveSync("addon", buildDir);
 | 
			
		||||
 | 
			
		||||
  if (isPreRelease) {
 | 
			
		||||
    console.log(
 | 
			
		||||
      "[Build] [Warn] Running in pre-release mode. update.json will not be replaced.",
 | 
			
		||||
    );
 | 
			
		||||
  } else {
 | 
			
		||||
    copyFileSync("update-template.json", "update.json");
 | 
			
		||||
  }
 | 
			
		||||
  copyFileSync("update-template.json", updateJSONFile);
 | 
			
		||||
 | 
			
		||||
  await esbuild();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										17
									
								
								update-beta.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								update-beta.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
			
		||||
{
 | 
			
		||||
  "addons": {
 | 
			
		||||
    "addontemplate@euclpts.com": {
 | 
			
		||||
      "updates": [
 | 
			
		||||
        {
 | 
			
		||||
          "version": "1.0.0",
 | 
			
		||||
          "update_link": "https://github.com/windingwind/zotero-addon-template/releases/latest/download/zotero-addon-template.xpi",
 | 
			
		||||
          "applications": {
 | 
			
		||||
            "zotero": {
 | 
			
		||||
              "strict_min_version": "6.999"
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      ]
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -4,7 +4,7 @@
 | 
			
		||||
      "updates": [
 | 
			
		||||
        {
 | 
			
		||||
          "version": "__buildVersion__",
 | 
			
		||||
          "update_link": "__releasepage__",
 | 
			
		||||
          "update_link": "__updateLink__",
 | 
			
		||||
          "applications": {
 | 
			
		||||
            "zotero": {
 | 
			
		||||
              "strict_min_version": "6.999"
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user