mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
feat(packages): add poster component to video skins (#994)
This commit is contained in:
@@ -8,6 +8,8 @@ import prompts from 'prompts';
|
||||
|
||||
export const SRC = './src';
|
||||
export const TEMPLATES = './templates';
|
||||
const IGNORED_ROOT_FILES = new Set(['index.html']);
|
||||
const GENERATED_SRC_FILES = new Set(['index.html', '__app-shell__.ts']);
|
||||
|
||||
export interface Change {
|
||||
state: 'left' | 'right' | 'distinct';
|
||||
@@ -25,7 +27,7 @@ export function getChanges(): Change[] {
|
||||
name: (d.name1 ?? d.name2)!,
|
||||
relativePath: d.relativePath,
|
||||
}))
|
||||
.filter((d) => d.name != null);
|
||||
.filter((d) => d.name != null && !shouldIgnoreChange(d));
|
||||
}
|
||||
|
||||
function colorizePatch(patch: string): string {
|
||||
@@ -53,6 +55,21 @@ export function printDiff(oldPath: string, newPath: string, label: string): void
|
||||
console.log(colorizePatch(body));
|
||||
}
|
||||
|
||||
function isGeneratedSrcFile(change: Change): boolean {
|
||||
return change.relativePath === '.' && GENERATED_SRC_FILES.has(change.name);
|
||||
}
|
||||
|
||||
function isIgnoredRootFile(change: Change): boolean {
|
||||
return change.relativePath === '.' && IGNORED_ROOT_FILES.has(change.name);
|
||||
}
|
||||
|
||||
function shouldIgnoreChange(change: Change): boolean {
|
||||
if (isGeneratedSrcFile(change) || isIgnoredRootFile(change)) return true;
|
||||
|
||||
// Sync/reset only manage sandbox directories, not loose files at the root.
|
||||
return change.relativePath === '.';
|
||||
}
|
||||
|
||||
export function filePath(change: Change): string {
|
||||
return path.join(change.relativePath, change.name);
|
||||
}
|
||||
@@ -65,6 +82,57 @@ export function templatesPath(change: Change): string {
|
||||
return path.join(TEMPLATES, change.relativePath, change.name);
|
||||
}
|
||||
|
||||
export async function mirrorTemplatesToSrc(): Promise<string[]> {
|
||||
const created: string[] = [];
|
||||
|
||||
async function mirror(dir: string): Promise<void> {
|
||||
for (const entry of await fs.readdir(dir)) {
|
||||
const templatePath = path.join(dir, entry);
|
||||
const relativeFilePath = path.relative(TEMPLATES, templatePath);
|
||||
const targetPath = path.join(SRC, relativeFilePath);
|
||||
const stats = await fs.stat(templatePath);
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
await fs.ensureDir(targetPath);
|
||||
await mirror(templatePath);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (await fs.pathExists(targetPath)) continue;
|
||||
|
||||
await fs.copy(templatePath, targetPath);
|
||||
created.push(targetPath);
|
||||
}
|
||||
}
|
||||
|
||||
for (const entry of await fs.readdir(TEMPLATES)) {
|
||||
const templatePath = path.join(TEMPLATES, entry);
|
||||
const stats = await fs.stat(templatePath);
|
||||
|
||||
if (!stats.isDirectory()) continue;
|
||||
|
||||
await fs.ensureDir(path.join(SRC, entry));
|
||||
await mirror(templatePath);
|
||||
}
|
||||
|
||||
return created;
|
||||
}
|
||||
|
||||
export async function removeGeneratedSrcFiles(): Promise<string[]> {
|
||||
const removed: string[] = [];
|
||||
|
||||
for (const file of GENERATED_SRC_FILES) {
|
||||
const filePath = path.join(SRC, file);
|
||||
|
||||
if (!(await fs.pathExists(filePath))) continue;
|
||||
|
||||
await fs.remove(filePath);
|
||||
removed.push(filePath);
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
export async function confirm(message: string): Promise<boolean> {
|
||||
const { ok } = await prompts({
|
||||
type: 'confirm',
|
||||
|
||||
Reference in New Issue
Block a user