├── .vscode ├── settings.json └── launch.json ├── test ├── simple-test.d.ts ├── function-test.d.ts ├── type-test.d.ts ├── enum-test.d.ts ├── accesor-test.d.ts ├── basic-test.d.ts └── class-test.d.ts ├── .editorconfig ├── scripts ├── clean.sh ├── build.js ├── test.sh └── build.sh ├── tsconfig.json ├── LICENSE ├── src ├── terminal.ts ├── grok-cli.ts └── grok.ts ├── package.json ├── AGENTS.md ├── config └── rollup.config.js ├── CODE_OF_CONDUCT.md ├── README.md └── .eslintrc.json /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true 3 | } 4 | -------------------------------------------------------------------------------- /test/simple-test.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The simplest example possible: a single type definition with a comment. 3 | */ 4 | 5 | export type T = string; 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | indent_size = 2 9 | indent_style = space 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | 13 | [*.md] 14 | trim_trailing_whitespace = false 15 | -------------------------------------------------------------------------------- /scripts/clean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e # exit immediately on error 4 | set -o nounset # abort on unbound variable 5 | set -o pipefail # don't hide errors within pipes 6 | # set -x # for debuging, trace what is being executed. 7 | 8 | cd "$(dirname "$0")/.." 9 | 10 | rm -rf "./bin" 11 | rm -rf "./test/output" 12 | rm -rf "./build" 13 | rm -rf "./coverage" 14 | -------------------------------------------------------------------------------- /test/function-test.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Global function 3 | */ 4 | 5 | declare function mainEntryPoint(one: string): boolean; 6 | 7 | /** 8 | * Function with plain object arguments 9 | * 10 | * @param options.anotherOption Comment on second field of first argument 11 | * @param other Comment on rest argument 12 | */ 13 | 14 | declare function foo( 15 | options?: { 16 | withHighlighting: boolean; 17 | anotherOption: string; 18 | }, 19 | ...other 20 | ): boolean; 21 | -------------------------------------------------------------------------------- /scripts/build.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | // https://esbuild.github.io/api/ 4 | 5 | // eslint-disable-next-line import/no-extraneous-dependencies 6 | const { build } = require('esbuild'); 7 | build({ 8 | entryPoints: ['src/grok-cli.ts'], 9 | outfile: 'bin/grok-cli.js', 10 | bundle: true, 11 | platform: 'node', 12 | external: [ 13 | './node_modules/*', 14 | 'highlight.js', 15 | 'fs-extra', 16 | 'typedoc', 17 | 'markdown-it', 18 | 'chalk', 19 | 'ci-info', 20 | 'cosmiconfig', 21 | 'update-notifier', 22 | 'yargs', 23 | ], 24 | banner: { js: '#!/usr/bin/env node' }, 25 | minify: false, 26 | sourcemap: true, 27 | logLevel: 'debug', 28 | }); 29 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowJs": true, 4 | "declaration": true, 5 | "emitDecoratorMetadata": true, 6 | "esModuleInterop": true, 7 | "experimentalDecorators": true, 8 | "incremental": true, 9 | "module": "ESNext", 10 | "moduleResolution": "node", 11 | // "newLine": "lf", 12 | "noImplicitAny": false, 13 | "noLib": false, 14 | "removeComments": true, 15 | "sourceMap": true, 16 | // "strictNullChecks": true, 17 | "target": "es2020", 18 | 19 | "lib": ["es2020", "dom", "dom.iterable", "scripthost"] 20 | // "lib": ["es2020", "scripthost"] 21 | }, 22 | "exclude": ["node_modules", "**/*.spec.ts", "bin", "config"] 23 | } 24 | -------------------------------------------------------------------------------- /test/type-test.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This is a comment. 3 | * @method foo() 4 | * @module Module 5 | * @function function() 6 | * @private 7 | * @example 8 | * let x = 1; 9 | * const y: Foo = 0; 10 | * @category Category One 11 | */ 12 | 13 | type Foo = string & boolean; 14 | 15 | /** 16 | * 17 | * Use a table to document the value of a union, intersection or 18 | * enum. 19 | * 20 | * | | | 21 | * |------:|:------| 22 | * |`one`| The value foo is useful to represent fooness | 23 | * |`two`| The value bar is useful to represent barness | 24 | * |`three`| The value bar is useful to represent barness. 25 | * If necessary, use more lines. 26 | * You can even use some code samples 27 | * ``` 28 | * const x = Foo.enum; 29 | * ``` | 30 | * 31 | */ 32 | 33 | type UnionType = 'one' | 'two' | 'three'; 34 | -------------------------------------------------------------------------------- /test/enum-test.d.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Enums 3 | */ 4 | export enum Response { 5 | No = 0, 6 | Yes = 1, 7 | } 8 | export enum Direction { 9 | Up = 'UP', 10 | Down = 'DOWN', 11 | Left = 'LEFT', 12 | Right = 'RIGHT', 13 | } 14 | export enum FileAccess { 15 | // constant members 16 | None, 17 | Read = 1 << 1, 18 | Write = 1 << 2, 19 | ReadWrite = Read | Write, 20 | // computed member 21 | G, 22 | B, 23 | } 24 | export const nameOfA = Direction.Up; // "UP" 25 | 26 | export const enum EnumH1 { 27 | /** 28 | * Shortest name: {@link EnumH1.memberH2} 29 | * Full name: {@link (EnumH1:enum).memberH2} 30 | */ 31 | memberH2, 32 | } 33 | 34 | // (MUST NOT have TSDoc, because this is part of an enum that was already 35 | // documented above.) 36 | export const enum EnumH1 { 37 | /** 38 | * Shortest name: {@link EnumH1.memberH3} 39 | * Full name: {@link (EnumH1:enum).memberH3} 40 | */ 41 | memberH3 = 3, 42 | } 43 | -------------------------------------------------------------------------------- /test/accesor-test.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Getter/Setter (accessor) 3 | */ 4 | declare class AccessorClass { 5 | private _bar: boolean; 6 | /** 7 | * Comment for getter 8 | * Full name: {@link (AccessorClass:class).(bar:instance)} 9 | */ 10 | get bar(): boolean; 11 | /** 12 | * Comment for setter is ignored 13 | */ 14 | set bar(value: boolean); 15 | } 16 | 17 | /* 18 | * Setter only 19 | */ 20 | declare class SetterClass { 21 | private _bar: boolean; 22 | /** 23 | * Comment for setter is read 24 | */ 25 | set bar(value: boolean); 26 | } 27 | 28 | /* 29 | * Getter only 30 | */ 31 | declare class GetterClass { 32 | constructor(); 33 | private _bar: boolean; 34 | /** 35 | * Comment for getter 36 | * Note intentionally confusing name "constructor" 37 | * Links should point to the correct entry. 38 | * Note: typedoc currently doesn't parse this correctly 39 | */ 40 | get xconstructor(): boolean; 41 | } 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 UI-JS 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /scripts/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e # exit immediately on error 4 | set -o nounset # abort on unbound variable 5 | set -o pipefail # don't hide errors within pipes 6 | # set -x # for debuging, trace what is being executed. 7 | 8 | cd "$(dirname "$0")/.." 9 | 10 | # Read the first argument, set it to "dev" if not set 11 | VARIANT="${1-coverage}" 12 | 13 | export BASENAME="\033[40m Grok Test \033[0;0m " # `basename "$0"` 14 | export DOT="\033[32m 羽 \033[0;0m" # Hourglass 15 | export CHECK="\033[32m ✔ \033[0;0m" 16 | export ERROR="\033[31;7m ERROR \033[0;0m" 17 | export LINECLEAR="\033[1G\033[2K" # position to column 1; erase whole line 18 | export DIM="\033[0;2m" 19 | export RESET="\033[0;0m" 20 | 21 | for f in "accesor" "basic" "class" "enum" "function" "simple" "type" 22 | do 23 | echo -e "$BASENAME${DIM}"${f}-test.d.ts"$RESET" 24 | 25 | node ./bin/grok-cli.js "test/${f}-test.d.ts" --outDir ./test/output/${f} --verbose --ignore-errors 26 | 27 | done 28 | 29 | 30 | # if [ "$VARIANT" = "coverage" ]; then 31 | # npx jest --coverage 32 | # elif [ "$VARIANT" = "snapshot" ]; then 33 | # npx jest -u 34 | # else 35 | # npx jest 36 | # fi -------------------------------------------------------------------------------- /scripts/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e # exit immediately on error 4 | set -o nounset # abort on unbound variable 5 | set -o pipefail # don't hide errors within pipes 6 | # set -x # for debuging, trace what is being executed. 7 | 8 | cd "$(dirname "$0")/.." 9 | 10 | export BASENAME="\033[40m Grok \033[0;0m " # `basename "$0"` 11 | export DOT="\033[32m 羽 \033[0;0m" # Hourglass 12 | export CHECK="\033[32m ✔ \033[0;0m" 13 | export ERROR="\033[31;7m ERROR \033[0;0m" 14 | export LINECLEAR="\033[1G\033[2K" # position to column 1; erase whole line 15 | export DIM="\033[0;2m" 16 | export RESET="\033[0;0m" 17 | 18 | 19 | # If no "node_modules" directory, do an install first 20 | if [ ! -d "./node_modules" ]; then 21 | printf "$BASENAME$DOT${RESET}Installing dependencies" 22 | npm install 23 | echo -e "$LINECLEAR${RESET}$BASENAME${CHECK}${DIM}Dependencies installed${RESET}" 24 | fi 25 | 26 | # Read the first argument, set it to "dev" if not set 27 | export BUILD="${1-dev}" 28 | 29 | echo -e "${RESET}$BASENAME$DOT${RESET}Build started" 30 | 31 | rm -rf ./bin 32 | 33 | node ./scripts/build.js 34 | 35 | echo -e "$LINECLEAR${RESET}$BASENAME$CHECK${RESET}Build completed" 36 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Run Grok", 9 | "request": "launch", 10 | "type": "node", 11 | "skipFiles": ["/**"], 12 | "program": "${workspaceFolder}/bin/grok-cli.js", 13 | "preLaunchTask": "npm: build", 14 | "sourceMaps": true, 15 | "smartStep": true, 16 | "outFiles": ["${workspaceFolder}/bin/grok-cli.js"], 17 | "args": [ 18 | "../mathlive/", 19 | "--inFile", 20 | "./src/mathlive.ts", 21 | 22 | // "../compute-engine/", 23 | // "--inFile", 24 | // "./src/compute-engine.ts", 25 | 26 | // "../mathlive/", 27 | // "--inFile", 28 | // "./src/mathlive.ts", 29 | 30 | // "test/enum-test.d.ts", 31 | "--outDir", 32 | "build", 33 | "--verbose", 34 | "--ignore-errors" 35 | ] 36 | }, 37 | { 38 | "name": "Grok Compute Engine", 39 | "request": "launch", 40 | "type": "node", 41 | "skipFiles": ["/**"], 42 | "program": "${workspaceFolder}/bin/grok-cli.js", 43 | "preLaunchTask": "npm: build", 44 | "sourceMaps": true, 45 | "smartStep": true, 46 | "outFiles": ["${workspaceFolder}/bin/grok-cli.js"], 47 | "args": [ 48 | "../compute-engine/", 49 | "--inFile", 50 | "./src/compute-engine.ts", 51 | 52 | // "../compute-engine/", 53 | // "--inFile", 54 | // "./src/compute-engine.ts", 55 | 56 | // "../mathlive/", 57 | // "--inFile", 58 | // "./src/mathlive.ts", 59 | 60 | // "test/enum-test.d.ts", 61 | "--outDir", 62 | "build", 63 | "--verbose", 64 | "--ignore-errors" 65 | ] 66 | } 67 | ] 68 | } 69 | -------------------------------------------------------------------------------- /src/terminal.ts: -------------------------------------------------------------------------------- 1 | // import chalk from 'chalk'; 2 | // import { isCI } from 'ci-info'; 3 | 4 | const chalk = require('chalk'); 5 | const ciInfo = require('ci-info'); 6 | const isCI = ciInfo.isCI; 7 | 8 | // 9 | // Terminal colors for various kind of messages 10 | // 11 | const tcOrange = '#ffcc00'; 12 | const tcRed = '#fa2040'; 13 | const tcBlue = '#6ab3ff'; 14 | const tcPurple = '#d1d7ff'; 15 | 16 | /** Do not use fancy color output if the output stream is not a terminal 17 | * (e.g. if we're redirecting errors to a log file) or when in a CI environment. 18 | * Note that the debug console in VSCode returns 'undefined' for isTTY. 19 | */ 20 | let gUseColor = (process.stdout.isTTY ?? false) && !isCI; 21 | 22 | export const terminal = { 23 | useColor: (flag: boolean): void => { 24 | gUseColor = flag; 25 | }, 26 | autoFormat: (m: string): string => { 27 | return m 28 | .replace(/("(.*)")/g, (x) => { 29 | return terminal.string(x.slice(1, -1)); 30 | }) 31 | .replace(/(`(.*)`)/g, (x) => { 32 | return terminal.keyword(x); 33 | }); 34 | }, 35 | success: (m = ''): string => { 36 | chalk.green('✔︎ ' + m); 37 | return gUseColor ? chalk.bold.green('✔︎ ' + m) : '✔︎ ' + m; 38 | }, 39 | error: (m = ''): string => { 40 | return gUseColor ? chalk.hex(tcRed)(chalk.bold('✘ ' + m)) : '✘ ' + m; 41 | }, 42 | warning: (m = ''): string => { 43 | return gUseColor 44 | ? chalk.hex(tcOrange)(chalk.bold('⚠️ ' + m)) 45 | : '⚠ ' + m; 46 | }, 47 | path: (m = ''): string => { 48 | return gUseColor ? chalk.hex(tcBlue).italic(m) : m; 49 | }, 50 | keyword: (m = ''): string => { 51 | return gUseColor ? chalk.hex(tcOrange)(m) : m; 52 | }, 53 | string: (m = ''): string => { 54 | return gUseColor 55 | ? chalk.hex(tcOrange)('"' + chalk.italic(m) + '"') 56 | : '"' + m + '"'; 57 | }, 58 | dim: (m = ''): string => { 59 | return gUseColor ? chalk.hex('#999')(m) : m; 60 | }, 61 | time: (t = new Date()): string => { 62 | return gUseColor 63 | ? chalk.hex(tcPurple)(`[${t.toLocaleTimeString()}]`) 64 | : '[' + t + ']'; 65 | }, 66 | link: (m: string): string => { 67 | return gUseColor 68 | ? '\n▷ ' + 69 | chalk.hex(tcPurple)( 70 | 'https://github.com/arnog/chromatic/docs/errors/' + m + '.md' 71 | ) 72 | : '\n▷ https://github.com/arnog/chromatic/docs/errors/' + m + '.md'; 73 | }, 74 | }; 75 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@ui-js/grok", 3 | "version": "1.8.0", 4 | "description": "A tool to build beautiful documentation from TypeScript declaration files", 5 | "publishConfig": { 6 | "access": "public" 7 | }, 8 | "keywords": [ 9 | "TypeScript", 10 | "documentation", 11 | "tool" 12 | ], 13 | "license": "MIT", 14 | "main": "bin/grok-cli.js", 15 | "bin": { 16 | "grok": "./bin/grok-cli.js" 17 | }, 18 | "files": [ 19 | "bin" 20 | ], 21 | "devDependencies": { 22 | "@cortex-js/prettier-config": "^1.1.1", 23 | "@types/node": "^17.0.23", 24 | "esbuild": "^0.25.11", 25 | "eslint": "^8.12.0", 26 | "eslint-config-prettier": "^8.5.0", 27 | "eslint-plugin-import": "^2.25.4", 28 | "eslint-plugin-prettier": "^4.0.0", 29 | "lint-staged": "^12.3.7", 30 | "please-upgrade-node": "^3.2.0" 31 | }, 32 | "dependencies": { 33 | "@typescript-eslint/eslint-plugin": "^5.17.0", 34 | "@typescript-eslint/parser": "^5.17.0", 35 | "chalk": "^4.0.0", 36 | "ci-info": "^3.3.0", 37 | "cosmiconfig": "^7.0.1", 38 | "fs-extra": "^10.0.1", 39 | "glob": "^7.2.0", 40 | "highlight.js": "^11.5.0", 41 | "markdown-it": "^12.3.2", 42 | "markdown-it-deflist": "^2.1.0", 43 | "postcss": "^8.4.12", 44 | "postcss-cli": "^9.1.0", 45 | "prettier": "^2.6.1", 46 | "resolve-from": "^5.0.0", 47 | "typedoc": "0.22.13", 48 | "typescript": "^4.6.0", 49 | "update-notifier": "^7.3.1", 50 | "yaml": "^1.10.2", 51 | "yargs": "^17.4.0" 52 | }, 53 | "engines": { 54 | "node": ">=16.0.0" 55 | }, 56 | "repository": { 57 | "type": "git", 58 | "url": "https://github.com/ui-js/grok.git" 59 | }, 60 | "scripts": { 61 | "build": "bash ./scripts/build.sh", 62 | "clean": "bash ./scripts/clean.sh", 63 | "coverage": "bash ./scripts/test.sh coverage", 64 | "dist": "bash ./scripts/build.sh production", 65 | "grok": "node ./bin/grok-cli.js", 66 | "lint": "eslint --ignore-path ./.prettierignore --fix \"src/*.{ts,js}\"", 67 | "prettier": "prettier --ignore-path ./.prettierignore --write \"**/*.{ts,js,css,md,yml,json}\" \"!vendor/**\"", 68 | "smoke": "node ./bin/grok-cli.js test --inFile ./enum-test.d.ts --outDir build --verbose --ignore-errors", 69 | "test": "bash ./scripts/test.sh" 70 | }, 71 | "prettier": "@cortex-js/prettier-config", 72 | "lint-staged": { 73 | "**/*.ts": [ 74 | "eslint --fix", 75 | "git add" 76 | ], 77 | "*.{js,css,json,md}": [ 78 | "prettier --write", 79 | "git add" 80 | ] 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /AGENTS.md: -------------------------------------------------------------------------------- 1 | # Repository Guidelines 2 | 3 | ## Project Structure & Module Organization 4 | - Core TypeScript sources live in `src/`; `src/grok-cli.ts` routes CLI flags into the generator logic in `src/grok.ts` and `src/terminal.ts`. 5 | - `scripts/` contains the build and test automation, and `scripts/build.js` invokes esbuild to bundle the CLI. 6 | - Compiled artifacts land in `bin/`. Test declaration fixtures sit under `test/*.d.ts` with golden outputs in `test/output/` for quick diffing. 7 | - Bundling tweaks live in `config/rollup.config.js`. 8 | 9 | ## Build, Test, and Development Commands 10 | - `npm run build` bundles the CLI into `bin/grok-cli.js`; run before linking or packing. 11 | - `npm run dist` performs a production-lean build for release candidates. 12 | - `npm run grok -- --outDir ` executes the local CLI against a fixture for manual checks. 13 | - `npm run test` re-generates documentation from every fixture; follow with `git diff test/output` to spot regressions. 14 | - `npm run clean` removes `bin/` and stale outputs. `npm run coverage` runs the same harness, ready for CI coverage wiring. 15 | 16 | ## Coding Style & Naming Conventions 17 | - TypeScript files use two-space indentation, CommonJS `require` where interoperability is needed, and descriptive suffixes (e.g., `*-cli.ts` for entrypoints). 18 | - Prettier formatting derives from `@cortex-js/prettier-config`; run `npm run prettier` prior to opening a PR. 19 | - ESLint governs the `src/*.ts` surface. Use `npm run lint` and address autofixable issues before pushing. 20 | 21 | ## Testing Guidelines 22 | - Tests rely on deterministic output: add `test/-test.d.ts` fixtures and capture generated docs under `test/output//`. 23 | - Keep fixture names kebab-cased and mirror directories from the CLI invocation. 24 | - When behavior changes intentionally, update the matching output and reference the delta in your PR description. 25 | 26 | ## Commit & Pull Request Guidelines 27 | - Follow Conventional Commits (`chore: deps`, `doc: update readme` are in history); keep subjects under 60 characters and in the imperative mood. 28 | - Each PR should include a short summary, linked issue when relevant, and a note on validation. Attach snippets or screenshots of affected documentation when the output shifts. 29 | 30 | ## Environment & Tooling Tips 31 | - Target Node.js 16+; `scripts/build.sh` installs dependencies on demand, but prefer explicit `npm install` during local setup. 32 | - esbuild drives the bundle, so re-run `npm run build` after touching dependency topology or CLI entry files. Adjust externals in `scripts/build.js` if the bundling strategy changes. 33 | -------------------------------------------------------------------------------- /config/rollup.config.js: -------------------------------------------------------------------------------- 1 | import resolve from '@rollup/plugin-node-resolve'; 2 | import { terser } from 'rollup-plugin-terser'; 3 | import typescript from 'rollup-plugin-typescript2'; 4 | import pkg from '.././package.json'; 5 | 6 | process.env.BUILD = process.env.BUILD || 'development'; 7 | const PRODUCTION = process.env.BUILD === 'production'; 8 | 9 | console.log('PRODUCTION', PRODUCTION); 10 | 11 | const TYPESCRIPT_OPTIONS = { 12 | typescript: require('typescript'), 13 | clean: PRODUCTION, 14 | tsconfigOverride: { 15 | compilerOptions: { 16 | declaration: false, 17 | }, 18 | }, 19 | }; 20 | 21 | const TERSER_OPTIONS = { 22 | compress: { 23 | drop_console: false, 24 | drop_debugger: true, 25 | ecma: 8, // Use "5" to support older browsers 26 | module: true, 27 | warnings: true, 28 | passes: 2, 29 | global_defs: { 30 | ENV: JSON.stringify(process.env.BUILD), 31 | VERSION: JSON.stringify(pkg.version || '0.0'), 32 | }, 33 | }, 34 | }; 35 | export default [ 36 | { 37 | input: 'src/grok-cli.ts', 38 | output: { 39 | file: 'bin/grok-cli.js', 40 | format: 'cjs', 41 | banner: '#!/usr/bin/env node', 42 | sourcemap: !PRODUCTION, 43 | }, 44 | plugins: [ 45 | resolve({ preferBuiltins: true }), 46 | typescript(TYPESCRIPT_OPTIONS), 47 | // PRODUCTION && terser(TERSER_OPTIONS), 48 | // copy({ 49 | // targets: [{ src: 'package.json', dest: 'bin' }], 50 | // }), 51 | ], 52 | watch: { 53 | clearScreen: true, 54 | exclude: 'node_modules/**', 55 | include: ['src/**', 'examples/**'], 56 | }, 57 | }, 58 | { 59 | input: 'src/grok.ts', 60 | output: { 61 | file: 'bin/grok.js', 62 | format: 'cjs', 63 | sourcemap: !PRODUCTION, 64 | }, 65 | plugins: [ 66 | resolve({ preferBuiltins: true }), 67 | typescript(TYPESCRIPT_OPTIONS), 68 | PRODUCTION && terser(TERSER_OPTIONS), 69 | ], 70 | watch: { 71 | clearScreen: false, 72 | exclude: ['node_modules/**'], 73 | }, 74 | }, 75 | { 76 | input: 'src/grok.ts', 77 | output: { 78 | file: 'bin/grok.esm.js', 79 | format: 'esm', 80 | sourcemap: !PRODUCTION, 81 | }, 82 | plugins: [ 83 | resolve({ preferBuiltins: true }), 84 | typescript(TYPESCRIPT_OPTIONS), 85 | PRODUCTION && terser(TERSER_OPTIONS), 86 | ], 87 | watch: { 88 | clearScreen: false, 89 | exclude: ['node_modules/**'], 90 | }, 91 | }, 92 | ]; 93 | 94 | /* 95 | amd – Asynchronous Module Definition, used with module loaders like RequireJS 96 | cjs – CommonJS, suitable for Node and other bundlers 97 | esm – Keep the bundle as an ES module file, suitable for other bundlers and inclusion as a