feat(runner): updated the way runner works
This commit is contained in:
14
.env
14
.env
@@ -1,11 +1,11 @@
|
||||
VITE_TITLE="Arknights: Ch'en/Chen the Holungday - 明日方舟:假日威龙陈"
|
||||
VITE_FILENAME=dyn_illust_char_1013_chen2
|
||||
VITE_LOGO_FILENAME=logo_rhodes_override
|
||||
VITE_FALLBACK_FILENAME=char_1013_chen2_2
|
||||
VITE_TITLE="Arknights: Chongyue - 明日方舟:重岳"
|
||||
VITE_FILENAME=dyn_illust_char_2024_chyue
|
||||
VITE_LOGO_FILENAME=logo_sui
|
||||
VITE_FALLBACK_FILENAME=char_2024_chyue_2
|
||||
VITE_VIEWPORT_LEFT=0
|
||||
VITE_VIEWPORT_RIGHT=0
|
||||
VITE_VIEWPORT_TOP=1
|
||||
VITE_VIEWPORT_BOTTOM=1
|
||||
VITE_INVERT_FILTER=false
|
||||
VITE_VIEWPORT_TOP=0
|
||||
VITE_VIEWPORT_BOTTOM=0
|
||||
VITE_INVERT_FILTER=true
|
||||
VITE_IMAGE_WIDTH=2048
|
||||
VITE_IMAGE_HEIGHT=2048
|
||||
30
README.md
30
README.md
@@ -11,29 +11,29 @@ A project that builds showcase webpage for Arknights Live2D-equipped operators.
|
||||
### Command Line Tool
|
||||
|
||||
``` bash
|
||||
$ O={operator_name} node runner.js
|
||||
$ node runner.js generate {operator_name}
|
||||
To generate operator assets for showcase page
|
||||
```
|
||||
``` bash
|
||||
$ node runner.js -a
|
||||
To generate all operator assets for showcase page
|
||||
```
|
||||
``` bash
|
||||
$ O={operator_name} node runner.js -i
|
||||
To initialize folder and config file for an operator
|
||||
```
|
||||
``` bash
|
||||
$ node runner.js -d
|
||||
To generate directory.json
|
||||
```
|
||||
``` bash
|
||||
$ O={operator_name} pnpm run dev
|
||||
$ node runner.js dev {operator_name}
|
||||
Live showcase page server for development
|
||||
```
|
||||
``` bash
|
||||
$ O={operator_name} pnpm run build
|
||||
$ node runner.js build {operator_name}
|
||||
Build showcase webpage for an operator
|
||||
```
|
||||
``` bash
|
||||
$ node runner.js build-all
|
||||
To generate all operator assets for showcase page
|
||||
```
|
||||
``` bash
|
||||
$ node runner.js init {operator_name}
|
||||
To initialize folder and config file for an operator
|
||||
```
|
||||
``` bash
|
||||
$ node runner.js directory
|
||||
To generate directory.json
|
||||
```
|
||||
### Webpage & JavaScript
|
||||
|
||||
Add query string `settings` to bring up the settings panel to adjust your settings. Then use appropriate JavaScript code to load your settings
|
||||
|
||||
@@ -7,11 +7,11 @@ export default class EnvGenerator {
|
||||
this.#config = config.operators[operatorName]
|
||||
}
|
||||
|
||||
async generate(dimensions) {
|
||||
return await this.#promise(dimensions)
|
||||
async generate() {
|
||||
return await this.#promise()
|
||||
}
|
||||
|
||||
#promise(dimensions) {
|
||||
#promise() {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve([
|
||||
`VITE_TITLE="${this.#config.title}"`,
|
||||
@@ -23,8 +23,8 @@ export default class EnvGenerator {
|
||||
`VITE_VIEWPORT_TOP=${this.#config.viewport_top}`,
|
||||
`VITE_VIEWPORT_BOTTOM=${this.#config.viewport_bottom}`,
|
||||
`VITE_INVERT_FILTER=${this.#config.invert_filter}`,
|
||||
`VITE_IMAGE_WIDTH=${dimensions[0]}`,
|
||||
`VITE_IMAGE_HEIGHT=${dimensions[1]}`,
|
||||
`VITE_IMAGE_WIDTH=2048`,
|
||||
`VITE_IMAGE_HEIGHT=2048`,
|
||||
].join('\n'))
|
||||
})
|
||||
}
|
||||
|
||||
22
libs/exec.js
22
libs/exec.js
@@ -1,12 +1,28 @@
|
||||
import { execSync } from 'child_process'
|
||||
import { createServer, build } from 'vite'
|
||||
|
||||
export function buildAll(config) {
|
||||
for (const [key, _] of Object.entries(config.operators)) {
|
||||
if (key.startsWith('_')) break;
|
||||
console.log(execSync(`O=${key} node runner.js && O=${key} pnpm run build`).toString());
|
||||
console.log(execSync(`node runner.js --build ${key}`).toString());
|
||||
}
|
||||
}
|
||||
|
||||
export function runDev(config) {
|
||||
|
||||
export function runDev(rootDir) {
|
||||
; (async () => {
|
||||
const server = await createServer({
|
||||
root: rootDir,
|
||||
})
|
||||
await server.listen()
|
||||
|
||||
server.printUrls()
|
||||
})()
|
||||
}
|
||||
|
||||
export function runBuild(rootDir) {
|
||||
; (async () => {
|
||||
await build({
|
||||
root: rootDir,
|
||||
})
|
||||
})()
|
||||
}
|
||||
@@ -15,6 +15,10 @@ export async function read(filePath, encoding = 'utf8') {
|
||||
return await fsP.readFile(filePath, encoding, { flag: 'r' })
|
||||
}
|
||||
|
||||
export async function readSync(filePath, encoding = 'utf8') {
|
||||
return fs.readFileSync(filePath, encoding, { flag: 'r' })
|
||||
}
|
||||
|
||||
export function exists(filePath) {
|
||||
return fs.existsSync(filePath)
|
||||
}
|
||||
@@ -45,3 +49,7 @@ export async function copy(sourcePath, targetPath) {
|
||||
mkdir(path.dirname(targetPath))
|
||||
return await fsP.copyFile(sourcePath, targetPath)
|
||||
}
|
||||
|
||||
function append(content, filePath) {
|
||||
|
||||
}
|
||||
|
||||
5
libs/readme.js
Normal file
5
libs/readme.js
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
export function append(config, operatorName, rootDir) {
|
||||
|
||||
}
|
||||
95
runner.js
95
runner.js
@@ -1,34 +1,32 @@
|
||||
import assert from 'assert'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import getConfig from './libs/config.js'
|
||||
import ProjectJson from './libs/project_json.js'
|
||||
import EnvGenerator from './libs/env_generator.js'
|
||||
import { write, rmdir, copy } from './libs/file.js'
|
||||
import AssetsProcessor from './libs/assets_processor.js'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import init from './libs/initializer.js'
|
||||
import directory from './libs/directory.js'
|
||||
import { buildAll } from './libs/exec.js'
|
||||
import { buildAll, runDev, runBuild } from './libs/exec.js'
|
||||
import { append } from './libs/readme.js'
|
||||
|
||||
let __dirname
|
||||
__dirname = __dirname || path.dirname(fileURLToPath(import.meta.url))
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||
const config = getConfig(__dirname)
|
||||
|
||||
let mode = null
|
||||
const op = process.argv[2]
|
||||
const OPERATOR_NAME = process.env.O || process.argv[3];
|
||||
|
||||
if (process.argv[1].endsWith('vite.js')) {
|
||||
mode = "VITE"
|
||||
} else {
|
||||
mode = "NODE"
|
||||
}
|
||||
const OPERATOR_NAME = process.argv[3];
|
||||
|
||||
/**
|
||||
* Skip all, no need for OPERATOR_NAME
|
||||
* --build-all: build all assets
|
||||
* --directory: build directory.json
|
||||
*/
|
||||
switch (op) {
|
||||
case '-a':
|
||||
case 'build-all':
|
||||
buildAll(config)
|
||||
process.exit(0)
|
||||
case '-d':
|
||||
case 'directory':
|
||||
directory(config, __dirname)
|
||||
process.exit(0)
|
||||
default:
|
||||
@@ -44,32 +42,38 @@ const SHOWCASE_PUBLIC_ASSSETS_FOLDER = path.join(SHOWCASE_PUBLIC_FOLDER, "assets
|
||||
const EXTRACTED_FOLDER = path.join(OPERATOR_SOURCE_FOLDER, OPERATOR_NAME, 'extracted')
|
||||
const OPERATOR_SHARE_FOLDER = path.join(OPERATOR_SOURCE_FOLDER, '_share')
|
||||
rmdir(SHOWCASE_PUBLIC_FOLDER)
|
||||
if (mode === 'NODE') {
|
||||
|
||||
switch (op) {
|
||||
case '-i':
|
||||
init(OPERATOR_NAME, __dirname, EXTRACTED_FOLDER)
|
||||
process.exit(0)
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
rmdir(OPERATOR_RELEASE_FOLDER)
|
||||
|
||||
const projectJson = new ProjectJson(config, OPERATOR_NAME, __dirname, OPERATOR_SHARE_FOLDER)
|
||||
projectJson.load().then((content) => {
|
||||
write(JSON.stringify(content, null, 2), path.join(OPERATOR_RELEASE_FOLDER, 'project.json'))
|
||||
})
|
||||
|
||||
const assetsProcessor = new AssetsProcessor(config, OPERATOR_NAME, __dirname)
|
||||
assetsProcessor.process(SHOWCASE_PUBLIC_ASSSETS_FOLDER, EXTRACTED_FOLDER).then((content) => {
|
||||
const envGenerator = new EnvGenerator(config, OPERATOR_NAME)
|
||||
envGenerator.generate(content.dimensions).then((value) => {
|
||||
write(value, path.join(__dirname, '.env'))
|
||||
})
|
||||
write(JSON.stringify(content.assetsJson, null), path.join(OPERATOR_SOURCE_FOLDER, OPERATOR_NAME, `${config.operators[OPERATOR_NAME].filename}.json`))
|
||||
})
|
||||
/**
|
||||
* Skip assets generation part
|
||||
* --init: init folder and config for an operator
|
||||
*/
|
||||
switch (op) {
|
||||
case 'init':
|
||||
init(OPERATOR_NAME, __dirname, EXTRACTED_FOLDER)
|
||||
process.exit(0)
|
||||
case 'readme':
|
||||
append(config, OPERATOR_NAME, __dirname)
|
||||
process.exit(0)
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
rmdir(OPERATOR_RELEASE_FOLDER)
|
||||
|
||||
const projectJson = new ProjectJson(config, OPERATOR_NAME, __dirname, OPERATOR_SHARE_FOLDER)
|
||||
projectJson.load().then((content) => {
|
||||
write(JSON.stringify(content, null, 2), path.join(OPERATOR_RELEASE_FOLDER, 'project.json'))
|
||||
})
|
||||
|
||||
const assetsProcessor = new AssetsProcessor(config, OPERATOR_NAME, __dirname)
|
||||
assetsProcessor.process(SHOWCASE_PUBLIC_ASSSETS_FOLDER, EXTRACTED_FOLDER).then((content) => {
|
||||
write(JSON.stringify(content.assetsJson, null), path.join(OPERATOR_SOURCE_FOLDER, OPERATOR_NAME, `${config.operators[OPERATOR_NAME].filename}.json`))
|
||||
})
|
||||
|
||||
const envGenerator = new EnvGenerator(config, OPERATOR_NAME, __dirname)
|
||||
envGenerator.generate().then((content) => {
|
||||
write(content, path.join(__dirname, '.env'))
|
||||
})
|
||||
const filesToCopy = [
|
||||
{
|
||||
filename: 'preview.jpg',
|
||||
@@ -96,7 +100,14 @@ filesToCopy.forEach((file) => {
|
||||
copy(path.join(file.source, file.filename), path.join(file.target, file.filename))
|
||||
})
|
||||
|
||||
export default {
|
||||
OPERATOR_NAME,
|
||||
config,
|
||||
switch (op) {
|
||||
case 'dev':
|
||||
runDev(__dirname)
|
||||
break
|
||||
case 'build':
|
||||
runBuild(__dirname)
|
||||
break
|
||||
case 'generate':
|
||||
default:
|
||||
break
|
||||
}
|
||||
@@ -1,6 +1,11 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import path from 'path'
|
||||
import data from './runner'
|
||||
import getConfig from './libs/config.js'
|
||||
|
||||
const data = {
|
||||
config: getConfig(__dirname),
|
||||
OPERATOR_NAME: process.argv[3],
|
||||
}
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
|
||||
Reference in New Issue
Block a user