Installations
npm install extra-build
Developer Guide
Typescript
Yes
Module System
CommonJS, ESM
Node Version
22.9.0
NPM Version
10.8.3
Score
63.5
Supply Chain
87.8
Quality
79
Maintenance
50
Vulnerability
97.3
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (86.1%)
JavaScript (13.9%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
158,123
Last Day
93
Last Week
143
Last Month
1,137
Last Year
13,889
GitHub Statistics
MIT License
1 Stars
490 Commits
3 Watchers
3 Branches
1 Contributors
Updated on Sep 29, 2024
Bundle Size
140.16 kB
Minified
32.10 kB
Minified + Gzipped
Package Meta Information
Latest Version
2.3.0
Package Id
extra-build@2.3.0
Unpacked Size
81.18 kB
Size
20.14 kB
File Count
6
NPM Version
10.8.3
Node Version
22.9.0
Published on
Sep 29, 2024
Total Downloads
Cumulative downloads
Total Downloads
158,123
Last Day
9,200%
93
Compared to previous day
Last Week
-49.8%
143
Compared to previous week
Last Month
23.1%
1,137
Compared to previous month
Last Year
-46%
13,889
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Common build tools for extra-* packages.
📦 Node.js,
📜 Files,
📰 Docs.
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
.
Standalone symbol name of a package, such as @package/submodule
, can be
obtained with symbolname (i.e., package_submodule
). This is necessary when
webifying (making it accessible with a script
tag) a package. Keyword
name for an identifier can be procured with keywordname, which can then be
used to set the keywords of a package in the metadata file package.json
.
Logging of error, warning, log, and info messages with colors is
provided with error, warn, log, and info respectively. A shell command
can be executed (displaying the command and its output) with exec. The
output of a command can be obtained as a string
with execStr.
Reading/writing of text/JSON files is possible with convenience methods
readFileText, writeFileText, readJson, and writeJson. To save the
status and contents of a file (without having to do any existence check)
is possible with readDocument and writeDocument. They are useful when it is
required to update a file temporarily and restore it later (if it exists, or
remove if it did not exist).
Helper git
commands for commit+push, and setting up a new branch and
pushing to remote (for gh-pages
) is available as gitCommitPush and
gitSetupBranch. A JavaScript file can be bundled (to a single file) with
bundleScript, and webified (for access on the web) with webifyScript. A
banner can be added to the generated script with addBanner. To parse a
GitHub URL (for example from the repository.url
field in package.json
)
parseGithubUrl can be used. GitHub repository details can be updated (by
default from package.json
) with updateGithubRepoDetails.
The metadata file of a package (package.json
) can be read/written with
readMetadata and writeMetadata respectively. The current registry being
used for publishing to NPM (in .npmrc
file) can be obtained with registry,
and modified with setRegistry. The latest version of a package can be
obtained with latestVersion, and the next unpublished version (based on the
latest package version, and the version
mentioned in package.json
) can be
obtained with nextUnpublishedVersion.
JsDoc for a package can be generated with generateDocs, and published
with publishDocs. Reflection information of docs can be obtained from
the source file (through typedoc
) with loadDocs. This can then used to
obtain detailed information on exported symbols using docsName,
docsLocation, docsFlags, docsKind, docsChildCount, docsParameterCount,
docsSignatureCount, docsType, docsDescription, and docsReturns. For
reference symbols, the referred to symbol (which has all the type
information) can be obtained with docsRefer. Simplified details of a
reflection (symbol) can be obtained with docsDetails and docsReferDetails
(get details of referred to symbol).
Reference code block for wiki
can be generated with wikiCodeReference,
example code block can be generated with wikiCodeExample, and full
markdown text can be generated with wikiMarkdown. The "Index" table of
wiki
or README.md
can be updated (using simplified details of exported
symbols) with wikiUpdateIndex, and link references (named links in
markdown) can be updated with wikiUpdateLinkReferences. Finally a package can
be published to NPM with publish, and to GitHub with publishGithub.
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?
Stability: Experimental.
1const xbuild = require('extra-build'); 2 3 4// 1. Set version and publish package. 5var m = xbuild.readMetadata('.'); 6// → {name, version, description, ...} 7m.version = '2.0.0'; 8xbuild.writeMetadata('.', m); 9xbuild.publish('.'); 10xbuild.publishGithub('.', 'owner'); 11 12 13// 2. Publish next version, update github details. 14var m = xbuild.readMetadata('.'); 15var ver = xbuild.nextUnpublishedVersion(m.name, m.version); 16m.version = ver; 17xbuild.writeMetadata('.', m); 18xbuild.publish('.'); 19xbuild.publishGithub('.', 'owner'); 20xbuild.updateGithubRepoDetails(); 21 22 23// 3. Update keywords for package. 24var m = xbuild.readMetadata('.'); 25var p = xbuild.loadDocs(['src/index.ts']); 26var ds = p.children.map(xbuild.docsDetails); 27var s = new Set([...m.keywords, ...ds.map(d => d.name)]); 28m.keywords = Array.from(s); 29xbuild.writeMetadata('.', m); 30 31 32// 4. Restore package.json after publishing with updated version. 33var _package = xbuild.readDocument('package.json'); 34var m = xbuild.readMetadata('.'); 35m.version = '2.0.0'; 36xbuild.writeMetadata('.', m); 37xbuild.publish('.'); 38xbuild.writeDocument(_package); 39 40 41// 5. Update README index table. 42var owner = 'owner', repo = 'repo'; 43var p = xbuild.loadDocs(['src/index.ts']); 44var ds = p.children.map(xbuild.docsDetails); 45var re = /namespace|function/i; 46var dm = new Map(ds.map(d => [d.name, d])); 47var txt = xbuild.readFileText('README.md'); 48txt = xbuild.wikiUpdateIndex(txt, dm, d => re.test(d.kind)); 49txt = xbuild.wikiUpdateLinkReferences(txt, dm, {owner, repo}); 50xbuild.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 a script file. |
jsdocifyScript | Transform JSDocs in a 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. |
publish | Publish package to NPM. |
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 | Generate reference code block for wiki. |
wikiCodeExample | Generate example code block for wiki. |
wikiMarkdown | Generate markdown text for wiki. |
wikiUpdateIndex | Update the "Index" (property, description) table in markdown text. |
wikiUpdateLinkReferences | Update link references in markdown text. |
wikiUpdateDescription | Update description in markdown text. |
wikiUpdateCodeReference | Update code reference in markdown text. |

No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
4 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-x4c5-c7rf-jjgv
- Warn: Project is vulnerable to: GHSA-h5c3-5r3r-rr8q
- Warn: Project is vulnerable to: GHSA-rmvr-2pp2-xj38
- Warn: Project is vulnerable to: GHSA-xx4v-prfh-6cgc
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/nodef/extra-build/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/nodef/extra-build/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:57: update your workflow using https://app.stepsecurity.io/secureworkflow/nodef/extra-build/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:58: update your workflow using https://app.stepsecurity.io/secureworkflow/nodef/extra-build/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:61: update your workflow using https://app.stepsecurity.io/secureworkflow/nodef/extra-build/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:72: update your workflow using https://app.stepsecurity.io/secureworkflow/nodef/extra-build/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:73: update your workflow using https://app.stepsecurity.io/secureworkflow/nodef/extra-build/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:76: update your workflow using https://app.stepsecurity.io/secureworkflow/nodef/extra-build/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pr.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/nodef/extra-build/pr.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pr.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/nodef/extra-build/pr.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:80
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:63
- Info: 0 out of 8 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
- Info: 4 out of 6 npmCommand dependencies pinned
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Warn: no topLevel permission defined: .github/workflows/pr.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3.3
/10
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More