feat(cli): add site cli to run scripts + handle media
This commit is contained in:
parent
5055816f68
commit
d08787f5aa
12 changed files with 1615 additions and 26 deletions
101
cli/lib/config.js
Normal file
101
cli/lib/config.js
Normal file
|
@ -0,0 +1,101 @@
|
|||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import inquirer from 'inquirer';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const CACHE_DIR = path.resolve(__dirname, '..', '.cache');
|
||||
const CONFIG_PATH = path.join(CACHE_DIR, 'config.json');
|
||||
const MEDIA_TYPES = ['movie', 'show'];
|
||||
const ASSET_TYPES = ['poster', 'backdrop'];
|
||||
|
||||
export const initConfig = async () => {
|
||||
const config = {};
|
||||
const { storageDir } = await inquirer.prompt([{
|
||||
name: 'storageDir',
|
||||
message: 'Where is your storage root directory?',
|
||||
validate: fs.pathExists
|
||||
}]);
|
||||
|
||||
config.storageDir = storageDir;
|
||||
|
||||
const { customize } = await inquirer.prompt([{
|
||||
type: 'confirm',
|
||||
name: 'customize',
|
||||
message: 'Do you want to customize default media paths?',
|
||||
default: false
|
||||
}]);
|
||||
|
||||
config.mediaPaths = {};
|
||||
|
||||
for (const mediaType of MEDIA_TYPES) {
|
||||
config.mediaPaths[mediaType] = {};
|
||||
|
||||
for (const assetType of ASSET_TYPES) {
|
||||
const mediaFolder = `${mediaType}s`;
|
||||
const assetFolder = assetType === 'poster' ? '' : `/${assetType}s`;
|
||||
const defaultPath = `Media assets/${mediaFolder}${assetFolder}`.replace(/\/$/, '');
|
||||
let subpath = defaultPath;
|
||||
|
||||
if (customize) {
|
||||
const response = await inquirer.prompt([{
|
||||
name: 'subpath',
|
||||
message: `Subpath for ${mediaType}/${assetType} (relative to storage root):`,
|
||||
default: defaultPath
|
||||
}]);
|
||||
|
||||
subpath = response.subpath;
|
||||
}
|
||||
|
||||
config.mediaPaths[mediaType][assetType] = subpath;
|
||||
}
|
||||
}
|
||||
|
||||
config.artistPath = customize
|
||||
? (
|
||||
await inquirer.prompt([
|
||||
{
|
||||
name: 'artistPath',
|
||||
message: 'Subpath for artist images (relative to storage root):',
|
||||
default: 'Media assets/artists'
|
||||
}
|
||||
])
|
||||
).artistPath
|
||||
: 'Media assets/artists';
|
||||
config.albumPath = customize
|
||||
? (
|
||||
await inquirer.prompt([
|
||||
{
|
||||
name: 'albumPath',
|
||||
message: 'Subpath for album images (relative to storage root):',
|
||||
default: 'Media assets/albums'
|
||||
}
|
||||
])
|
||||
).albumPath
|
||||
: 'Media assets/albums';
|
||||
config.bookPath = customize
|
||||
? (
|
||||
await inquirer.prompt([
|
||||
{
|
||||
name: 'bookPath',
|
||||
message: 'Subpath for book images (relative to storage root):',
|
||||
default: 'Media assets/books'
|
||||
}
|
||||
])
|
||||
).bookPath
|
||||
: 'Media assets/books';
|
||||
|
||||
await fs.ensureDir(CACHE_DIR);
|
||||
await fs.writeJson(CONFIG_PATH, config, { spaces: 2 });
|
||||
|
||||
console.log(`✅ Config saved to ${CONFIG_PATH}`);
|
||||
}
|
||||
|
||||
export const loadConfig = async () => {
|
||||
if (!await fs.pathExists(CONFIG_PATH)) {
|
||||
console.error('❌ Config not found. Run `coryd init` first.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
return await fs.readJson(CONFIG_PATH);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue