Skip to content

Commit 8cbbf1d

Browse files
committed
fix: adapt new doc version
1 parent 3e489bc commit 8cbbf1d

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

bin/echarts-offline-doc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ program
1717
.option('-c, --cnpm', '使用 `cnpm` 安装依赖')
1818
.option('-s, --serve', '开启一个 HTTP Server 查看离线文档')
1919
.option('-l, --local', '本地查看离线文档')
20+
.option('--verbose', '输出调试日志')
2021
.parse(process.argv)
2122

2223
const options = program.opts()

build/modify.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const {
66
PATH_REPO_DOC_ASSETS,
77
PATH_REPO_DOC_PUBLIC,
88
PATH_REPO_DOC_SRC,
9+
PATH_REPO_DOC_BUILD,
910
PATH_REPO_DOC_BUILD_ENTRY,
1011
URL_ECHARTS_FAVICON,
11-
PATH_REPO_DOC
1212
} = require('../config')
1313

1414
function getRelativePath(assetPath) {
@@ -42,7 +42,11 @@ async function modify(assetsMapping) {
4242
})
4343

4444
// rewrite the URLs in source files
45-
const relativePathRoot = getRelativePath(require(PATH_REPO_DOC_BUILD_ENTRY).output.path) + '/'
45+
let webpackConfig = require(PATH_REPO_DOC_BUILD_ENTRY)
46+
if (typeof webpackConfig === 'function') {
47+
webpackConfig = await webpackConfig('asf', 'production')
48+
}
49+
const relativePathRoot = getRelativePath(webpackConfig.output.path) + '/'
4650
const files = await globby('**/*.{js,vue}', {
4751
cwd: PATH_REPO_DOC_SRC,
4852
ignore: '**/documents/**',
@@ -58,7 +62,7 @@ async function modify(assetsMapping) {
5862
fs.writeFileSync(file, content, 'utf8')
5963
}
6064

61-
const buildScriptPath = path.resolve(PATH_REPO_DOC, 'build.js')
65+
const buildScriptPath = path.resolve(PATH_REPO_DOC_BUILD, 'build-doc.js')
6266
const buildScriptContent = fs.readFileSync(buildScriptPath, 'utf8')
6367
fs.writeFileSync(
6468
buildScriptPath,

config/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const PATH_REPO_DOC_CONFIG = path.resolve(PATH_REPO_DOC, './config')
1111
const PATH_REPO_DOC_SRC = path.resolve(PATH_REPO_DOC, './src')
1212
const PATH_REPO_DOC_PUBLIC = path.resolve(PATH_REPO_DOC, './public')
1313
const PATH_REPO_DOC_ASSETS = path.resolve(PATH_REPO_DOC_PUBLIC, './assets')
14-
const PATH_REPO_DOC_BUILD_ENTRY = path.resolve(PATH_REPO_DOC, './build/webpack.config.js')
14+
const PATH_REPO_DOC_BUILD = path.resolve(PATH_REPO_DOC, './build')
15+
const PATH_REPO_DOC_BUILD_ENTRY = path.resolve(PATH_REPO_DOC_BUILD, './webpack.config.js')
1516

1617
const URL_ECHARTS_LOGO = 'https://echarts.apache.org/zh/images/logo.png'
1718
const URL_ECHARTS_FAVICON = 'https://echarts.apache.org/zh/images/favicon.png'
@@ -28,6 +29,7 @@ module.exports = {
2829
PATH_REPO_DOC_SRC,
2930
PATH_REPO_DOC_PUBLIC,
3031
PATH_REPO_DOC_ASSETS,
32+
PATH_REPO_DOC_BUILD,
3133
PATH_REPO_DOC_BUILD_ENTRY,
3234

3335
URL_ECHARTS_LOGO,

config/view-online.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { officialWebsitePath } = require('./env.local')
1+
const { officialWebsitePath } = require('./env.asf-override')
22

33
module.exports = function() {
44
return /* html */`

index.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const chalk = require('chalk')
55
const globby = require('globby')
66
const Spinnies = require('spinnies')
77

8+
const isVerbose = process.argv.includes('--verbose')
9+
810
const {
911
PATH_DIST,
1012
PATH_TMP,
@@ -34,7 +36,7 @@ function createSpawn(command, args, cwd, processName) {
3436
command, args,
3537
{
3638
cwd,
37-
stdio: 'ignore',
39+
stdio: isVerbose ? 'inherit' : 'ignore',
3840
windowsHide: true,
3941
detached: false
4042
}
@@ -161,7 +163,7 @@ async function build() {
161163

162164
await fs.remove(PATH_DIST)
163165

164-
const configFileName = 'env.local.js'
166+
const configFileName = 'env.asf-override.js'
165167
// copy config
166168
await fs.copy(
167169
path.resolve(__dirname, `./config/${configFileName}`),
@@ -185,7 +187,7 @@ async function build() {
185187
)
186188

187189
await createSpawn(
188-
'node', ['build.js', '--env', 'local'],
190+
'node', ['build.js', '--env', 'asf'],
189191
PATH_REPO_DOC,
190192
processName
191193
)
@@ -264,11 +266,15 @@ async function cleanup(suppressError) {
264266
}
265267

266268
process.on('uncaughtException', e => {
267-
console.error(chalk.red('An uncaught error occurred'))
268-
console.error(chalk.red(e))
269+
console.error(chalk.red('An uncaught error occurred:\n' + e.stack))
269270
process.exit(-2)
270271
})
271272

273+
process.on('unhandledRejection', (reason) => {
274+
console.error(chalk.red('An unhandled promise rejection occurred:\n' + (reason.stack || reason)))
275+
process.exit(-3)
276+
})
277+
272278
module.exports = async function run() {
273279
try {
274280
// cleanup first
@@ -291,8 +297,8 @@ module.exports = async function run() {
291297
// build
292298
await build()
293299
} catch (e) {
294-
console.error(chalk.red(e))
300+
console.error(chalk.red(e.stack))
295301
} finally {
296-
await cleanup(true)
302+
await cleanup(!isVerbose)
297303
}
298304
}

0 commit comments

Comments
 (0)