mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-21 13:50:29 +08:00
99 lines
4.8 KiB
JavaScript
99 lines
4.8 KiB
JavaScript
'use strict';const require$$0$1=require('node:path'),require$$1$1=require('node:fs'),require$$2=require('node:stream/promises'),index=require('./index.B8Uk9n3v.cjs'),require$$4=require('tar-fs'),require$$5=require('node:zlib'),require$$1=require('undici'),require$$0=require('picocolors'),fetchRetry=require('./fetch-retry.D06uBUaW.cjs'),misc=require('./misc.BpcQjda1.cjs'),require$$11=require('ci-info');var downloadPreviousBuild = {exports: {}};var hasRequiredDownloadPreviousBuild;
|
|
|
|
function requireDownloadPreviousBuild () {
|
|
if (hasRequiredDownloadPreviousBuild) return downloadPreviousBuild.exports;
|
|
hasRequiredDownloadPreviousBuild = 1;
|
|
(function (module, exports) {
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
Object.defineProperty(exports, "downloadPreviousBuild", {
|
|
enumerable: true,
|
|
get: function() {
|
|
return downloadPreviousBuild;
|
|
}
|
|
});
|
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0$1);
|
|
const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1$1);
|
|
const _promises = require$$2;
|
|
const _trace = /*@__PURE__*/ index.r();
|
|
const _tarfs = require$$4;
|
|
const _nodezlib = /*#__PURE__*/ _interop_require_default(require$$5);
|
|
const _undici = /*#__PURE__*/ _interop_require_default(require$$1);
|
|
const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0);
|
|
const _dir = /*@__PURE__*/ fetchRetry.a();
|
|
const _fetchretry = /*@__PURE__*/ fetchRetry.r();
|
|
const _misc = /*@__PURE__*/ misc.r();
|
|
const _ciinfo = require$$11;
|
|
function _interop_require_default(obj) {
|
|
return obj && obj.__esModule ? obj : {
|
|
default: obj
|
|
};
|
|
}
|
|
const GITHUB_CODELOAD_URL = 'https://codeload.github.com/sukkalab/ruleset.skk.moe/tar.gz/master';
|
|
const GITLAB_CODELOAD_URL = 'https://gitlab.com/SukkaW/ruleset.skk.moe/-/archive/master/ruleset.skk.moe-master.tar.gz';
|
|
const downloadPreviousBuild = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
|
if (_nodefs.default.existsSync(_dir.PUBLIC_DIR) && !(0, _misc.isDirectoryEmptySync)(_dir.PUBLIC_DIR)) {
|
|
console.log(_picocolors.default.blue('Public directory exists, skip downloading previous build'));
|
|
return;
|
|
}
|
|
// we uses actions/checkout to download the previous build now, so we should throw if the directory is empty
|
|
if (_ciinfo.isCI) {
|
|
throw new Error('CI environment detected, but public directory is empty');
|
|
}
|
|
const tarGzUrl = await span.traceChildAsync('get tar.gz url', async ()=>{
|
|
const resp = await (0, _fetchretry.requestWithLog)(GITHUB_CODELOAD_URL, {
|
|
method: 'HEAD'
|
|
});
|
|
if (resp.statusCode !== 200) {
|
|
console.warn('Download previous build from GitHub failed! Status:', resp.statusCode);
|
|
console.warn('Switch to GitLab');
|
|
return GITLAB_CODELOAD_URL;
|
|
}
|
|
return GITHUB_CODELOAD_URL;
|
|
});
|
|
return span.traceChildAsync('download & extract previoud build', async ()=>{
|
|
const respBody = _undici.default.pipeline(tarGzUrl, {
|
|
method: 'GET',
|
|
headers: {
|
|
'User-Agent': 'curl/8.9.1',
|
|
// https://github.com/unjs/giget/issues/97
|
|
// https://gitlab.com/gitlab-org/gitlab/-/commit/50c11f278d18fe1f3fb12eb595067216bb58ade2
|
|
'sec-fetch-mode': 'same-origin'
|
|
},
|
|
// Allow redirects by default
|
|
maxRedirections: 5
|
|
}, ({ statusCode, body })=>{
|
|
if (statusCode !== 200) {
|
|
console.warn('Download previous build failed! Status:', statusCode);
|
|
if (statusCode === 404) {
|
|
throw new Error('Download previous build failed! 404');
|
|
}
|
|
}
|
|
return body;
|
|
}).end();
|
|
const pathPrefix = 'ruleset.skk.moe-master/';
|
|
const gunzip = _nodezlib.default.createGunzip();
|
|
const extract = (0, _tarfs.extract)(_dir.PUBLIC_DIR, {
|
|
ignore (_, header) {
|
|
if (header) {
|
|
if (header.type !== 'file' && header.type !== 'directory') {
|
|
return true;
|
|
}
|
|
if (header.type === 'file' && _nodepath.default.extname(header.name) === '.ts') {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
},
|
|
map (header) {
|
|
header.name = header.name.replace(pathPrefix, '');
|
|
return header;
|
|
}
|
|
});
|
|
return (0, _promises.pipeline)(respBody, gunzip, extract);
|
|
});
|
|
});
|
|
} (downloadPreviousBuild, downloadPreviousBuild.exports));
|
|
return downloadPreviousBuild.exports;
|
|
}exports.r=requireDownloadPreviousBuild; |