Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite build process #14

Merged
merged 3 commits into from
Mar 13, 2023
Merged
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
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ SPDX-License-Identifier: BSD-2-Clause

This is a TypeScript library for processing Ansible documentation markup. It is named after [the Python package of the same name](https://github.com/ansible-community/antsibull-docs/).

## How to use this

### Node.js (CommonJS modules)

```js
const { parse, toHTML } = require('antsibull_docs');

function convert() {
return toHTML(parse(['First paragraph.', 'Second B(paragraph).']));
}
```

### Webpack (EcmaScript modules)

```ts
import { parse, toHTML } from 'antsibull_docs';

function convert(): string {
return toHTML(parse(['First paragraph.', 'Second B(paragraph).']));
}
```

## How to develop on this

After checking out the repository, run
Expand All @@ -26,13 +48,14 @@ to install all required node packages. Afterwards you can run
$ npm build
```

to build the package,
to build the package as both ESM and CJS,

```shell
$ npm build:watch
$ npm build:cjs:watch
$ npm build:esm:watch
```

to start a watch process which builds the package every time a file is modified,
to start a watch process which builds the package (as CJS or ESM) every time a file is modified,

```shell
$ npm test
Expand Down
2 changes: 2 additions & 0 deletions changelogs/fragments/14-module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- "Build both ESM and CommonJS modules for easier consumption in both webpack and node.js projects (https://github.com/ansible-community/antsibull-docs-ts/pull/14)."
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "antsibull_docs",
"version": "0.1.0",
"description": "TypeScript library for processing Ansible documentation markup",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
"files": [
".eslintrc.json",
".prettierignore",
Expand All @@ -20,16 +20,18 @@
"README.md"
],
"scripts": {
"build": "npx tsc",
"build:watch": "npx tsc -w",
"build": "npx tsc -p tsconfig-cjs.json && npx tsc -p tsconfig-esm.json",
"build:cjs": "npx tsc -p tsconfig-cjs.json",
"build:cjs:watch": "npx tsc -p tsconfig-cjs.json -w",
"build:esm": "npx tsc -p tsconfig-esm.json",
"build:esm:watch": "npx tsc -p tsconfig-esm.json -w",
"format:check": "npx prettier --check .",
"format:write": "npx prettier --write .",
"lint": "npx eslint \"src/**/*.ts\"",
"test": "npx jest",
"test:coverage": "npx jest --coverage",
"test:coverage:watch": "npx jest --coverage --watchAll",
"test:watch": "npx jest --watchAll",
"watch": "npx tsc -w"
"test:watch": "npx jest --watchAll"
},
"keywords": [
"ansible",
Expand Down
14 changes: 14 additions & 0 deletions tsconfig-cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Simplified BSD License (see LICENSES/BSD-2-Clause.txt or https://opensource.org/licenses/BSD-2-Clause)
SPDX-FileCopyrightText: Ansible Project
SPDX-License-Identifier: BSD-2-Clause
*/
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist/cjs",
"declaration": false,
"declarationMap": false
}
}
9 changes: 9 additions & 0 deletions tsconfig-esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
Simplified BSD License (see LICENSES/BSD-2-Clause.txt or https://opensource.org/licenses/BSD-2-Clause)
SPDX-FileCopyrightText: Ansible Project
SPDX-License-Identifier: BSD-2-Clause
*/
{
"extends": "./tsconfig.json",
"compilerOptions": {}
}
23 changes: 13 additions & 10 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
/*
Simplified BSD License (see LICENSES/BSD-2-Clause.txt or https://opensource.org/licenses/BSD-2-Clause)
SPDX-FileCopyrightText: Ansible Project
SPDX-License-Identifier: BSD-2-Clause
*/
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */

/* Language and Environment */
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
"target": "es2016",

/* Modules */
"module": "commonjs" /* Specify what module code is generated. */,
"rootDir": "src",
"module": "esnext",

/* Emit */
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "dist",
"outDir": "dist/esm",

/* Interop Constraints */
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,

/* Type Checking */
"strict": true,
Expand All @@ -32,16 +35,16 @@
"useUnknownInCatchVariables": true,
"alwaysStrict": true,
"noUnusedLocals": true,
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
"noUnusedParameters": true,
"exactOptionalPropertyTypes": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,

/* Completeness */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
"skipLibCheck": true
},
"include": ["src/**/*"],
"exclude": ["src/**/*.spec.ts"]
Expand Down
3 changes: 0 additions & 3 deletions tsconfig.json.license

This file was deleted.