feat(showcase): add preview option
This commit is contained in:
17
aklive2d.js
17
aklive2d.js
@@ -23,17 +23,12 @@ async function main() {
|
|||||||
const op = process.argv[2]
|
const op = process.argv[2]
|
||||||
let OPERATOR_NAMES = process.argv.slice(3);
|
let OPERATOR_NAMES = process.argv.slice(3);
|
||||||
|
|
||||||
const background = new Background()
|
|
||||||
await background.process()
|
|
||||||
const backgrounds = ['operator_bg.png', ...background.files]
|
|
||||||
const charwordTable = new CharwordTable()
|
const charwordTable = new CharwordTable()
|
||||||
|
|
||||||
directory()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Skip all, no need for OPERATOR_NAME
|
* Skip all, no need for OPERATOR_NAME
|
||||||
* build-all: build all assets
|
* build-all: build all assets
|
||||||
* directory: build directory.json
|
* directory: build directory
|
||||||
*/
|
*/
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case 'directory':
|
case 'directory':
|
||||||
@@ -45,6 +40,10 @@ async function main() {
|
|||||||
OPERATOR_NAMES.push(key)
|
OPERATOR_NAMES.push(key)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
case 'preview':
|
||||||
|
assert(OPERATOR_NAMES.length !== 0, 'Please set the operator name.')
|
||||||
|
fork(path.join(__projetRoot, 'vite.config.js'), [op, OPERATOR_NAMES])
|
||||||
|
return
|
||||||
case 'charword':
|
case 'charword':
|
||||||
await charwordTable.process()
|
await charwordTable.process()
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
@@ -54,6 +53,12 @@ async function main() {
|
|||||||
|
|
||||||
assert(OPERATOR_NAMES.length !== 0, 'Please set the operator name.')
|
assert(OPERATOR_NAMES.length !== 0, 'Please set the operator name.')
|
||||||
|
|
||||||
|
const background = new Background()
|
||||||
|
await background.process()
|
||||||
|
const backgrounds = ['operator_bg.png', ...background.files]
|
||||||
|
|
||||||
|
directory()
|
||||||
|
|
||||||
for (const OPERATOR_NAME of OPERATOR_NAMES) {
|
for (const OPERATOR_NAME of OPERATOR_NAMES) {
|
||||||
const OPERATOR_SOURCE_FOLDER = path.join(__projetRoot, __config.folder.operator)
|
const OPERATOR_SOURCE_FOLDER = path.join(__projetRoot, __config.folder.operator)
|
||||||
const OPERATOR_RELEASE_FOLDER = path.join(__projetRoot, __config.folder.release, OPERATOR_NAME)
|
const OPERATOR_RELEASE_FOLDER = path.join(__projetRoot, __config.folder.release, OPERATOR_NAME)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"dev": "node aklive2d dev",
|
"dev": "node aklive2d dev",
|
||||||
"build": "node aklive2d build",
|
"build": "node aklive2d build",
|
||||||
"build-all": "node aklive2d build-all",
|
"build-all": "node aklive2d build-all",
|
||||||
|
"preview": "node aklive2d preview",
|
||||||
"init": "node aklive2d init",
|
"init": "node aklive2d init",
|
||||||
"readme": "node aklive2d readme",
|
"readme": "node aklive2d readme",
|
||||||
"directory": "node aklive2d directory",
|
"directory": "node aklive2d directory",
|
||||||
|
|||||||
@@ -1,16 +1,27 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { fileURLToPath } from 'url'
|
import { fileURLToPath } from 'url'
|
||||||
import { defineConfig, loadEnv } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
import react from '@vitejs/plugin-react-swc'
|
import react from '@vitejs/plugin-react-swc'
|
||||||
import getConfig from './libs/config.js'
|
import getConfig from './libs/config.js'
|
||||||
|
import { rmdir } from './libs/file.js'
|
||||||
|
|
||||||
global.__projetRoot = path.dirname(fileURLToPath(import.meta.url))
|
global.__projetRoot = path.dirname(fileURLToPath(import.meta.url))
|
||||||
|
|
||||||
class ViteRunner {
|
class ViteRunner {
|
||||||
#globalConfig = getConfig()
|
#globalConfig = getConfig()
|
||||||
#mode
|
#mode
|
||||||
#baseViteConfig = {}
|
#baseViteConfig = {
|
||||||
|
configFile: false,
|
||||||
|
base: "",
|
||||||
|
server: {
|
||||||
|
host: '0.0.0.0',
|
||||||
|
},
|
||||||
|
build: {
|
||||||
|
emptyOutDir: false,
|
||||||
|
chunkSizeWarningLimit: 10000,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
config() {
|
config() {
|
||||||
let result;
|
let result;
|
||||||
@@ -19,10 +30,16 @@ class ViteRunner {
|
|||||||
switch (this.#mode) {
|
switch (this.#mode) {
|
||||||
case 'directory':
|
case 'directory':
|
||||||
result = this.directory()
|
result = this.directory()
|
||||||
|
const op = temp[2] || process.argv[3]
|
||||||
|
if (op !== 'preview') {
|
||||||
|
rmdir(path.resolve(__projetRoot, this.#globalConfig.folder.release, "_directory"))
|
||||||
|
rmdir(path.resolve(__projetRoot, this.#globalConfig.folder.release, "index.html"))
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case 'dev':
|
case 'dev':
|
||||||
case 'build':
|
case 'build':
|
||||||
case 'build-all':
|
case 'build-all':
|
||||||
|
case 'preview':
|
||||||
result = this.operator()
|
result = this.operator()
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
@@ -41,6 +58,9 @@ class ViteRunner {
|
|||||||
case 'build-all':
|
case 'build-all':
|
||||||
this.#build(viteConfig)
|
this.#build(viteConfig)
|
||||||
break
|
break
|
||||||
|
case 'preview':
|
||||||
|
this.#preview(viteConfig)
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -66,18 +86,25 @@ class ViteRunner {
|
|||||||
})()
|
})()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#preview(viteConfig) {
|
||||||
|
; (async () => {
|
||||||
|
const { preview } = await import('vite')
|
||||||
|
const previewServer = await preview({
|
||||||
|
...viteConfig,
|
||||||
|
})
|
||||||
|
|
||||||
|
previewServer.printUrls()
|
||||||
|
})()
|
||||||
|
}
|
||||||
|
|
||||||
operator() {
|
operator() {
|
||||||
const operatorName = process.env.O || process.argv[3]
|
const operatorName = process.env.O || process.argv[3]
|
||||||
assert(operatorName, 'Please set the operator name by using environment variable O.')
|
assert(operatorName, 'Please set the operator name by using environment variable O.')
|
||||||
return {
|
return {
|
||||||
configFile: false,
|
...this.#baseViteConfig,
|
||||||
base: "",
|
|
||||||
envDir: path.join(__projetRoot, this.#globalConfig.folder.operator, operatorName),
|
envDir: path.join(__projetRoot, this.#globalConfig.folder.operator, operatorName),
|
||||||
publicDir: path.resolve(__projetRoot, this.#globalConfig.folder.release, operatorName),
|
publicDir: path.resolve(__projetRoot, this.#globalConfig.folder.release, operatorName),
|
||||||
root: path.resolve(__projetRoot),
|
root: path.resolve(__projetRoot),
|
||||||
server: {
|
|
||||||
host: '0.0.0.0',
|
|
||||||
},
|
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': path.resolve(__projetRoot, './src'),
|
'@': path.resolve(__projetRoot, './src'),
|
||||||
@@ -85,9 +112,8 @@ class ViteRunner {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
|
...this.#baseViteConfig.build,
|
||||||
outDir: path.resolve(__projetRoot, this.#globalConfig.folder.release, operatorName),
|
outDir: path.resolve(__projetRoot, this.#globalConfig.folder.release, operatorName),
|
||||||
emptyOutDir: false,
|
|
||||||
chunkSizeWarningLimit: 10000,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,9 +138,9 @@ class ViteRunner {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
|
...this.#baseViteConfig.build,
|
||||||
outDir: path.resolve(__projetRoot, this.#globalConfig.folder.release),
|
outDir: path.resolve(__projetRoot, this.#globalConfig.folder.release),
|
||||||
emptyOutDir: false,
|
assetsDir: '_directory',
|
||||||
chunkSizeWarningLimit: 10000,
|
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
output: {
|
output: {
|
||||||
manualChunks: {
|
manualChunks: {
|
||||||
|
|||||||
Reference in New Issue
Block a user