diff --git a/examples/autocomplete/.gitignore b/examples/autocomplete/.gitignore new file mode 100644 index 0000000..de4d1f0 --- /dev/null +++ b/examples/autocomplete/.gitignore @@ -0,0 +1,2 @@ +dist +node_modules diff --git a/examples/autocomplete/README.md b/examples/autocomplete/README.md new file mode 100644 index 0000000..2e95b63 --- /dev/null +++ b/examples/autocomplete/README.md @@ -0,0 +1,11 @@ +# autocomplete + +This example generates a `dist/directives.json` formatted like the one in used in https://github.com/jaywcjlove/nginx-editor, but instead of web scraping it uses `nginx-directive-reference`. + +The result is a little more accurate, with up-to-date information and no false-positives where the web scraper is misinterperting the HTML and documenting non-existent NGINX directives. + +## Usage + +1. `npm ci` +2. `npm run build` +3. use the file in `dist/directives.json` as needed diff --git a/examples/autocomplete/index.ts b/examples/autocomplete/index.ts new file mode 100644 index 0000000..b0dc73e --- /dev/null +++ b/examples/autocomplete/index.ts @@ -0,0 +1,36 @@ +import { getDirectives, Format, Directive } from '@nginxinc/reference-lib' +type autocomplete = { + /** name of the NGINX module */ + m: string + /** name */ + n: string + /** markdown-formatted description */ + d: string + /** default value, as an unformatted string as if a human typed it into an + * nginx config */ + v?: string + /** markdown CSV for valid contexts */ + c: string + /** markdown-formatted syntax specifications, including directive name. + * Multiple syntaxes are seperated by newlines */ + s: string +} + +function toAutocomplete(d: Directive): autocomplete { + const ret: autocomplete = { + m: d.module, + n: d.name, + d: d.description, + c: d.contexts.map((c) => '`' + c + '`').join(', '), + s: d.syntax.map((s) => `**${d.name}** ${s};`).join('\n'), + } + + if (d.default) { + ret.v = `${d.name} ${d.default};` + } + + return ret +} + +const formatted = getDirectives(Format.Markdown).map(toAutocomplete) +console.log(JSON.stringify(formatted, undefined, 4)) diff --git a/examples/autocomplete/package-lock.json b/examples/autocomplete/package-lock.json new file mode 100644 index 0000000..54a1887 --- /dev/null +++ b/examples/autocomplete/package-lock.json @@ -0,0 +1,211 @@ +{ + "name": "autocomplete", + "version": "0.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "autocomplete", + "version": "0.0.0", + "dependencies": { + "@nginxinc/reference-lib": "file:../../reference-lib", + "@types/node": "^20.8.7", + "ts-node": "^10.9.1", + "typescript": "^5.2.2" + } + }, + "../../reference-lib": { + "version": "1.0.7", + "devDependencies": { + "@rollup/plugin-json": "^6.0.0", + "@rollup/plugin-typescript": "^11.1.4", + "@types/jest": "^29.5.5", + "install": "^0.13.0", + "jest": "^29.7.0", + "npm": "^9.8.1", + "rollup": "^3.29.4", + "ts-jest": "^29.1.1", + "tslib": "^2.6.2" + } + }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz", + "integrity": "sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.4.15", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", + "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, + "node_modules/@nginxinc/reference-lib": { + "resolved": "../../reference-lib", + "link": true + }, + "node_modules/@tsconfig/node10": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", + "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==" + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==" + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==" + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==" + }, + "node_modules/@types/node": { + "version": "20.8.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.7.tgz", + "integrity": "sha512-21TKHHh3eUHIi2MloeptJWALuCu5H7HQTdTrWIFReA8ad+aggoX+lRes3ex7/FtpC+sVUpFMQ+QTfYr74mruiQ==", + "dependencies": { + "undici-types": "~5.25.1" + } + }, + "node_modules/acorn": { + "version": "8.10.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.10.0.tgz", + "integrity": "sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-walk": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", + "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==" + }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==" + }, + "node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==" + }, + "node_modules/ts-node": { + "version": "10.9.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", + "integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==", + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, + "node_modules/typescript": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", + "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "5.25.3", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.25.3.tgz", + "integrity": "sha512-Ga1jfYwRn7+cP9v8auvEXN1rX3sWqlayd4HP7OKk4mZWylEmu3KzXDUGrQUN6Ol7qo1gPvB2e5gX6udnyEPgdA==" + }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==" + }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "engines": { + "node": ">=6" + } + } + } +} diff --git a/examples/autocomplete/package.json b/examples/autocomplete/package.json new file mode 100644 index 0000000..fe21aed --- /dev/null +++ b/examples/autocomplete/package.json @@ -0,0 +1,16 @@ +{ + "name": "autocomplete", + "private": true, + "version": "0.0.0", + "description": "build autocomplete datasets", + "type": "module", + "scripts": { + "build": "mkdir -p dist && ts-node --esm index.ts > dist/directives.json" + }, + "dependencies": { + "@nginxinc/reference-lib": "file:../../reference-lib", + "@types/node": "^20.8.7", + "ts-node": "^10.9.1", + "typescript": "^5.2.2" + } +} diff --git a/examples/autocomplete/tsconfig.json b/examples/autocomplete/tsconfig.json new file mode 100644 index 0000000..2a47b61 --- /dev/null +++ b/examples/autocomplete/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "module": "ES2020", + "moduleResolution": "bundler" + }, + "include": ["*.ts"] +} diff --git a/reference-lib/jest.config.js b/reference-lib/jest.config.js index db45fbe..bfaa096 100644 --- a/reference-lib/jest.config.js +++ b/reference-lib/jest.config.js @@ -1,9 +1,9 @@ -module.exports = { - transform: {'^.+\\.ts?$': 'ts-jest'}, - testEnvironment: 'node', - testRegex: '/tests/.*\\.(test|spec)?\\.(ts|tsx)$', - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], - moduleNameMapper: { - "reference.json": "./src/__mocks__/reference_mock.json" - } - }; +export default { + transform: { '^.+\\.ts?$': 'ts-jest' }, + testEnvironment: 'node', + testRegex: '/tests/.*\\.(test|spec)?\\.(ts|tsx)$', + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], + moduleNameMapper: { + 'reference.json': './src/__mocks__/reference_mock.json', + }, +} diff --git a/reference-lib/package.json b/reference-lib/package.json index 5fa74df..24e6930 100644 --- a/reference-lib/package.json +++ b/reference-lib/package.json @@ -3,6 +3,7 @@ "version": "1.0.7", "description": "", "main": "dist/index.js", + "type": "module", "scripts": { "build": "./node_modules/.bin/rollup -c", "test": "jest --coverage"