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