Skip to content

Commit

Permalink
fix: add info.json to migration
Browse files Browse the repository at this point in the history
  • Loading branch information
cecilia-sanare committed Jun 27, 2024
1 parent 77cb1cf commit 917f29e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ const DIST_DIR = join(import.meta.dirname, '../dist');
async function generate() {
const apps = await getApps();
const list = await getAppsList(apps);
const info = getInfo();

await Promise.all([
migrate({
list,
apps,
info,
}),
generateSchema(),
generateAppsListFile(list),
generateInfoFile(getInfo()),
generateInfoFile(info),
]);

await mkdir(DIST_DIR, {
Expand Down
21 changes: 15 additions & 6 deletions src/migrations/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join } from 'path';
import { writeFile, mkdir } from 'fs/promises';
import type { AppsList, App, V1, V2, V3, V4 } from '../types';
import type { AppsList, App, Info, V1, V2, V3, V4 } from '../types';
import { APPS_DIR } from '../utils/apps';
import * as v1 from './v1';
import * as v2 from './v2';
Expand All @@ -11,15 +11,16 @@ export type Migrations = {
v1: Migration<V1.Tweaks, V1.Tweak>;
v2: Migration<V2.Tweaks, V2.Tweak>;
v3: Migration<V3.AppsList, V3.App>;
v4: Migration<V4.AppsList, V4.App>;
v4: Migration<V4.AppsList, V4.App, V4.Info>;
};

export type Migration<L, T> = {
export type Migration<L, T, I = undefined> = {
list: L;
apps: T[];
info: I;
};

export async function migrate(initial: Migration<AppsList, App>) {
export async function migrate(initial: Migration<AppsList, App, Info>) {
const v4Apps = await v4.migrate(initial);
const v3Apps = await v3.migrate(v4Apps);
const v2Apps = await v2.migrate(v3Apps);
Expand All @@ -46,12 +47,20 @@ export async function migrate(initial: Migration<AppsList, App>) {
recursive: true,
});

await Promise.all([
const promises = [
writeFile(join(VERSIONED_APPS_DIR, appsFileName), JSON.stringify(migration.list, null, 2), 'utf-8'),
...migration.apps.map(async (app) => {
await writeFile(join(VERSIONED_APPS_DIR, `${app.id}.json`), JSON.stringify(app, null, 2), 'utf-8');
}),
]);
];

if (migration.info) {
promises.push(
writeFile(join(VERSIONED_APPS_DIR, 'info.json'), JSON.stringify(migration.info, null, 2), 'utf-8')
);
}

await Promise.all(promises);
})
);
}
5 changes: 4 additions & 1 deletion src/migrations/v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import type { V4, V3 } from '../types';
/**
* Removed fsync and esync options as they're redundant when environment variables are available.
*/
export async function migrate({ list, apps }: Migration<V4.AppsList, V4.App>): Promise<Migration<V3.AppsList, V3.App>> {
export async function migrate({
list,
apps,
}: Migration<V4.AppsList, V4.App, V4.Info>): Promise<Migration<V3.AppsList, V3.App>> {
return {
list,
apps: apps.map((app) => {
Expand Down
9 changes: 7 additions & 2 deletions src/migrations/v4.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import type { Migration } from '.';
import type { App, AppsList, V4 } from '../types';
import type { App, AppsList, Info, V4 } from '../types';

/**
* TODO: Map these back to V4 once a breaking change occurs
*/
export async function migrate({ list, apps }: Migration<AppsList, App>): Promise<Migration<V4.AppsList, V4.App>> {
export async function migrate({
list,
apps,
info,
}: Migration<AppsList, App, Info>): Promise<Migration<V4.AppsList, V4.App, V4.Info>> {
return {
list,
apps,
info,
};
}
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import * as V4 from './v4';

export type AppsList = V4.AppsList;
export type App = V4.App;
export type Info = V4.Info;

export { V4 };
2 changes: 1 addition & 1 deletion src/utils/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function getAppFiles(includeTemplate: boolean = false): Promise<str
(file) =>
file.endsWith('.json') &&
(!file.startsWith('.') || includeTemplate) &&
!['apps.json', 'schema.json'].includes(file)
!['apps.json', 'info.json', 'schema.json'].includes(file)
);
}

Expand Down

0 comments on commit 917f29e

Please sign in to comment.