-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecute.ts
34 lines (27 loc) · 1.23 KB
/
execute.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { fontFaceCore } from '@font-face/core';
import chalk from 'chalk';
import pkgDir from 'pkg-dir';
import {dirname, resolve} from 'path';
import NodeDirectoryContext from './nodeDirectoryContext';
import createResources from './createResources';
import cssComments from './cssComments';
import { FontFaceNodeConfig } from './index.d';
export default async(config: FontFaceNodeConfig) => {
const appRoot = pkgDir.sync();
console.log(chalk.cyan('Found app root as '), chalk.green(appRoot));
const {input, output, fonts} = config;
const {dir: inputDir} = input;
const {dir: outputDir, resourceDir, cssFileName} = output;
const inputDirPath = resolve(appRoot, inputDir);
const outputDirPath = resolve(appRoot, outputDir);
const resourceDirPath = resolve(appRoot, resourceDir || resolve(outputDirPath, 'resources'));
const rawCss = fontFaceCore({
directoryContext: new NodeDirectoryContext({inputDirPath, outputDirPath, resourceDirPath}),
fonts,
});
const cssContent = cssComments + '\n' + rawCss;
await createResources({
inputDirPath, outputDirPath, resourceDirPath, cssFileName, cssContent,
});
console.log(chalk.cyan('Done !!'));
};