Skip to content

Commit

Permalink
HookModule: pass along resource root dir
Browse files Browse the repository at this point in the history
  • Loading branch information
city41 committed Jul 25, 2024
1 parent b21c774 commit 9f70662
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
18 changes: 12 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import type { Palette16Bit } from './api/palette/types';
export type { CodeEmitData };

const dummyHook: Required<HookModule> = {
init() {
init(_rootDir) {
return Promise.resolve();
},
overrideInputData(input) {
overrideInputData(_rootDir, input) {
return Promise.resolve(input);
},
overrideEmitData(emitData) {
overrideEmitData(_rootDir, emitData) {
return Promise.resolve(emitData);
},
};
Expand Down Expand Up @@ -49,10 +49,13 @@ async function main(options: OptionValues) {
...inputHookModule,
};

await hookModule.init();
await hookModule.init(rootDir);
}

const resourceJson = await hookModule.overrideInputData(inputResourceJson);
const resourceJson = await hookModule.overrideInputData(
rootDir,
inputResourceJson
);

if (!validateInputJson(resourceJson)) {
console.error('After hook.overrideInputData, the input is no longer valid');
Expand Down Expand Up @@ -87,7 +90,10 @@ async function main(options: OptionValues) {
palettes: finalPalettes,
};

const codeEmitData = await hookModule.overrideEmitData(preCodeEmitData);
const codeEmitData = await hookModule.overrideEmitData(
rootDir,
preCodeEmitData
);

emit(rootDir, resourceJson.codeEmit, codeEmitData).then(
(codeEmitFilesToWrite) => {
Expand Down
12 changes: 9 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,13 @@ export const JsonInput = t.intersection([
export type JsonInput = t.TypeOf<typeof JsonInput>;

export type HookModule = {
init?: () => Promise<void>;
overrideInputData?: (input: JsonInput) => Promise<JsonInput>;
overrideEmitData?: (emitData: CodeEmitData) => Promise<CodeEmitData & any>;
init?: (resourceRootDir: string) => Promise<void>;
overrideInputData?: (
resourceRootDir: string,
input: JsonInput
) => Promise<JsonInput>;
overrideEmitData?: (
resourceRootDir: string,
emitData: CodeEmitData
) => Promise<CodeEmitData & any>;
};
12 changes: 6 additions & 6 deletions testData/testHook.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const hook = {
init() {
console.log('test hook init');
init(rootDir) {
console.log('test hook init', rootDir);
return Promise.resolve();
},
overrideInputData(input) {
console.log('test hook overrideInputData');
overrideInputData(rootDir, input) {
console.log('test hook overrideInputData', rootDir);
console.log(input);
return Promise.resolve(input);
},
overrideEmitData(emitData) {
console.log('test hook overrideEmit');
overrideEmitData(rootDir, emitData) {
console.log('test hook overrideEmit', rootDir);
console.log(emitData);
return Promise.resolve(emitData);
},
Expand Down

0 comments on commit 9f70662

Please sign in to comment.