Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/main.js
*.swp
/.idea
/src/manifests
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"scripts": {
"build": "npm run clean && npm run build:types",
"build:types": "tsc --noEmit",
"build:update-manifest-paths": "node scripts/update-manifests-dist-path.js",
"build:manifests-to-ts": "node scripts/manifests-to-ts.js",
"clean": "node -e \"fs.rmSync('./dist', {force: true, recursive: true})\"",
"format": "prettier --write \"./src/**/*.ts\" \"./manifests/**/*.json\"",
"generate-schema": "node scripts/generate-schema.js",
"prepare": "tshy && npm run build:update-manifest-paths",
"prepare": "npm run build:manifests-to-ts && tshy",
"test:validate": "node scripts/validate-modules.js",
"sort-manifests": "node scripts/sort-manifests.js"
},
Expand Down
30 changes: 30 additions & 0 deletions scripts/manifests-to-ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {mkdir, readFile, readdir, rm, writeFile} from 'node:fs/promises';
import {fileURLToPath} from 'node:url';
import {existsSync} from 'node:fs';
import * as path from 'node:path';

const scriptDir = fileURLToPath(new URL('.', import.meta.url));
const tsManifestsPath = path.resolve(scriptDir, '../src/manifests');
const jsonManifestsPath = path.resolve(scriptDir, '../manifests');

if (existsSync(tsManifestsPath)) {
await rm(tsManifestsPath, {recursive: true});
}

await mkdir(tsManifestsPath, {recursive: true});

const manifests = await readdir(jsonManifestsPath, {withFileTypes: true});

for (const manifest of manifests) {
if (manifest.isFile() && path.extname(manifest.name) === '.json') {
const content = await readFile(
path.join(jsonManifestsPath, manifest.name),
'utf8'
);

await writeFile(
path.join(tsManifestsPath, manifest.name.replace(/\.json$/, '.ts')),
`import {ManifestModule} from '../types.js';\n\nconst manifest: ManifestModule = ${content.trim()};\nexport default manifest;\n`
);
}
}
16 changes: 0 additions & 16 deletions scripts/update-manifests-dist-path.js

This file was deleted.

14 changes: 3 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import {readFileSync} from 'node:fs';
import {ManifestModule} from './types.js';
import {manifestsDir} from './manifests-dir.js';

const nativeReplacements = JSON.parse(
readFileSync(`${manifestsDir}/native.json`, 'utf8')
) as ManifestModule;
const microUtilsReplacements = JSON.parse(
readFileSync(`${manifestsDir}/micro-utilities.json`, 'utf8')
) as ManifestModule;
const preferredReplacements = JSON.parse(
readFileSync(`${manifestsDir}/preferred.json`, 'utf8')
) as ManifestModule;
import microUtilsReplacements from './manifests/micro-utilities.js';
import preferredReplacements from './manifests/preferred.js';
import nativeReplacements from './manifests/native.js';

export * from './types.js';

Expand Down
4 changes: 0 additions & 4 deletions src/manifests-dir-cjs.cts

This file was deleted.

6 changes: 0 additions & 6 deletions src/manifests-dir.ts

This file was deleted.