Skip to content

Commit

Permalink
Merge pull request #32 from IIIF-Commons/feature/types
Browse files Browse the repository at this point in the history
Type changes
  • Loading branch information
stephenwf authored Jan 16, 2024
2 parents 2acd195 + dc85a42 commit c19f29f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 78 deletions.
57 changes: 21 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
"name": "@iiif/parser",
"version": "1.1.2",
"license": "MIT",
"description": "IIIF Presentation 2 and 3 parsing utilities",
"repository": {
"type": "git",
"url": "https://github.com/iiif-commons/parser"
},
"main": "dist/bundle/cjs/index.js",
"module": "dist/bundle/esm/index.mjs",
"types": "dist/index.d.ts",
Expand All @@ -11,60 +16,40 @@
"exports": {
".": {
"require": "./dist/bundle/cjs/index.js",
"import": "./dist/bundle/esm/index.mjs"
"import": "./dist/bundle/esm/index.mjs",
"types": "./dist/index.d.ts"
},
"./presentation-2": {
"require": "./dist/presentation-2/cjs/index.js",
"import": "./dist/presentation-2/esm/index.mjs"
"import": "./dist/presentation-2/esm/index.mjs",
"types": "./dist/presentation-2/index.d.ts"
},
"./presentation-3": {
"require": "./dist/bundle/cjs/index.js",
"import": "./dist/bundle/esm/index.mjs"
"import": "./dist/bundle/esm/index.mjs",
"types": "./dist/index.d.ts"
},
"./strict": {
"require": "./dist/strict/cjs/index.js",
"import": "./dist/strict/esm/index.mjs"
"import": "./dist/strict/esm/index.mjs",
"types": "./dist/strict/index.d.ts"
},
"./image-3": {
"require": "./dist/image-3/cjs/index.js",
"import": "./dist/image-3/esm/index.mjs"
},
"./upgrader": "./dist/upgrader/index.umd.js",
"./dist/presentation-2/index.d.ts": {
"import": "./dist/presentation-2/index.d.ts"
},
"./dist/index.d.ts": {
"import": "./dist/index.d.ts"
},
"./dist/upgrader/index.d.ts": {
"import": "./dist/upgrader/index.d.ts"
},
"./dist/strict/index.d.ts": {
"import": "./dist/strict/index.d.ts"
"import": "./dist/image-3/esm/index.mjs",
"types": "./dist/image-3/index.d.ts"
},
"./dist/image-3/index.d.ts": {
"import": "./dist/image-3/index.d.ts"
"./upgrader": {
"require": "./dist/upgrader/index.umd.js",
"import": "./dist/upgrader/index.umd.js",
"types": "./dist/upgrader/index.d.ts"
}
},
"typesVersions": {
"*": {
"*": [
"dist/index.d.ts"
],
"presentation-2": [
"dist/presentation-2/index.d.ts"
],
"presentation-3": [
"dist/index.d.ts"
],
"upgrader": [
"dist/upgrader/index.d.ts"
],
"strict": [
"dist/strict/index.d.ts"
],
"image-3": [
"dist/image-3/index.d.ts"
"./dist/*",
"./*"
]
}
},
Expand Down
29 changes: 19 additions & 10 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { defineConfig } from './base-config.mjs';
import { build } from 'vite';
import chalk from 'chalk';
import { execa } from "execa";
import { execa } from 'execa';

(async () => {

const DIST = 'dist';

// Main UMD build.
Expand Down Expand Up @@ -43,7 +42,7 @@ import { execa } from "execa";
name: 'index',
outDir: `${DIST}/strict`,
})
)
);
buildMsg('@iiif/parser/image-3');
await build(
defineConfig({
Expand All @@ -66,21 +65,31 @@ import { execa } from "execa";
buildMsg('Types');

listItem('@iiif/parser');
await execa('./node_modules/.bin/dts-bundle-generator', [`--out-file=${DIST}/index.d.ts`, './src/index.ts'])
await execa('./node_modules/.bin/dts-bundle-generator', [`--out-file=${DIST}/index.d.ts`, './src/index.ts']);

listItem('@iiif/parser/presentation-2');
await execa('./node_modules/.bin/dts-bundle-generator', [`--out-file=${DIST}/presentation-2/index.d.ts`, './src/presentation-2/index.ts'])
await execa('./node_modules/.bin/dts-bundle-generator', [
`--out-file=${DIST}/presentation-2/index.d.ts`,
'./src/presentation-2/index.ts',
]);

listItem('@iiif/parser/strict');
await execa('./node_modules/.bin/dts-bundle-generator', [`--out-file=${DIST}/strict/index.d.ts`, './src/presentation-3/strict-upgrade.ts'])
await execa('./node_modules/.bin/dts-bundle-generator', [
`--out-file=${DIST}/strict/index.d.ts`,
'./src/presentation-3/strict-upgrade.ts',
]);

listItem('@iiif/parser/upgrader');
await execa('./node_modules/.bin/dts-bundle-generator', [`--out-file=${DIST}/upgrader/index.d.ts`, './src/upgrader.ts'])
await execa('./node_modules/.bin/dts-bundle-generator', [
`--out-file=${DIST}/upgrader/index.d.ts`,
'./src/upgrader.ts',
]);

listItem('@iiif/parser/image-3');
await execa('./node_modules/.bin/dts-bundle-generator', [`--out-file=${DIST}/image-3/index.d.ts`, './src/image-3/index.ts'])


await execa('./node_modules/.bin/dts-bundle-generator', [
`--out-file=${DIST}/image-3/index.d.ts`,
'./src/image-3/index.ts',
]);

function buildMsg(name) {
console.log(chalk.grey(`\n\nBuilding ${chalk.blue(name)}\n`));
Expand Down
66 changes: 34 additions & 32 deletions scripts/validate.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { promises as FS } from "node:fs";
import chalk from "chalk";
import { promises as FS } from 'node:fs';
import chalk from 'chalk';

const pkgJson = await FS.readFile(`./package.json`);
const pkg = JSON.parse(pkgJson.toString());
Expand All @@ -8,11 +8,13 @@ let _indent = 2;
let _indentBy = 4;

function logWithIndent(msg) {
console.log(chalk.gray(`${new Array(_indent + 1).fill("").join(" ")}${msg}`));
console.log(chalk.gray(`${new Array(_indent + 1).fill('').join(' ')}${msg}`));
}

async function checkFile(file, description) {
logWithIndent(`${description ? `"${chalk.cyanBright(description)}": ` : ''}${chalk.blue(`"${file}"`)} ${chalk.green(`✓`)} exists`);
logWithIndent(
`${description ? `"${chalk.cyanBright(description)}": ` : ''}${chalk.blue(`"${file}"`)} ${chalk.green(`✓`)} exists`
);
await FS.stat(file);
}

Expand All @@ -25,21 +27,23 @@ function dedent(arr = false) {
logWithIndent(arr ? ']' : '}');
}

console.log(chalk.gray(`
console.log(
chalk.gray(`
Validating ${chalk.blue(`package.json`)}
`))
`)
);

logWithIndent(`{`);

await checkFile(pkg.main, "main");
await checkFile(pkg.module, "module");
await checkFile(pkg.types, "types");
await checkFile(pkg.main, 'main');
await checkFile(pkg.module, 'module');
await checkFile(pkg.types, 'types');

const exportKeys = Object.keys(pkg.exports);
logWithIndent(`"exports": {`);
indent();
for (const exportKey of exportKeys) {
if (typeof pkg.exports[exportKey] === "string") {
if (typeof pkg.exports[exportKey] === 'string') {
await checkFile(pkg.exports[exportKey], exportKey);
continue;
}
Expand All @@ -53,26 +57,24 @@ for (const exportKey of exportKeys) {
}
dedent();

// const typesVersionKeys = Object.keys(pkg.typesVersions);
// logWithIndent(`"typesVersions": {`);
// indent();
// for (const typesVersionKey of typesVersionKeys) {
// const variations = Object.keys(pkg.typesVersions[typesVersionKey]);
// logWithIndent(`"${typesVersionKey}": {`);
// indent();
// for (const variation of variations) {
// const listOfTypes = pkg.typesVersions[typesVersionKey][variation];
// logWithIndent(`"${variation}": [`);
// indent();
// for (const pathToTypescriptFile of listOfTypes) {
// await checkFile(pathToTypescriptFile);
// }
// dedent(true);
// }
// dedent();
// }
// dedent();

const typesVersionKeys = Object.keys(pkg.typesVersions);
logWithIndent(`"typesVersions": {`);
indent();
for (const typesVersionKey of typesVersionKeys) {
const variations = Object.keys(pkg.typesVersions[typesVersionKey]);
logWithIndent(`"${typesVersionKey}": {`);
indent();
for (const variation of variations) {
const listOfTypes = pkg.typesVersions[typesVersionKey][variation];
logWithIndent(`"${variation}": [`);
indent();
for (const pathToTypescriptFile of listOfTypes) {
await checkFile(pathToTypescriptFile);
}
dedent(true);
}
dedent();
}
dedent();

console.log(chalk.greenBright(`\n\n ✓ package.json is valid`));

console.log(chalk.greenBright(`\n\n ✓ package.json is valid `));

0 comments on commit c19f29f

Please sign in to comment.