11import * as esbuild from 'esbuild' ;
2- import { mkdir , readdir , readFile , writeFile } from 'fs/promises' ;
2+ import { mkdir , readdir , readFile , writeFile } from 'fs/promises' ;
33import path from 'path' ;
4- import yaml from 'js- yaml' ;
4+ import YAML from 'yaml' ; // Use the existing 'yaml' package
55
66const watch = process . argv . includes ( '--watch' ) ;
77const serve = process . argv . includes ( '--serve' ) ;
88
99const PINOUTS_DIR = 'public/pinouts' ;
1010const INDEX_JSON_PATH = 'public/index.json' ;
1111
12- await mkdir ( './public/dist' , { recursive : true } ) ;
12+ await mkdir ( './public/dist' , { recursive : true } ) ;
1313
14- const commonOptions = {
15- bundle : true ,
16- sourcemap : true ,
17- minify : true ,
18- target : [ 'esnext' ] ,
19- format : 'esm' ,
20- logLevel : 'info' ,
21- loader : {
22- '.woff2' : 'dataurl' ,
23- } ,
24- } ;
2514
2615// --- Pinout Index Generation ---
2716
2817async function findYamlFiles ( dir ) {
2918 let yamlFiles = [ ] ;
3019 try {
31- const entries = await readdir ( dir , { withFileTypes : true } ) ;
20+ const entries = await readdir ( dir , { withFileTypes : true } ) ;
3221 for ( const entry of entries ) {
3322 const fullPath = path . join ( dir , entry . name ) ;
3423 if ( entry . isDirectory ( ) ) {
3524 yamlFiles = yamlFiles . concat ( await findYamlFiles ( fullPath ) ) ;
36- } else if ( entry . isFile ( ) && ( entry . name . endsWith ( '.yaml' ) || entry . name . endsWith ( '.yml' ) ) ) {
25+ } else if ( entry . isFile ( ) && ( entry . name . endsWith ( '.yaml' ) ) ) {
3726 yamlFiles . push ( fullPath ) ;
3827 }
3928 }
@@ -55,8 +44,8 @@ async function generateIndexJson() {
5544 for ( const filePath of yamlFiles ) {
5645 try {
5746 const fileContent = await readFile ( filePath , 'utf-8' ) ;
58- const doc = yaml . load ( fileContent ) ;
59- const title = doc ?. setup ?. title ;
47+ const doc = YAML . parse ( fileContent ) ; // Use YAML.parse instead of yaml.load
48+ const title = doc ?. title ;
6049 if ( title ) {
6150 // Make path relative to 'public' directory
6251 const relativePath = path . relative ( 'public' , filePath ) ;
@@ -94,8 +83,8 @@ const pinoutIndexPlugin = {
9483 // Run on end of each build (including rebuilds in watch/serve mode)
9584 build . onEnd ( async ( result ) => {
9685 if ( result . errors . length === 0 && ( watch || serve ) ) {
97- // Check if relevant files changed? For now, regenerate always on success.
98- // A more sophisticated check could involve tracking YAML file mtimes.
86+ // Check if relevant files changed? For now, regenerate always on success.
87+ // A more sophisticated check could involve tracking YAML file mtimes.
9988 await generateIndexJson ( ) ;
10089 }
10190 } ) ;
@@ -105,9 +94,21 @@ const pinoutIndexPlugin = {
10594
10695// --- ESBuild Options ---
10796
97+ const commonOptions = {
98+ bundle : true ,
99+ sourcemap : true ,
100+ minify : true ,
101+ target : [ 'esnext' ] ,
102+ format : 'esm' ,
103+ logLevel : 'info' ,
104+ loader : {
105+ '.woff2' : 'dataurl' ,
106+ } ,
107+ } ;
108+
108109const cliOptions = {
109110 ...commonOptions ,
110- plugins : [ pinoutIndexPlugin ] , // Add plugin here
111+ plugins : [ pinoutIndexPlugin ] ,
111112 entryPoints : [ './src/cli.js' ] ,
112113 outfile : './public/dist/cli.js' ,
113114 platform : 'node' ,
@@ -126,7 +127,6 @@ const browserOptions = {
126127 define : {
127128 global : 'window'
128129 } ,
129- plugins : [ pinoutIndexPlugin ] , // Add plugin here
130130} ;
131131
132132async function build ( ) {
0 commit comments