@html_first/js_lib_template
v2.0.17
Published
an opionated js library single file exporter
Downloads
2
Maintainers
Readme
HOW TO INSTALL
npm i @html_first/js_lib_template --save-devor
bun i @html_first/js_lib_template -Dor any npm dependency management cli
singleton_instantiate_to_run
- class prefixed with "__", are:
singleton, can only be instantiated once;- call
runmethod of the instance, to starts the watcher to autogenerate the documentation;
exported-api-and-type-list
extendedfrom core- singleton_instantiate_to_run;
fileNamecontains.type.detects@+typedef+ ... +fileName;- supports nested folders;
- targets [
'*.mjs','*.ts','*.mts']files; instantiateclass API to watch for file changes;- the exported API should contains match literally:
/**
* @param {string} exportName
* @returns {string[]}
*/
exportPatterns = (exportName) => [
`export class ${exportName}`,
`export const ${exportName}`,
`export function ${exportName}`,
];- doesn't support
varorlet, for semantics; - supports for [
"*.mjs","*.ts","*.mts"]; fileNamecontains.type.detects@+typedef+ ... +fileName;- additional base setup for js developement:
- generate
types;
// tsconfig.js
{
"compilerOptions": {
"allowJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "./types",
"module": "ESNext",
"target": "ES2020",
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"baseUrl": "."
},
"include": [filePathOptionValue]
}
- generation script
// package.json
{
...
"main": "index.mjs",
"types": "./types/index.d.mts",
"module": "index.mjs",
"type": "module",
...
"scripts": {
"dev": "concurrently \"bun --watch ./dev/index.mjs\" \"bun tsc --watch\""
},
...
}- with type definition it can also check for:
- if there are any name colision, as we don't support aliases exports;
- allow your library user to set
skiplibChecks: falseon theirtypescriptconfiguration;
extendedfrom core- singleton_instantiate_to_run;
fileNamecontains.type.detects@+see+ ... +fileName;- using class instantiation, generate single
markdowndocumentation forPHP;
- on comment after
@seethrought the end of comment will be added;
- supports nesting;
- additional base setup;
- example file setting:
// ./dev/index.mjs
// @ts-check
import { __PHPDev } from '@html_first/js_lib_template';
new __PHPDev({
folderPath: './src',
readMePath: './README.md',
description: ['## HOW TO INSTALL','```shell','composer require author/package-name','```'].
}).run();- saving script for convenience:
// package.json
{
...
"scripts": {
...
"dev": "bun --watch ./dev/index.mjs"
...
},
}
...- starts watching:
bun dev
// or
npm run dev- class template for
auto document/export generator;
- extended class must call super on it's constructor
export class MyClass extends {
constructor(){
super({ ...coreOptions });
// ...
}
// ...
// also you need to override any method and property prefixed with "_"
}- constructor argument:
/**
* @typedef {Object} coreOptions
* @property {string} [coreOptions.filePath]
* - realtive path from wroking directory
* @property {string} [coreOptions.folderPath]
* - realtive path from wroking directory
* @property {string} [coreOptions.readMePath]
* - realtive path from wroking directory
* @property {string} [coreOptions.tableOfContentTitle]
* @property {string[]} [coreOptions.copyright]
* @property {string[]} [coreOptions.description]
* @property {import('chokidar').WatchOptions} [coreOptions.option]
*/- we use chokidar for watching changes:
- refer the options to chokidar github
- in essence this class is a collection of method to help to do the above points, incase of you want to create your own
documentation/export generatorcallingthis.createHandler; - file content detection uses
string.includes, as I cannot get arroundregexto allow me to use$as export name; README.mdauto export rules:
- has
description;- in case you want to render empty string use [
blank];- detectes the first
commentBlockwithdescription;- automatically turns string after last
descriptionof thatcommentBlockuntil end of thecommentBlock;upperCaseORsymbol;fileNamematch withexportedName;special export:fileNamecontains.type.:only works on
languagethat havetypesupports, wheredeclaringandassigningtypescan be done on differentfile:
- will detect depends on the
handler@+coreInstance._typedefIdentifier... +filename;
fileNamecontains.export.:
- use to bypass
upperCaserule:
- links:
- auto named
h2tagid, it match thefileNameinlowerCase;- in this
autoExportedcase__JSDevcan be refered as#__jsdev;- use
namedExportextracted files fromthis.getListFilesNestedDetailsmethod;- run
thisInstance.run();to start the watcher; !!!WARNING
- copy out:
- filePath: default
./index.mjs,- readMePath: default
./README.md,- folderPath: default
./src/*,typescriptoutDirorpackage.jsontypes: default./types/*,
- of any file you might need to be unmodified, before fully knowing what this library will modify...
