- v0.0.49Latest
- v0.0.48
- v0.0.47
- v0.0.46
- v0.0.45
- v0.0.44
- v0.0.43
- v0.0.42
- v0.0.41
- v0.0.40
- v0.0.39
- v0.0.38
- v0.0.37
- v0.0.36
- v0.0.35
- v0.0.34
- v0.0.33
- v0.0.32
- v0.0.31
- v0.0.30
- v0.0.29
- v0.0.28
- v0.0.27
- v0.0.26
- v0.0.25
- v0.0.24
- v0.0.23
- v0.0.22
- v0.0.21
- v0.0.20
- v0.0.19
- v0.0.18
- v0.0.17
- v0.0.16
- v0.0.15
- v0.0.14
- v0.0.13
- v0.0.12
- v0.0.11
- v0.0.10
- v0.0.9
- v0.0.8
- v0.0.7
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
tsa - Typescript source code analysis and documentation tool
Extension to tsc
that adds custom file loader, and documentation generator.
It can be used as command-line tool, or programmatically as Typescript library.
The original Typescript Compiler can load Typescript programs or modules from source files, and parse them to syntax nodes. This allows to analyze the project, or to bundle it to a single Javascript file.
However tsc
cannot load files from HTTP URLs as Deno does.
This library solves this issue by adding custom file loader. Also it adds facility to generate syntax nodes in less raw format, so the project structure can be easily analyzed. The nodes this library produces are compatible with x/deno_doc@0.62.0. Also this library can bundle Typescript project to single Typescript file (not only Javascript), and to generate project documentation in Markdown format.
Using as command-line tool
To install this tool do:
deno install --allow-env --allow-net --allow-read --allow-write https://deno.land/x/tsa@v0.0.30/tsa.ts
The command supports 5 operations:
tsa doc-json
(alias:tsa doc
) - generate JSON AST (abstract syntax tree) that contains functions and classes of the project together with their doc-comments.tsa doc-md
- generate documentation in Markdown format.tsa bundle-js
(alias:tsa bundle
) - generate.js
bundle that contains all the files of the project as single ECMA module or program.tsa bundle-ts
- generate.ts
bundle.tsa types
- generate.d.ts
file with type declarations.
tsa doc-json [options] [fileN.tsā¦]
Generate JSON AST suitable for further documentation generation.
Options:
--outFile <out.json>
- Where to save the result (default: stdout).--pretty
- Produce human-readable JSON.
Example:
tsa doc-json --pretty --outFile=/tmp/doc.json https://deno.land/x/dir@1.5.1/mod.ts
tsa doc-md [options] [fileN.tsā¦]
Generate documentation in markdown format.
Options:
--outFile <README.md>
(required) - Where to save the result.--outDir <generated-doc>
- This command also creates linked README.md files in the āoutDir directory (default: āgenerated-docā). The directory will be created near āoutFile or existing directory will be emptied if necessary.--moduleName <My Project>
- The title that will appear in the main README.md file.--importUrl <URL>
- Optionally specify one such flag per each source file in corresponding order. This lets including in the documentation import examples for public symbols. The specified importUrl must point to a public registry that downloads (or will download) the same file as provided to the generator. For example:tsa doc-md foo/mod.ts --importUrl https://deno.land/foo@1.0.0/mod.ts bar/mod.ts --importUrl https://deno.land/bar@1.0.0/mod.ts
(the number of āimportUrl options must be the same as number of given files).--outUrl <URL>
- If you plan to upload the resulting files to a public resource (such as github), you can optionally specify URL by which the āoutFile will be publicly accessible. Then you can use script examples in doc-comments marked as// To run this example:
on the first line, and followed by a line that contains āexample.tsā, like// deno run --allow-all example.ts
, and these lines will be converted to// To download and run this example:
ā¦
tsa bundle-js [options] [fileN.tsā¦]
Bundle Typescript source files to single Javascript module.
Options:
--outFile <out.js>
- Where to save the result (default: stdout).--target <ESNext>
- Target JavaScript version. One of: ES2015, ES2016, ES2017, ES2018, ES2019, ES2020, ES2021, ES2022, ESNext (default: ESNext).
tsa bundle-ts [options] [fileN.tsā¦]
Bundle Typescript source files to single .ts
module.
Options:
--outFile <out.ts>
- Where to save the result (default: stdout).--target <ESNext>
- Target JavaScript version. One of: ES2015, ES2016, ES2017, ES2018, ES2019, ES2020, ES2021, ES2022, ESNext (default: ESNext).
tsa types [options] [fileN.tsā¦]
Generate type declarations file (DTS).
Options:
--outFile <out.d.ts>
- Where to save the result (default: stdout).
Using as Typescript library
This library internally uses the official Typescript Compiler,
and reexports itās namespace as tsa symbol. This namespace contains all of the ts
namespace,
plus this library extends it by defining createTsaProgram function within this namespace.
When using Typescript Compiler, the first step is to create ts.Program by calling ts.createProgram() function. Similarly when using this library, the first step is to create tsa.TsaProgram object by calling tsa.createTsaProgram().
// To download and run this example:
// curl 'https://raw.githubusercontent.com/jeremiah-shaulov/tsa/v0.0.30/README.md' | perl -ne '$y=$1 if /^```(.)?/; print $_ if $y&&$m; $m=$y&&($m||m~<example-p9mn>~)' > /tmp/example-p9mn.ts
// deno run --allow-env --allow-net --allow-read --allow-write /tmp/example-p9mn.ts
import {tsa, printDiagnostics, LoadOptions} from 'https://deno.land/x/tsa@v0.0.30/mod.ts';
const SUBJ = 'https://deno.land/x/dir@1.5.1/mod.ts'; // Can be local file (`file:///...`)
// Options for typescript compiler.
// To generate docs, set `declaration` and `emitDeclarationOnly`.
// To bundle leave blank.
const compilerOptions: tsa.CompilerOptions =
{ declaration: true,
emitDeclarationOnly: true,
};
// Configures how to resolve module specifiers, and how to load module contents.
const loadOptions: LoadOptions =
{
};
// Create typescript program
const program = await tsa.createTsaProgram([SUBJ], compilerOptions, loadOptions);
// Print errors and warnings (if any)
printDiagnostics(tsa.getPreEmitDiagnostics(program));
// Now use the `program` object...
tsa.TsaProgram extends ts.Program by adding 2 methods:
The purpose of this library is to provide these 2 methods.