From e58659d8fc98d21844216d39db18b5d63ff3400a Mon Sep 17 00:00:00 2001 From: Haoyu Xu Date: Mon, 16 Jan 2023 18:27:48 -0500 Subject: [PATCH] feat(directory): add directory.json for index page --- config.yaml | 3 ++- config/chongyue.yaml | 12 ++++++++++++ config/ling_it_does_wash_the_strings.yaml | 12 ++++++++++++ lib/directory.js | 18 ++++++++++++++++++ lib/file.js | 5 +++++ preprocessing.js | 15 ++++++++++++--- 6 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 config/chongyue.yaml create mode 100644 config/ling_it_does_wash_the_strings.yaml create mode 100644 lib/directory.js diff --git a/config.yaml b/config.yaml index bd8848c..04d80e2 100644 --- a/config.yaml +++ b/config.yaml @@ -24,4 +24,5 @@ operators: rosmontis_become_anew: !include config/rosmontis_become_anew.yaml passager_dream_in_a_moment: !include config/passager_dream_in_a_moment.yaml mizuki_summer_feast: !include config/mizuki_summer_feast.yaml - \ No newline at end of file + chongyue: !include config/chongyue.yaml + ling_it_does_wash_the_strings: !include config/ling_it_does_wash_the_strings.yaml \ No newline at end of file diff --git a/config/chongyue.yaml b/config/chongyue.yaml new file mode 100644 index 0000000..e15c39f --- /dev/null +++ b/config/chongyue.yaml @@ -0,0 +1,12 @@ +link: chongyue +type: operator +date: 2023/01 +title: 'Arknights: Chongyue - 明日方舟:重岳' +filename: dyn_illust_char_1013_chen2 +logo: logo_sui +fallback_name: char_1013_chen2_2 +viewport_left: 0 +viewport_right: 0 +viewport_top: 0 +viewport_bottom: 0 +invert_filter: true \ No newline at end of file diff --git a/config/ling_it_does_wash_the_strings.yaml b/config/ling_it_does_wash_the_strings.yaml new file mode 100644 index 0000000..b6d2de2 --- /dev/null +++ b/config/ling_it_does_wash_the_strings.yaml @@ -0,0 +1,12 @@ +link: ling_it_does_wash_the_strings +type: skin +date: 2023/01 +title: 'Arknights: It Does Wash the Strings / Ling - 明日方舟:濯缨 · 令' +filename: dyn_illust_char_2023_ling#4 +logo: logo_sui +fallback_name: char_2023_ling_2#4 +viewport_left: 0 +viewport_right: 0 +viewport_top: 0 +viewport_bottom: 0 +invert_filter: false \ No newline at end of file diff --git a/lib/directory.js b/lib/directory.js new file mode 100644 index 0000000..d9cb5fe --- /dev/null +++ b/lib/directory.js @@ -0,0 +1,18 @@ +import path from 'path' +import { writeSync, copy } from './file.js' + +export default function (config, rootDir) { + const targetFolder = path.join(rootDir, config.folder.release, "_assets"); + const sourceFolder = path.join(rootDir, config.folder.operator); + const filesToCopy = []; + const directoryJson = [] + for (const [key, value] of Object.entries(config.operators)) { + filesToCopy.push(key); + directoryJson.push(value); + } + writeSync(JSON.stringify(directoryJson, null), path.join(targetFolder, "directory.json")) + filesToCopy.forEach((key) => { + const filename = `${config.operators[key].filename}.json`; + copy(path.join(sourceFolder, key, filename), path.join(targetFolder, filename)) + }) +} diff --git a/lib/file.js b/lib/file.js index a0133a2..a7b5f2a 100644 --- a/lib/file.js +++ b/lib/file.js @@ -6,6 +6,11 @@ export async function write(content, filePath) { return await fsP.writeFile(filePath, content, { flag: 'w' }) } +export function writeSync(content, filePath) { + mkdir(path.dirname(filePath)) + return fs.writeFileSync(filePath, content, { flag: 'w' }) +} + export async function read(filePath, encoding = 'utf8') { return await fsP.readFile(filePath, encoding, { flag: 'r' }) } diff --git a/preprocessing.js b/preprocessing.js index 041749d..de56ddb 100644 --- a/preprocessing.js +++ b/preprocessing.js @@ -7,6 +7,7 @@ import AssetsProcessor from './lib/assets_processor.js' import path from 'path' import { fileURLToPath } from 'url' import init from './lib/initializer.js' +import directory from './lib/directory.js' let mode = null const OPERATOR_NAME = process.env.O; @@ -35,9 +36,17 @@ const EXTRACTED_FOLDER = path.join(OPERATOR_SOURCE_FOLDER, OPERATOR_NAME, 'extra const OPERATOR_SHARE_FOLDER = path.join(OPERATOR_SOURCE_FOLDER, '_share') if (mode === 'NODE') { - if (process.argv[2] === '-i') { - init(OPERATOR_NAME, __dirname, EXTRACTED_FOLDER) - process.exit(0) + const op = process.argv[2] + + switch (op) { + case '-i': + init(OPERATOR_NAME, __dirname, EXTRACTED_FOLDER) + process.exit(0) + case '-d': + directory(config, __dirname) + process.exit(0) + default: + break } rmdir(OPERATOR_RELEASE_FOLDER)