-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(packages): add
crypto-frontmatter mirror
to copy raw assets (#26)
#### What this PR does / why we need it: Optimizes the `crypto-frontmatter` project.
- Loading branch information
Showing
23 changed files
with
216 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#! /usr/bin/env node | ||
/* eslint-disable */ | ||
require('./dist/cli.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { copyFile, mkdir } from 'node:fs/promises'; | ||
import { join } from 'node:path'; | ||
|
||
import { Command, Option, runExit } from 'clipanion'; | ||
|
||
import { getFrontmatterIndexArray, getInstalledFrontmatterCollection, getNodeModulesPath } from './index'; | ||
|
||
export class MirrorCommand extends Command { | ||
static override paths = [[`mirror`]]; | ||
private target = Option.String(); | ||
|
||
async execute(): Promise<number | void> { | ||
await mkdir(this.target, { recursive: true }); | ||
|
||
const collections = await getInstalledFrontmatterCollection(); | ||
for (const collection of collections) { | ||
let count = 0; | ||
const indexArray = await getFrontmatterIndexArray(collection.caip2, collection.namespace); | ||
for (const frontmatterIndex of indexArray) { | ||
for (const frontmatterImage of frontmatterIndex.fields.images) { | ||
const from = getNodeModulesPath(collection.caip2, collection.namespace, frontmatterImage.path); | ||
const to = join(this.target, frontmatterImage.path); | ||
count++; | ||
await copyFile(from, to); | ||
} | ||
} | ||
|
||
this.context.stdout.write(`Mirrored ${count} files for "${collection.caip2}/${collection.namespace}"\n`); | ||
} | ||
} | ||
} | ||
|
||
// noinspection JSIgnoredPromiseFromCall | ||
void runExit([MirrorCommand]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.