fix build example
diff --git a/package.json b/package.json
index cbc49e1..90c55fe 100644
--- a/package.json
+++ b/package.json
@@ -5,11 +5,11 @@
"scripts": {
"build": "npx webpack --config build/webpack.config.js --mode production",
"watch": "npx webpack --config build/webpack.config.js --mode development --devtool source-map --watch",
- "localsite": "npm run build && node build/copyResource.js --env localsite",
- "release": "npm run build && node build/copyResource.js --env asf",
+ "localsite": "npm run compile:example || npm run build && node build/copyResource.js --env localsite",
+ "release": "npm run compile:example || npm run build && node build/copyResource.js --env asf",
"dev": "npx concurrently --kill-others \"npm:watch\" \"npm:server\"",
- "build:example": "node tool/build-example.js && node tool/build-example.js --source data-gl",
- "compile:example": "tsc --project public/examples/tsconfig.json || prettier --write public/examples/js",
+ "build:example": "npm run compile:example || node tool/build-example.js && node tool/build-example.js --gl",
+ "compile:example": "node tool/compile-example.js",
"test:e2e": "node e2e/main.js --bundler webpack -m",
"test:e2e:local": "node e2e/main.js --bundler webpack -m --local",
"test:e2e:esbuild": "node e2e/main.js --bundler esbuild -m",
diff --git a/public/examples/tsconfig.json b/public/examples/tsconfig.json
index b689d9a..f47c85b 100644
--- a/public/examples/tsconfig.json
+++ b/public/examples/tsconfig.json
@@ -1,13 +1,13 @@
{
- "compilerOptions": {
- "target": "ES6",
- "strict": true,
- "moduleResolution": "node",
- "allowJs": true,
- "checkJs": false,
- "pretty": true,
- "outDir": "./js/",
- "baseUrl": "./"
- },
- "include": ["./ts/**/*.ts", "./ts/**/*.js", "./types/**/*.d.ts"]
-}
\ No newline at end of file
+ "compilerOptions": {
+ "target": "ES6",
+ "strict": true,
+ "moduleResolution": "node",
+ "allowJs": true,
+ "checkJs": false,
+ "pretty": true,
+ "outDir": "./js/",
+ "baseUrl": "./"
+ },
+ "include": ["./ts/**/*.ts", "./ts/**/*.js", "./types/**/*.d.ts"]
+}
diff --git a/src/common/store.js b/src/common/store.js
index f6a56df..af35246 100644
--- a/src/common/store.js
+++ b/src/common/store.js
@@ -49,6 +49,7 @@
.replace(/\/\*[\w\W]*?\*\//, '')
.trim()
// ts code needs add `export {}` to be a module. remove it.
+ // FIXME
.replace(/export\s+\{\s*\}\s*;?$/g, '')
);
}
diff --git a/tool/build-example.js b/tool/build-example.js
index ac763da..b23290b 100644
--- a/tool/build-example.js
+++ b/tool/build-example.js
@@ -36,8 +36,8 @@
const parser = new argparse.ArgumentParser({
addHelp: true
});
-parser.addArgument(['-s', '--source'], {
- help: 'Source folder'
+parser.addArgument(['--gl'], {
+ help: 'If generating gl'
});
parser.addArgument(['-t', '--theme'], {
help: 'Theme list, default to be all'
@@ -51,7 +51,7 @@
});
const args = parser.parseArgs();
-const sourceFolder = args.source || 'data';
+const isGL = args.gl;
let themeList = args.theme || 'default,dark';
let matchPattern = args.pattern;
if (matchPattern) {
@@ -107,7 +107,8 @@
) {
const thumbFolder = theme !== 'default' ? 'thumb-' + theme : 'thumb';
const page = await browser.newPage();
- const thumbDir = `${rootDir}public/${sourceFolder}/${thumbFolder}`;
+ const dataDir = isGL ? 'data-gl' : 'data';
+ const thumbDir = `${rootDir}public/${dataDir}/${thumbFolder}`;
const fileBase = `${thumbDir}/${basename}`;
const webmFile = `${fileBase}.webm`;
@@ -138,7 +139,9 @@
width: shotWidth || DEFAULT_PAGE_WIDTH,
height: (shotWidth || DEFAULT_PAGE_WIDTH) * DEFAULT_PAGE_RATIO
});
- let url = `${SCREENSHOT_PAGE_URL}?c=${basename}&t=${theme}&s=${sourceFolder}`;
+ let url = `${SCREENSHOT_PAGE_URL}?c=${basename}&t=${theme}${
+ isGL ? '&gl' : ''
+ }`;
if (hasVideo) {
url += `&start=${videoStart}&end=${videoEnd}`;
@@ -193,9 +196,9 @@
return _$getEChartsOption();
});
const optionStr = optionToJson(option);
- fse.ensureDirSync(`${rootDir}public/${sourceFolder}/option/`);
+ fse.ensureDirSync(`${rootDir}public/${dataDir}/option/`);
fs.writeFileSync(
- `${rootDir}public/${sourceFolder}/option/${basename}.json`,
+ `${rootDir}public/${dataDir}/option/${basename}.json`,
optionStr,
'utf-8'
);
@@ -261,7 +264,9 @@
// TODO puppeteer will have Navigation Timeout Exceeded: 30000ms exceeded error in these examples.
const screenshotBlackList = [];
- const files = await globby(`${rootDir}public/${sourceFolder}/*.js`);
+ const files = await globby(
+ `${rootDir}public/examples/js/${isGL ? 'gl/' : ''}*.js`
+ );
const exampleList = [];
@@ -286,10 +291,7 @@
let fmResult;
try {
- const code = fs.readFileSync(
- `${rootDir}public/${sourceFolder}/${basename}.js`,
- 'utf-8'
- );
+ const code = fs.readFileSync(fileName, 'utf-8');
fmResult = matter(code, {
delimiters: ['/*', '*/']
});
@@ -355,7 +357,10 @@
if (!matchPattern) {
fs.writeFileSync(
- path.join(__dirname, `../src/data/chart-list-${sourceFolder}.js`),
+ path.join(
+ __dirname,
+ `../src/data/chart-list-data${isGL ? '-gl' : ''}.js`
+ ),
code,
'utf-8'
);
@@ -420,7 +425,7 @@
}
);
},
- sourceFolder === 'data-gl' ? 2 : 16
+ isGL ? 2 : 16
);
await runTasks(
diff --git a/tool/compile-example.js b/tool/compile-example.js
new file mode 100644
index 0000000..321bf4c
--- /dev/null
+++ b/tool/compile-example.js
@@ -0,0 +1,35 @@
+const globby = require('globby');
+const fs = require('fs');
+const path = require('path');
+const shell = require('shelljs');
+
+const exampleDir = path.join(__dirname, '../public/examples');
+
+async function run() {
+ const hasError =
+ shell.exec(`tsc --project ${path.join(exampleDir, 'tsconfig.json')}`)
+ .code !== 0;
+ shell.exec(`prettier --write ${path.join(exampleDir, 'js')}`);
+
+ const files = await globby(path.join(exampleDir, `js/**/*.js`));
+
+ for (let file of files) {
+ const content =
+ fs
+ .readFileSync(file, 'utf-8')
+ .trim()
+ // ts code needs add `export {}` to be a module. remove it.
+ // FIXME
+ .replace(/export\s+\{\s*\}\s*;?$/g, '')
+ .replace(/^'use strict';/, '')
+ .trim() + '\n';
+
+ fs.writeFileSync(file, content, 'utf-8');
+ }
+
+ if (hasError) {
+ shell.exit(1);
+ }
+}
+
+run();
diff --git a/tool/screenshot.html b/tool/screenshot.html
index ebab89e..271e8cc 100644
--- a/tool/screenshot.html
+++ b/tool/screenshot.html
@@ -141,10 +141,11 @@
console.error('No ROOT_PATH specified. Use default ROOT_PATH "."');
window.ROOT_PATH = '.';
}
- const sourceFolder = params.s || 'data';
const scriptTag = document.createElement('script');
scriptTag.async = false;
- scriptTag.src = `../public/${sourceFolder}/${params.c}.js`;
+ scriptTag.src = `../public/examples/js${'gl' in params ? '/gl' : ''}/${
+ params.c
+ }.js`;
document.body.appendChild(scriptTag);
let videoRecorder;