Package Exports
- extra-build
Readme
Common build tools for extra-* packages.
📦 NPM,
📜 Files,
📰 Docs.
Stability: Experimental.
Why do packages need to be built? For TypeScript-based source
libraries (such as this) our main priority is to generate JavaScript file(s)
which can be imported from the runtime (Node.js), and publish them to a
package registry such as NPM. In addition we might like to generate
associated type declarations (.d.ts file), which is one of the reasons
behind choosing to write in TypeScript. We might also like to bundle all
scripts (and type declarations) into a single file to help reduce package size,
dependencies, or eliminate unused code.
Documentation plays a key role in reducing the amount of time spent on
Stack Overflow, and thus must be maintained at all costs. Instead of manually
updating it, most developers choose to generate this from documentation comments
in the code. An Index can be added to the README file that links to documention. Thus we have a new build step. In addition, we might like to update package metadata
(in package.json or GitHub repo), build source files for another platform
(such as the web), update package version automatically, generate wiki files
(for code examples), or publish to GitHub packages.
This package provides utility functions for all of these operations, and more.
The previous version of this package provided a CLI for all of these
operations, but was inflexible in its design (it could only be used when the
source code was arranged is a very specific way). This redesigned version
provides a JavaScipt API instead that allows for significant customization,
in addition to providing a number of helper functions commonly used in build
steps. Build steps can be written in a script file, say build.js, and executed
on a CI system such as GitHub Actions using .github/workflows/*.yml.
Behind the dial, these are the gears that make this package tick. TypeScript is
compiled with tsc, bundled with rollup, webified with browserify and
terser. Documentation is generated with typedoc, which is also used to
obtain DocsDetails in order to update index table in README using
extra-markdown-text, generate wiki files, and update package metadata locally
and on GitHub repo using @octokit/rest. Updating of package versions is
achieved with npm view and semver. To spice up the console with colors,
kleur is used.
The goals for the future include generating example file for RunKit, linking wiki from JsDoc, and duplicating example code from wiki to JsDoc. Did you find a bug? Or have a feature request?
const build = require('extra-build');
// 1. Set version and publish package.
var m = build.readMetadata('.');
// → {name, version, description, ...}
m.version = '2.0.0';
build.writeMetadata('.', m);
build.publish('.');
build.publishGithub('.', 'owner');
// 2. Publish next version, update github details.
var m = build.readMetadata('.');
var ver = build.nextUnpublishedVersion(m.name, m.version);
m.version = ver;
build.writeMetadata('.', m);
build.publish('.');
build.publishGithub('.', 'owner');
build.updateGithubRepoDetails();
// 3. Update keywords for package.
var m = build.readMetadata('.');
var p = build.loadDocs(['src/index.ts']);
var ds = p.children.map(build.docsDetails);
var s = new Set([...m.keywords, ...ds.map(d => d.name)]);
m.keywords = Array.from(s);
build.writeMetadata('.', m);
// 4. Restore package.json after publishing with updated version.
var _package = build.readDocument('package.json');
var m = build.readMetadata('.');
m.version = '2.0.0';
build.writeMetadata('.', m);
build.publish('.');
build.writeDocument(_package);
// 5. Update README index table.
var owner = 'owner', repo = 'repo';
var p = build.loadDocs(['src/index.ts']);
var ds = p.children.map(build.docsDetails);
var re = /namespace|function/i;
var dm = new Map(ds.map(d => [d.name, d]));
var txt = build.readFileText('README.md');
txt = build.wikiUpdateIndex(txt, dm, d => re.test(d.kind));
txt = build.wikiUpdateLinkReferences(txt, dm, {owner, repo});
build.writeFileText('README.md', txt);Index
| Property | Description |
|---|---|
| symbolname | Get symbol name for file. |
| keywordname | Get keyword name for file. |
| error | Print error message to stderr with newline. |
| warn | Print warning message to stderr with newline. |
| log | Print log message to stdout with newline. |
| info | Print info message to stdout with newline. |
| exec | Execute command with output, and print the command. |
| execStr | Execute command and get its output as string. |
| readFileText | Read file text with Unix EOL. |
| writeFileText | Write file text with system EOL. |
| readJson | Read JSON file as object. |
| writeJson | Write object to JSON file. |
| readDocument | Read document. |
| writeDocument | Write document. |
| gitCommitPush | Commit new changes and push to remote. |
| gitSetupBranch | Setup new branch and push to remote. |
| addBanner | Add banner (header comment) to script text. |
| bundleScript | Bundle a script file with config. |
| webifyScript | Webify an script file. |
| parseGithubUrl | Get details from GitHub URL. |
| updateGithubRepoDetails | Update GitHub repository details. |
| readMetadata | Read package.json data. |
| writeMetadata | Write package.json data. |
| registry | Get current registry. |
| setRegistry | Set current registry. |
| latestVersion | Get latest package version. |
| nextUnpublishedVersion | Get next unpublished version for package. |
| publishGithub | Publish package to GitHub. |
| generateDocs | Generate docs using typedoc. |
| publishDocs | Publish docs to gh-pages. |
| docsRefer | Get the reflection that is referred to. |
| docsName | Get name of a reflection. |
| docsLocation | Get location of reflection. |
| docsFlags | Get flags of a reflection. |
| docsKind | Get kind name of a reflection. |
| docsChildCount | Get child count of a reflection. |
| docsParameterCount | Get parameter count of a reflection (function). |
| docsSignatureCount | Get signature count of a reflection. |
| docsType | Get type name of a reflection. |
| docsDescription | Get description of a reflection. |
| docsReturns | Get returns description of a reflection (function). |
| docsDetails | Get details of a reflection. |
| docsReferDetails | Get details of a reflection, referring the necessary details. |
| loadDocs | Load docs from source file. |
| wikiCodeReference | Get reference code block for wiki. |
| wikiCodeExample | Get example code block for wiki. |
| wikiMarkdown | Get markdown text for wiki. |
| wikiUpdateIndex | Update the "Index" (property, description) table in markdown text. |
| wikiUpdateLinkReferences | Update link references in markdown text. |
| publish | Publish package to NPM. |
