Skip to content

Commit

Permalink
Use subpath exports and add build command (fixes #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyraxx committed Jul 18, 2024
1 parent 5ec7a27 commit dc146ff
Show file tree
Hide file tree
Showing 10 changed files with 468 additions and 61 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build TypeScript

on:
pull_request:
branches:
- main
push:
branches:
- main

permissions:
contents: read

jobs:
run-eslint:
name: Run TypeScript Build
runs-on: ubuntu-latest

steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4

- name: Setup Node.js
id: setup-node
uses: actions/setup-node@v4
with:
cache: npm
node-version: 22

- name: Install Dependencies
id: npm-ci
run: npm ci

- name: Run TypeScript Build
id: npm-build
run: npm run build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.DS_Store
tests/fixtures/public-testfiles
dist
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ Example usage in a Node.js environment:

```typescript
import * as fs from 'node:fs/promises';
import { Asset, JUMBF, Manifest, MalformedContentError } from 'c2pa-ts';
import { MalformedContentError } from 'c2pa-ts';
import { Asset, BMFF, JPEG, PNG } from 'c2pa-ts/asset';
import { SuperBox } from 'c2pa-ts/jumbf';
import { ManifestStore, ValidationResult, ValidationStatusCode } from 'c2pa-ts/manifest';

if (process.argv.length < 3) {
console.error('Missing filename');
Expand All @@ -72,13 +75,13 @@ if (process.argv.length < 3) {
const buf = await fs.readFile(process.argv[2]);

// Read the asset file and dump some information about its structure
let asset: Asset.Asset;
if (Asset.JPEG.canRead(buf)) {
asset = new Asset.JPEG(buf);
} else if (Asset.PNG.canRead(buf)) {
asset = new Asset.PNG(buf);
} else if (Asset.BMFF.canRead(buf)) {
asset = new Asset.BMFF(buf);
let asset: Asset;
if (JPEG.canRead(buf)) {
asset = new JPEG(buf);
} else if (PNG.canRead(buf)) {
asset = new PNG(buf);
} else if (BMFF.canRead(buf)) {
asset = new BMFF(buf);
} else {
console.error('Unknown file format');
process.exit(1);
Expand All @@ -89,26 +92,25 @@ console.log(asset.dumpInfo());
const jumbf = asset.getManifestJUMBF();

if (jumbf) {
let validationResult: Manifest.ValidationResult;
let validationResult: ValidationResult;

try {
// Deserialize the JUMBF box structure
const superBox = JUMBF.SuperBox.fromBuffer(jumbf);
const superBox = SuperBox.fromBuffer(jumbf);
console.log('JUMBF structure:');
console.log(superBox.toString());

// Read the manifest store from the JUMBF container
const manifests = Manifest.ManifestStore.read(superBox);
const manifests = ManifestStore.read(superBox);

// Validate the active manifest
validationResult = await manifests.validate(asset);

} catch (e) {
// Gracefully handle any exceptions to make sure we get a well-formed validation result
if (e instanceof MalformedContentError) {
validationResult = Manifest.ValidationResult.error(Manifest.ValidationStatusCode.GeneralError, e.message);
validationResult = ValidationResult.error(ValidationStatusCode.GeneralError, e.message);
} else {
validationResult = Manifest.ValidationResult.fromError(e as Error);
validationResult = ValidationResult.fromError(e as Error);
}
}

Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
import tseslint from 'typescript-eslint';

export default tseslint.config(
{ ignores: ['dist/*', 'eslint.config.js'] },
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
Expand Down
Loading

0 comments on commit dc146ff

Please sign in to comment.