Skip to content

Commit

Permalink
Merge pull request #4 from kontheocharis/bug-fixes
Browse files Browse the repository at this point in the history
Add some bug fixes and improvements to the API
  • Loading branch information
kontheocharis authored Aug 6, 2023
2 parents 475cd25 + 7bd9b6f commit f520f81
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
8 changes: 5 additions & 3 deletions api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export interface CommonApi {
/**
* Read the contents of the given file.
*/
read: (filename: string) => Promise<Output>;
read: (filename: string) => Promise<string>;
}

/**
Expand Down Expand Up @@ -197,15 +197,17 @@ export interface GlobalConfig {
/**
* Make a powar-ts module.
*/
export function module<T>(m: (vars: T) => Module): (vars: T) => Module {
export function module<T = undefined>(
m: T extends undefined ? () => Module : (vars: T) => Module
): typeof m {
return m;
}

/**
* Produce some object `U` determined by some module variables `T` and the powar-ts module API.
*/
export function produce<T, U>(
m: (vars: T, p: ModuleApi) => U,
m: (vars: T, p: ModuleApi) => U
): (vars: T, p: ModuleApi) => U {
return m;
}
8 changes: 4 additions & 4 deletions api_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function makeCommonApi({
await ensureParentExists(dest);
// Ensure to fully resolve the source path, so that the link is not
// relative.
await exec(`ln -sf "$(realpath '${src}')" "${dest}"`);
await exec(`ln -sf "$(realpath ${src})" "${dest}"`);
});
}

Expand All @@ -80,8 +80,8 @@ export function makeCommonApi({
});
}

async function read(filename: string): Promise<Output> {
return await exec(`cat "${filename}"`);
async function read(filename: string): Promise<string> {
return (await exec(`cat "${filename}"`)).stdoutAsString();
}

return {
Expand All @@ -101,7 +101,7 @@ export function makeCommonApi({
*/
async function iterateEntries(
entries: [string, string | string[]][],
fn: (src: string, dest: string) => Promise<void>,
fn: (src: string, dest: string) => Promise<void>
): Promise<void> {
for (const [src, d] of entries) {
const destinations = Array.isArray(d) ? d : [d];
Expand Down
12 changes: 11 additions & 1 deletion deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 9 additions & 11 deletions run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,15 @@ function ensureDepsAreMet(ctx: Ctx): void {
*/
async function performModuleActions(ctx: Ctx): Promise<void> {
const { log, settings } = ctx;
await Promise.all(
getRequestedModules(ctx).map(async (module) => {
log.info(`Running ${module.name}...`);
const api = makeCommonApi({
log: makeLogger(settings.logLevel, 1),
path: module.path,
settings,
});
await module.action(api);
})
);
for (const module of getRequestedModules(ctx)) {
log.info(`Running ${module.name}...`);
const api = makeCommonApi({
log: makeLogger(settings.logLevel, 1),
path: module.path,
settings,
});
await module.action(api);
}
}

/**
Expand Down

0 comments on commit f520f81

Please sign in to comment.