Skip to content

Commit

Permalink
Fix: Type Exports, Await main functions
Browse files Browse the repository at this point in the history
  • Loading branch information
black7375 committed Jan 9, 2023
1 parent f432305 commit 8779366
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 36 deletions.
10 changes: 5 additions & 5 deletions build/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ interface BlockI {
unicodes: string;
}
export declare function parseCSS(dirPath?: string, url?: string): Promise<BlockI[]>;
interface FontDefaultOptionI {
export interface FontDefaultOptionI {
saveDir: string;
format: Format;
nameFormat: string;
logFormat: string;
defaultArgs: string[];
etcArgs: string[];
}
interface FontRangeOptionI extends FontDefaultOptionI {
export interface FontRangeOptionI extends FontDefaultOptionI {
fromCSS: "default" | "srcIndex" | "srcName";
}
interface FontSubsetOptionI extends FontDefaultOptionI {
export interface FontSubsetOptionI extends FontDefaultOptionI {
textFile: string;
text: string;
}
interface FontPipeOptionI extends FontRangeOptionI, FontSubsetOptionI {
export interface FontPipeOptionI extends FontRangeOptionI, FontSubsetOptionI {
cssFile: string;
}
type ArgOptionT<I> = FontDefaultOptionI["saveDir"] | Partial<I>;
Expand All @@ -36,7 +36,7 @@ type Format = "otf" | "ttf" | "woff2" | "woff" | "woff-zopfli";
export declare const defaultArgs: string[];
export declare function fontRange(fontPath?: string, url?: string, fontRangeOption?: FontRangeOptionT): Promise<import("@esm2cjs/execa").ExecaSyncReturnValue<string>[]>;
export declare function fontSubset(fontPath?: string, fontSubsetOption?: FontSubsetOptionT): Promise<import("@esm2cjs/execa").ExecaSyncReturnValue<string>>;
interface FontPipeI {
export interface FontPipeI {
fontPath: string;
option?: FontPipeOptionT;
}
Expand Down
48 changes: 25 additions & 23 deletions build/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ function fontRange(fontPath = "", url = exports.targets.korean, fontRangeOption)
const result = yield worker.run(options);
return result;
}));
return Promise.all(result);
return yield Promise.all(result);
});
}
exports.fontRange = fontRange;
Expand Down Expand Up @@ -347,27 +347,29 @@ function getShardInfo(shardEnv) {
return [index, total];
}
function fontPipe(subsetList, shard) {
const shardEnv = (typeof shard === "object" && typeof shard.shard === "string")
? shard.shard
: (typeof shard === "object" || typeof shard === "undefined")
? process.env.SHARD || "1/1"
: shard;
const shardFormat = (typeof shard === "object" && typeof shard.shardFormat === "string")
? shard.shardFormat
: "== {START}/{END} ==========";
const [index, total] = getShardInfo(shardEnv);
const shardSize = Math.ceil(subsetList.length / total);
const shardStart = shardSize * (index - 1);
const shardEnd = shardSize * index;
if (shardEnv !== "1/1") {
const shardMsg = shardFormat
.replace("{START}", index.toString())
.replace("{END}", total.toString());
console.log(shardMsg);
}
const result = subsetList
.slice(shardStart, shardEnd)
.map(fontPipeExec);
return Promise.all(result);
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const shardEnv = (typeof shard === "object" && typeof shard.shard === "string")
? shard.shard
: (typeof shard === "object" || typeof shard === "undefined")
? process.env.SHARD || "1/1"
: shard;
const shardFormat = (typeof shard === "object" && typeof shard.shardFormat === "string")
? shard.shardFormat
: "== {START}/{END} ==========";
const [index, total] = getShardInfo(shardEnv);
const shardSize = Math.ceil(subsetList.length / total);
const shardStart = shardSize * (index - 1);
const shardEnd = shardSize * index;
if (shardEnv !== "1/1") {
const shardMsg = shardFormat
.replace("{START}", index.toString())
.replace("{END}", total.toString());
console.log(shardMsg);
}
const result = subsetList
.slice(shardStart, shardEnd)
.map(fontPipeExec);
return yield Promise.all(result);
});
}
exports.fontPipe = fontPipe;
16 changes: 8 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,22 @@ export async function parseCSS(dirPath = "src", url = targets.korean) {
}

// == Options - Basics =========================================================
interface FontDefaultOptionI {
export interface FontDefaultOptionI {
saveDir: string;
format: Format;
nameFormat: string;
logFormat: string;
defaultArgs: string[];
etcArgs: string[];
}
interface FontRangeOptionI extends FontDefaultOptionI {
export interface FontRangeOptionI extends FontDefaultOptionI {
fromCSS: "default" | "srcIndex" | "srcName";
}
interface FontSubsetOptionI extends FontDefaultOptionI {
export interface FontSubsetOptionI extends FontDefaultOptionI {
textFile: string;
text: string;
}
interface FontPipeOptionI extends FontRangeOptionI, FontSubsetOptionI {
export interface FontPipeOptionI extends FontRangeOptionI, FontSubsetOptionI {
cssFile: string;
}
type ArgOptionT<I> = FontDefaultOptionI["saveDir"] | Partial<I>;
Expand Down Expand Up @@ -414,7 +414,7 @@ export async function fontRange(fontPath = "", url = targets.korean, fontRangeOp
return result;
});

return Promise.all(result);
return await Promise.all(result);
}

export async function fontSubset(fontPath = "", fontSubsetOption?: FontSubsetOptionT) {
Expand All @@ -441,7 +441,7 @@ export async function fontSubset(fontPath = "", fontSubsetOption?: FontSubsetOpt
}

// == Pipeline =================================================================
interface FontPipeI {
export interface FontPipeI {
fontPath: string;
option?: FontPipeOptionT;
}
Expand Down Expand Up @@ -478,7 +478,7 @@ interface ShardI {
shardFormat: string;
}
type ShardT = ShardI["shard"] | Partial<ShardI>
export function fontPipe(subsetList: FontPipeI[], shard?: ShardT) {
export async function fontPipe(subsetList: FontPipeI[], shard?: ShardT) {
const shardEnv = (typeof shard === "object" && typeof shard.shard === "string")
? shard.shard
: (typeof shard === "object" || typeof shard === "undefined")
Expand All @@ -503,5 +503,5 @@ export function fontPipe(subsetList: FontPipeI[], shard?: ShardT) {
const result = subsetList
.slice(shardStart, shardEnd)
.map(fontPipeExec);
return Promise.all(result);
return await Promise.all(result);
}

0 comments on commit 8779366

Please sign in to comment.