@ali-i18n-fe/dada-component
Version:
70 lines (57 loc) • 1.5 kB
JavaScript
const { getPackageConfig } = require("./getPackageJson");
const { getCurrentPathConfig } = require("./index");
const buildArgv = require("yargs-parser")(process.env.BUILD_ARGV_STR || "");
function isDaily() {
return buildArgv.def_publish_env !== "prod";
}
function getDefVersion() {
const branch = process.env.BUILD_GIT_BRANCH;
const matches = /\w+\/(\d+?\.\d+?.\d+?(.+)?)/.exec(branch);
const version = matches && matches[1];
// console.log("get def version", branch);
return version;
}
function isDef() {
return !!process.env.BUILD_ENV;
}
function getDEFPublicPath() {
const packageConfig = getPackageConfig();
const {
type,
group: branchGroup,
project: branchProject,
} = getCurrentPathConfig();
const isTNPM = type !== "js";
let version = packageConfig.version;
// 去除 beta 等后缀
version = version.replace(/-.+/, "");
let hostname = 'g.alicdn.com';
if (isDaily()) {
hostname = "dev." + hostname;
}
if (process.env.HOST_NAME) {
hostname = process.env.HOST_NAME;
}
let host = isTNPM
? `${hostname}/code/npm/${packageConfig.name}/${version}/`
: `${hostname}/${branchGroup}/${branchProject}/${
isDef() ? `${getDefVersion()}/` : ""
}`;
return `https://${host}`;
}
/**
* 获取默认PublicPath
*/
function getDefaultPublicPath() {
if (isDef()) {
return getDEFPublicPath();
}
return "/";
}
module.exports = {
isDef,
isDaily,
getDefVersion,
getDefaultPublicPath,
getDEFPublicPath,
};