Skip to content

Commit

Permalink
Merge pull request #161 from Eyas/format-md
Browse files Browse the repository at this point in the history
Format Markdown
  • Loading branch information
Eyas authored Jul 13, 2021
2 parents a463849 + c5d6cdc commit ae4dbc2
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 48 deletions.
9 changes: 9 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules/
built
dist/gen/*
dist/schema/*
!dist/schema/package.json
!dist/schema/README.md
.nyc_output/
coverage/
.github/
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"proseWrap": "always",
"singleQuote": true,
"bracketSpacing": false,
"arrowParens": "avoid"
}
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "node"
- 'node'
after_success: npm run coverage_on_travis
git:
depth: 1
2 changes: 1 addition & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Schema DTS and the Schema TypeScript Generator are maintained by:

* [Eyas Sharaiha](https://eyas.sh/)
- [Eyas Sharaiha](https://eyas.sh/)
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ information on using pull requests.

## Community Guidelines

This project follows [Google's Open Source Community
Guidelines](https://opensource.google.com/conduct/).
This project follows
[Google's Open Source Community Guidelines](https://opensource.google.com/conduct/).
59 changes: 39 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ completions and stricter validation.

This repository contains two NPM packages:

- **[schema-dts-gen](https://www.npmjs.com/package/schema-dts-gen)** Providing
a command-line tool to generate TypeScript files based on a specific Schema
- **[schema-dts-gen](https://www.npmjs.com/package/schema-dts-gen)** Providing a
command-line tool to generate TypeScript files based on a specific Schema
version and layer.
- **[schema-dts](https://www.npmjs.com/package/schema-dts)** Pre-packaged
TypeScript typings of latest Schema.org schema, without
Expand All @@ -31,13 +31,17 @@ To use the typings for your project, simply add the
[`schema-dts`](https://www.npmjs.com/package/schema-dts) NPM package to your
project:

npm install schema-dts
```command
npm install schema-dts
```

Then you can use it by importing `"schema-dts"`.

### Root context

You will usually want your top-level item to include a `@context`, like `https://schema.org`. In order for your object type to accept this property, you can augment it with `WithContext`, e.g.:
You will usually want your top-level item to include a `@context`, like
`https://schema.org`. In order for your object type to accept this property, you
can augment it with `WithContext`, e.g.:

```ts
import {Person, WithContext} from 'schema-dts';
Expand All @@ -55,14 +59,23 @@ const p: WithContext<Person> = {

### Graphs and IDs

JSON-LD supports `'@graph'` objects that have richer interconnected links between the nodes. You can do that easily in `schema-dts` by using the `Graph` type.
JSON-LD supports `'@graph'` objects that have richer interconnected links
between the nodes. You can do that easily in `schema-dts` by using the `Graph`
type.

Notice that any node can have an `@id` when defining it. And you can reference the same node from different places by simply using an ID stub, for example `{ '@id': 'https://my.site/about/#page }` below is an ID stub.
Notice that any node can have an `@id` when defining it. And you can reference
the same node from different places by simply using an ID stub, for example
`{ '@id': 'https://my.site/about/#page }` below is an ID stub.

The example below shows potential JSON-LD for an About page. It includes definitions of Alyssa P. Hacker (the author & subject of the page), the specific page in this URL, and the website it belongs to. Some objects are still defined as inline nested objects (e.g. Occupation), since they are only referenced by their parent. Other objects are defined at the top-level with an `@id`, because multiple nodes refer to them.
The example below shows potential JSON-LD for an About page. It includes
definitions of Alyssa P. Hacker (the author & subject of the page), the specific
page in this URL, and the website it belongs to. Some objects are still defined
as inline nested objects (e.g. Occupation), since they are only referenced by
their parent. Other objects are defined at the top-level with an `@id`, because
multiple nodes refer to them.

```ts
import { Graph } from 'schema-dts';
import {Graph} from 'schema-dts';

const graph: Graph = {
'@context': 'https://schema.org',
Expand All @@ -74,10 +87,10 @@ const graph: Graph = {
hasOccupation: {
'@type': 'Occupation',
name: 'LISP Hacker',
qualifications: 'Knows LISP'
qualifications: 'Knows LISP',
},
mainEntityOfPage: { '@id': 'https://my.site/about/#page' },
subjectOf: { '@id': 'https://my.site/about/#page' }
mainEntityOfPage: {'@id': 'https://my.site/about/#page'},
subjectOf: {'@id': 'https://my.site/about/#page'},
},
{
'@type': 'AboutPage',
Expand All @@ -86,7 +99,7 @@ const graph: Graph = {
name: "Alyssa P. Hacker's Website",
inLanguage: 'en-US',
description: 'The personal website of LISP legend Alyssa P. Hacker',
mainEntity: { '@id': 'https://my.site/#alyssa' }
mainEntity: {'@id': 'https://my.site/#alyssa'},
},
{
'@type': 'WebPage',
Expand All @@ -95,12 +108,12 @@ const graph: Graph = {
name: "About | Alyssa P. Hacker's Website",
inLanguage: 'en-US',
isPartOf: {
'@id': 'https://my.site/#site'
'@id': 'https://my.site/#site',
},
about: { '@id': 'https://my.site/#alyssa' },
mainEntity: { '@id': 'https://my.site/#alyssa' }
}
]
about: {'@id': 'https://my.site/#alyssa'},
mainEntity: {'@id': 'https://my.site/#alyssa'},
},
],
};
```

Expand Down Expand Up @@ -141,17 +154,23 @@ Command line usage:

Use NPM to install dependencies:

npm install
```command
npm install
```

We have wrappers around `tsc` and `tsc --build` to build our generator other
.d.ts files.

To generate TypeScript from the latest Schema.org Schema:

npm run build-gen && npm run build-schema
```command
npm run build-gen && npm run build-schema
```

or simply build the schema-dts generator:

npm run build-gen
```command
npm run build-gen
```

To contribute changes, see [the CONTRIBUTING.md file](./CONTRIBUTING.md).
39 changes: 25 additions & 14 deletions dist/schema/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ Note: This is not an officially supported Google product.
To use the typings for your project, simply add the `schema-dts` NPM package to
your project:

npm install schema-dts
```command
npm install schema-dts
```

Then you can use it by importing `"schema-dts"`.

Expand Down Expand Up @@ -69,14 +71,23 @@ export const MY_ORG = JsonLd<Organization>({

### Graphs and IDs

JSON-LD supports `'@graph'` objects that have richer interconnected links between the nodes. You can do that easily in `schema-dts` by using the `Graph` type.
JSON-LD supports `'@graph'` objects that have richer interconnected links
between the nodes. You can do that easily in `schema-dts` by using the `Graph`
type.

Notice that any node can have an `@id` when defining it. And you can reference the same node from different places by simply using an ID stub, for example `{ '@id': 'https://my.site/about/#page }` below is an ID stub.
Notice that any node can have an `@id` when defining it. And you can reference
the same node from different places by simply using an ID stub, for example
`{ '@id': 'https://my.site/about/#page }` below is an ID stub.

The example below shows potential JSON-LD for an About page. It includes definitions of Alyssa P. Hacker (the author & subject of the page), the specific page in this URL, and the website it belongs to. Some objects are still defined as inline nested objects (e.g. Occupation), since they are only referenced by their parent. Other objects are defined at the top-level with an `@id`, because multiple nodes refer to them.
The example below shows potential JSON-LD for an About page. It includes
definitions of Alyssa P. Hacker (the author & subject of the page), the specific
page in this URL, and the website it belongs to. Some objects are still defined
as inline nested objects (e.g. Occupation), since they are only referenced by
their parent. Other objects are defined at the top-level with an `@id`, because
multiple nodes refer to them.

```ts
import { Graph } from 'schema-dts';
import {Graph} from 'schema-dts';

const graph: Graph = {
'@context': 'https://schema.org',
Expand All @@ -88,10 +99,10 @@ const graph: Graph = {
hasOccupation: {
'@type': 'Occupation',
name: 'LISP Hacker',
qualifications: 'Knows LISP'
qualifications: 'Knows LISP',
},
mainEntityOfPage: { '@id': 'https://my.site/about/#page' },
subjectOf: { '@id': 'https://my.site/about/#page' }
mainEntityOfPage: {'@id': 'https://my.site/about/#page'},
subjectOf: {'@id': 'https://my.site/about/#page'},
},
{
'@type': 'AboutPage',
Expand All @@ -100,7 +111,7 @@ const graph: Graph = {
name: "Alyssa P. Hacker's Website",
inLanguage: 'en-US',
description: 'The personal website of LISP legend Alyssa P. Hacker',
mainEntity: { '@id': 'https://my.site/#alyssa' }
mainEntity: {'@id': 'https://my.site/#alyssa'},
},
{
'@type': 'WebPage',
Expand All @@ -109,11 +120,11 @@ const graph: Graph = {
name: "About | Alyssa P. Hacker's Website",
inLanguage: 'en-US',
isPartOf: {
'@id': 'https://my.site/#site'
'@id': 'https://my.site/#site',
},
about: { '@id': 'https://my.site/#alyssa' },
mainEntity: { '@id': 'https://my.site/#alyssa' }
}
]
about: {'@id': 'https://my.site/#alyssa'},
mainEntity: {'@id': 'https://my.site/#alyssa'},
},
],
};
```
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ module.exports = {
testMatch: ['**/*_test.[jt]s?(x)'],
testPathIgnorePatterns: ['/node_modules/', '/built/', '/dist/'],
collectCoverage: true,
coveragePathIgnorePatterns: ['/node_modules/', '/built/', '/dist/']
};
coveragePathIgnorePatterns: ['/node_modules/', '/built/', '/dist/'],
};
9 changes: 2 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@
],
"all": true
},
"prettier": {
"singleQuote": true,
"bracketSpacing": false,
"arrowParens": "avoid"
},
"keywords": [
"typescript",
"tsd",
Expand All @@ -98,8 +93,8 @@
"license": "Apache-2.0",
"scripts": {
"clean": "del-cli built dist/gen dist/schema/**/* !dist/schema/package.json !dist/schema/README.md",
"lint": "eslint src/**/*.ts test/**/*.ts && prettier --check \"src/**/*.ts\" && prettier --check \"test/**/*.ts\"",
"fix": "eslint --fix src/**/*.ts test/**/*.ts && prettier --write \"src/**/*.ts\" && prettier --write \"test/**/*.ts\"",
"lint": "eslint src/**/*.ts test/**/*.ts && prettier --check .",
"fix": "eslint --fix src/**/*.ts test/**/*.ts && prettier --write .",
"test": "npm run lint && jest --coverage",
"coverage_on_travis": "cat ./coverage/lcov.info | coveralls",
"build": "tsc -b",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"compilerOptions": {
"outDir": "./built"
}
}
}

0 comments on commit ae4dbc2

Please sign in to comment.