feat: initial version

This commit is contained in:
Derrick Hammer 2023-07-07 00:28:07 -04:00
parent 19c82f33d6
commit 3a8855abe2
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
6 changed files with 19064 additions and 0 deletions

5
.presetterrc.json Normal file
View File

@ -0,0 +1,5 @@
{
"preset": [
"@lumeweb/node-library-preset"
]
}

18931
npm-shrinkwrap.json generated Normal file

File diff suppressed because it is too large Load Diff

32
package.json Normal file
View File

@ -0,0 +1,32 @@
{
"name": "@lumeweb/presetter-relay-plugin-preset",
"version": "0.1.0",
"type": "module",
"main": "lib/index.js",
"repository": {
"type": "git",
"url": "gitea@git.lumeweb.com:LumeWeb/presetter-relay-plugin-preset.git"
},
"devDependencies": {
"@lumeweb/node-library-preset": "^0.2.7",
"presetter": "^4.0.1"
},
"readme": "ERROR: No README data found!",
"_id": "@lumeweb/presetter-relay-plugin-preset@0.1.0",
"scripts": {
"prepare": "presetter bootstrap",
"build": "run build",
"semantic-release": "semantic-release"
},
"dependencies": {
"read-pkg": "^8.0.0",
"semantic-release": "^21.0.7"
},
"publishConfig": {
"access": "public"
},
"files": [
"lib",
"templates"
]
}

87
src/index.ts Normal file
View File

@ -0,0 +1,87 @@
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import {
loadFile,
template,
PresetAsset,
PresetContext,
resolveDirective,
} from "presetter";
import { readPackage } from "read-pkg";
const DIR = fileURLToPath(dirname(import.meta.url));
// paths to the template directory
const TEMPLATES = resolve(DIR, "..", "templates");
/** List of configurable variables */
export type Variable = {
/** the directory containing all source code (default: source) */
source: string;
/** the directory containing all the compiled files (default: lib) */
output: string;
buildSource: string;
};
export const DEFAULT_VARIABLE: Variable = {
source: "build",
output: "lib",
buildSource: "src",
};
function buildOptions(context: PresetContext) {
const opts = context.custom.config?.esbuild as any;
if (!opts) {
throw new Error("esbuild options missing!");
}
return { esbuildOptions: resolveDirective(opts, context).stringifiedConfig };
}
/**
* get the list of templates provided by this preset
* @returns list of preset templates
*/
export default async function (context: PresetContext): Promise<PresetAsset> {
let name: string = context.custom.config?.pluginName as unknown as string;
if (!name) {
const pkg = await readPackage();
name = pkg.name.split("plugin-").pop() as string;
}
return {
extends: ["presetter-preset-strict"],
template: {
"build.js": (context) => {
const content = loadFile(resolve(TEMPLATES, "build.js"), "text");
const variable = buildOptions(context);
return template(content, variable);
},
},
scripts: resolve(TEMPLATES, "scripts.yaml"),
noSymlinks: ["build.js"],
supplementaryConfig: {
"gitignore": ["build.js"],
"tsconfig": {
compilerOptions: {
moduleResolution: "nodenext",
},
},
"tsconfig.build": {
include: ["{buildSource}"],
compilerOptions: {
outDir: "{source}",
},
},
"esbuild": {
entryPoints: ["{source}/index.ts"],
outfile: `{output}/${name}.js`,
format: "cjs",
bundle: true,
platform: "node",
},
},
};
}

3
templates/build.js Normal file
View File

@ -0,0 +1,3 @@
import esbuild from "esbuild";
esbuild.buildSync({esbuildOptions});

6
templates/scripts.yaml Normal file
View File

@ -0,0 +1,6 @@
# replace the `prepare` template from presetter-preset
# so that the build procedure will not be triggered upon package installation
build: cross-env NODE_ENV=production run-s clean build:typescript:* build:esbuild
build:esbuild: node build.js
develop: cross-env NODE_ENV=development run-s "build:esbuild -- --watch {@}" --
clean:buildOutput: shx rm -rf {source}