Skip to content
Permalink
Browse files
use md5 hash for assets version
  • Loading branch information
pissang committed Dec 6, 2020
1 parent c81f53a commit 4c4e51f0a6f844b644f52d40cf1e6022ee17f6ae
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 31 deletions.
@@ -168,7 +168,7 @@ block content


block extra_js
script(src="#{cdnPayRoot}/#{ecWWWLang}/js/download.js?_v_=#{homeVersion}")
script(src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/download.js')}")
script(type='text/javascript').
document.getElementById('nav-download').className = 'active';

@@ -1,2 +1,2 @@
include ./nav-mixin
+nav(host, cdnPayRoot, cdnPayVersionParam)
+nav(host, cdnPayRoot, cdnPayVersion)
@@ -60,5 +60,5 @@ block extra_js
script(type='text/javascript').
document.getElementById('nav-resources').className = 'active';

script(src='#{cdnThirdParty.echartsMinJS_4_8_0}')
script(src='#{cdnPayRoot}/#{ecWWWLang}/js/cheat-sheet-en.js?_v_=#{homeVersion}')
script(src="#{cdnThirdParty.echartsMinJS_4_8_0}")
script(src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/cheat-sheet-en.js')}")
@@ -73,7 +73,7 @@ block content
include ./footer

block extra_js
script(src="#{cdnPayRoot}/#{ecWWWLang}/js/download.js?_v_=#{homeVersion}")
script(src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/download.js')}")
script(type='text/javascript').
document.getElementById('nav-download').className = 'active';

@@ -169,5 +169,5 @@ block extra_js
elements_selector: ".lazy"
};
script(src='https://cdn.jsdelivr.net/npm/vanilla-lazyload@12.0.0/dist/lazyload.min.js')
script(src='#{cdnPayRoot}/#{ecWWWLang}/js/index.js?_v_=#{homeVersion}')
script(src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/index.js')}")
<script async defer src="https://buttons.github.io/buttons.js"></script>
@@ -1,3 +1,3 @@
nav(role="navigation", class="navbar navbar-default navbar-fixed-top")
include ./nav-mixin
+nav(host, cdnPayRoot, cdnPayVersionParam)
+nav(host, cdnPayRoot, cdnPayVersion)
@@ -6,7 +6,7 @@ block variablesLang
block extra_head
title Spreadsheet Tool - Apache ECharts (incubating)
link(rel="stylesheet", type="text/css", href="#{cdnPayRoot}/#{ecWWWLang}/vendors/handsontable/0.26.1/dist/handsontable.full.min.css?_v_=#{cdnPayVersion}")
link(rel="stylesheet", type="text/css", href="#{cdnPayRoot}/#{ecWWWLang}/css/spreadsheet.css?_v_=#{homeVersion}")
link(rel="stylesheet", type="text/css", href="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/css/spreadsheet.css')}")
script(src="vendors/esl.js")


@@ -24,7 +24,7 @@ html(lang='#{htmlAttrLang}')
script(src='https://oss.maxcdn.com/respond/1.4.2/respond.min.js')
<![endif]-->

link(rel='stylesheet', type='text/css', href='#{cdnPayRoot}/#{ecWWWLang}/css/main.css?_v_=#{homeVersion}')
link(rel='stylesheet', type='text/css', href="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/css/main.css')}")

script.
window.EC_WWW_LANG = '#{ecWWWLang}';
@@ -71,7 +71,7 @@ html(lang='#{htmlAttrLang}')
block content

script(type='text/javascript', src='#{cdnThirdParty.bootstrapJS}')
script(type='text/javascript', src='#{cdnPayRoot}/#{ecWWWLang}/js/common.js?_v_=#{homeVersion}')
script(type='text/javascript', src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/common.js')}")

block extra_js

@@ -2,7 +2,7 @@ extends basic

block extra_head
title ECharts Documentation
link(rel="stylesheet", type="text/css", href="css/ecOption.css?_v_=#{homeVersion}")
link(rel="stylesheet", type="text/css", href="css/ecOption.css")
link(rel="stylesheet", type="text/css", href="vendors/prettify/prettify.css")
link(rel="stylesheet", type="text/css", href="vendors/perfect-scrollbar/0.6.8/css/perfect-scrollbar.min.css")
link(rel="stylesheet", type="text/css", href="vendors/jquery-autocomplete/jquery.auto-complete.css")
@@ -54,7 +54,7 @@ block extra_js
var vendorPath = '../vendors';

define('globalArgs', extend({
version: '#{homeVersion}',
version: '',
basePath: './',
// Schema url is added by each doc page
schemaUrl: '',
@@ -81,7 +81,7 @@ block extra_js
hasher: vendorPath + '/hasher/1.2.0/hasher.min',
perfectScrollbar: vendorPath + '/perfect-scrollbar/0.6.8/js/perfect-scrollbar'
},
urlArgs: '_v_=#{homeVersion}'
urlArgs: ''
});

require(['docTool/main'], function (main) {
@@ -8,7 +8,7 @@ block extra_head
overflow-x: hidden;
}
link(rel="stylesheet", href="#{cdnThirdParty.elementUICSS}")
link(rel="stylesheet", href="#{cdnPayRoot}/#{ecWWWLang}/css/doc-bundle.css?_v_=#{homeVersion}")
link(rel="stylesheet", href="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/css/doc-bundle.css')}")

block content

@@ -45,14 +45,14 @@ block extra_js
script(src="#{cdnThirdParty.codeMirrorJS}")
script(src="#{cdnThirdParty.codeMirrorJSModeJS}")
script(src="#{cdnThirdParty.beautifierJS}")
script(src="#{cdnPayRoot}/#{ecWWWLang}/js/doc-bundle.js?_v_=#{homeVersion}")
script(src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/doc-bundle.js')}")
script(type="text/javascript").
window.EC_WWW_CDN_PAY_ROOT = '#{cdnPayRoot}';

block global_args_extra

script(type="text/javascript").
document.getElementById('nav-doc').className = 'active';
window.globalArgsExtra.version = '#{homeVersion}';
window.globalArgsExtra.version = '#{docHash}';
echartsDoc.init('#ec-doc-main', window.globalArgsExtra);

@@ -8,7 +8,7 @@ block extra_head
overflow-x: hidden;
}
link(rel="stylesheet", href="#{cdnThirdParty.elementUICSS}")
link(rel="stylesheet", href="#{cdnPayRoot}/next/#{ecWWWLang}/css/doc-bundle.css?_v_=#{homeVersion}")
link(rel="stylesheet", href="#{getAssetUrl(cdnPayRoot, 'next/' + ecWWWLang + '/css/doc-bundle.css')}")

block content

@@ -29,14 +29,14 @@ block extra_js
script(src="#{cdnThirdParty.codeMirrorJS}")
script(src="#{cdnThirdParty.codeMirrorJSModeJS}")
script(src="#{cdnThirdParty.beautifierJS}")
script(src="#{cdnPayRoot}/next/#{ecWWWLang}/js/doc-bundle.js?_v_=#{homeVersion}")
script(src="#{getAssetUrl(cdnPayRoot, 'next/' + ecWWWLang + '/js/doc-bundle.js')}")
script(type="text/javascript").
window.EC_WWW_CDN_PAY_ROOT = '#{cdnPayRoot}';

block global_args_extra

script(type="text/javascript").
document.getElementById('nav-ec5').className = 'active';
window.globalArgsExtra.version = '#{homeVersion}';
window.globalArgsExtra.version = '#{nextDocHash}';
echartsDoc.init('#ec-doc-main', window.globalArgsExtra);

@@ -8,7 +8,7 @@ block extra_head
overflow-x: hidden;
}
link(rel="stylesheet", href="#{cdnThirdParty.elementUICSS}")
link(rel="stylesheet", href="#{cdnPayRoot}/next/examples/css/example-bundle.css?_v_=#{homeVersion}")
link(rel="stylesheet", href="#{getAssetUrl(cdnPayRoot, 'next/examples/css/example-bundle.css')}")

block content

@@ -17,7 +17,7 @@ block content
block extra_js
script(src="#{cdnThirdParty.vueJS}")
script(src="#{cdnThirdParty.elementUIJS}")
script(src="#{cdnPayRoot}/next/examples/js/example-bundle.js?_v_=#{homeVersion}")
script(src="#{getAssetUrl(cdnPayRoot, 'next/examples/js/example-bundle.js')}")
script(type="text/javascript").
window.EC_WWW_CDN_PAY_ROOT = '#{cdnPayRoot}';

@@ -8,7 +8,7 @@ block extra_head
overflow-x: hidden;
}
link(rel="stylesheet", href="#{cdnThirdParty.elementUICSS}")
link(rel="stylesheet", href="#{cdnPayRoot}/next/examples/css/example-bundle.css?_v_=#{homeVersion}")
link(rel="stylesheet", href="#{getAssetUrl(cdnPayRoot, 'next/examples/css/example-bundle.css')}")

block content

@@ -26,7 +26,7 @@ block content
block extra_js
script(src="#{cdnThirdParty.vueJS}")
script(src="#{cdnThirdParty.elementUIJS}")
script(src="#{cdnPayRoot}/next/examples/js/example-bundle.js?_v_=#{homeVersion}")
script(src="#{getAssetUrl(cdnPayRoot, 'next/examples/js/example-bundle.js')}")
script(type="text/javascript").
window.EC_WWW_CDN_PAY_ROOT = '#{cdnPayRoot}';

@@ -58,4 +58,4 @@ block extra_js
document.getElementById('nav-resources').className = 'active';

script(src='#{cdnThirdParty.echartsMinJS_4_8_0}')
script(src='#{cdnPayRoot}/#{ecWWWLang}/js/cheat-sheet.js?_v_=#{homeVersion}')
script(type='text/javascript', src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/cheat-sheet.js')}")
@@ -31,8 +31,8 @@ block extra_js
var GALLERY_VIEW_PATH = GALLERY_PATH + 'view.html?c=';
var GALLERY_THUMB_PATH = GALLERY_PATH + 'data/thumb/';

script(type='text/javascript', src='#{cdnPayRoot}/#{ecWWWLang}/js/config.js?_v_=#{homeVersion}')
script(type='text/javascript', src='#{cdnPayRoot}/#{ecWWWLang}/js/examples-nav.js?_v_=#{homeVersion}')
script(type='text/javascript', src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/config.js')}")
script(type='text/javascript', src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/examples-nav.js')}")

script(type='text/javascript').
document.getElementById('nav-examples').className = 'active';
@@ -30,9 +30,9 @@ block extra_js
var GALLERY_VIEW_PATH = GALLERY_PATH + 'view.html?c=';
var GALLERY_THUMB_PATH = GALLERY_PATH + 'data/thumb/';

script(type='text/javascript', src='#{cdnPayRoot}/#{ecWWWLang}/js/config.js?_v_=#{homeVersion}')
script(type='text/javascript', src='#{cdnPayRoot}/#{ecWWWLang}/js/chart-list.js?_v_=#{homeVersion}')
script(type='text/javascript', src='#{cdnPayRoot}/#{ecWWWLang}/js/examples-nav.js?_v_=#{homeVersion}')
script(type='text/javascript', src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/config.js')}")
script(type='text/javascript', src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/chart-list.js')}")
script(type='text/javascript', src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/examples-nav.js')}")

script(type='text/javascript').
document.getElementById('nav-examples').className = 'active';
@@ -13,6 +13,7 @@ const argv = require('yargs').argv;
const assert = require('assert');
const requirejs = require('requirejs');
const readline = require('readline');
const md5 = require('md5');

const LANGUAGES = ['zh', 'en'];
const projectDir = path.resolve(__dirname, '..');
@@ -74,6 +75,18 @@ function initEnv() {

assert(path.isAbsolute(config.releaseDestDir));

config.getAssetUrl = function (cdnPayRoot, filePath) {
const fullFilePath = path.join(config.releaseDestDir, filePath);
let content;
try {
content = fs.readFileSync(fullFilePath, 'utf-8');
}
catch (e) {
throw new Error(`Unkown file ${fullFilePath}`);
}
const hash = md5(content);
return cdnPayRoot + '/' + filePath + '?_v_=' + hash.substr(-10);
};
// Update home version each build.
config.homeVersion = +new Date();
// Temp: give a fixed version until need to update.
@@ -145,6 +158,20 @@ async function buildSASS(config) {
console.log('buildSASS done.');
}

async function getFolderHash(globPattern) {
const files = await globby(globPattern);
if (!files.length) {
throw new Error('No file exists for pattern ' + globPattern);
}
let concatedStr = '';
for (let file of files) {
const content = fs.readFileSync(file);
concatedStr += md5(content);
}
assert(concatedStr);
return md5(concatedStr).substr(-10);
}

async function buildJade(config) {
const basePath = path.resolve(projectDir, '_jade');
const srcPaths = await globby([
@@ -153,11 +180,21 @@ async function buildJade(config) {
cwd: basePath
});

const hashes = {};
for (let lang of ['zh', 'en']) {
hashes[lang] = {
docHash: await getFolderHash(path.resolve(config.releaseDestDir, lang, 'documents/**/*.js')),
nextDocHash: await getFolderHash(path.resolve(config.releaseDestDir, 'next', lang, 'documents/**/*.js'))
};
}

for (let srcPath of srcPaths) {
let filePath = path.resolve(basePath, srcPath);
const lang = srcPath.indexOf('zh/') === 0 ? 'zh' : 'en';

const cfg = Object.assign({}, config);
assert(hashes[lang]);

const cfg = Object.assign({}, config, hashes[lang]);
cfg.cdnPayRoot = config.cdnPayRootMap[lang];
cfg.cdnFreeRoot = config.cdnFreeRootMap[lang];

@@ -469,14 +506,16 @@ async function run() {
else {
if (config.filter === 'all') {
await buildSASS(config);
await buildJade(config);
await buildJS(config);
await copyResource(config);
await updateSourceVersion(config);

await buildLegacyDoc(config);
await buildSpreadsheet(config);

// Build jade at last because it needs to read the resources.
await buildJade(config);

await makeCDNChecker(config);
}
else {
@@ -23,6 +23,7 @@
"globby": "^10.0.1",
"jade": "^1.11.0",
"less": "^3.10.3",
"md5": "^2.3.0",
"node-sass": "^4.13.0",
"onchange": "^6.1.0",
"postcss": "^7.0.25",

0 comments on commit 4c4e51f

Please sign in to comment.