1- const siteName = "ZeroPoint" ;
2-
31/**
42 * Wait! Before you edit this file!
53 * This Eleventy-based project abstracts the traditional `.eleventy.js` file to help keep things clean and tidy.
@@ -14,198 +12,83 @@ const siteName = "ZeroPoint";
1412 * - `src/config/transforms.js`
1513 */
1614
17- /**
18- * Passthroughs and file copies are defined as named exports in /src/config/passthroughs.js
19- */
20- import passthroughs from './src/config/passthroughs.js' ;
21-
22- /**
23- * Collections are defined as named exports in /src/config/collections.js
24- */
25- import collections from './src/config/collections.js' ;
26-
27- /**
28- * Watch targets are defined as named exports in /src/config/watchtargets.js
29- */
30- import watchtargets from './src/config/watchtargets.js' ;
31-
32- /**
33- * Plugins are defined as named exports in /src/config/plugins.js
34- */
35- import plugins from './src/config/plugins.js' ;
36-
37- /**
38- * Shortcodes are defined as named exports in /src/config/shortcodes.js
39- */
40- import shortcodes from './src/config/shortcodes.js' ;
41-
42- /**
43- * Custom template languages are defined as named exports in /src/config/templateLanguages.js
44- */
45- import templatelanguages from './src/config/templateLanguages.js' ;
46-
47- /**
48- * Filters are defined as named exports in /src/config/filters.js
49- */
50- import filters from './src/config/filters.js' ;
15+ // Node.js imports
16+ import { readFileSync } from 'fs' ;
17+ import { join , dirname } from 'path' ;
18+ import { fileURLToPath } from 'url' ;
5119
52- /**
53- * Import the bundler configuration from /src/config/build.js
54- */
20+ // Local imports
5521import build from './src/config/build.js' ;
5622
57- /**
58- * Import transforms from /src/config/transforms.js
59- */
60- import transforms from './src/config/transforms.js' ;
61-
62- /**
63- * Any additional requirements can be added here
64- */
65- import chalk from 'chalk' ;
66-
67- /**
68- * Eleventy configuration
69- * https://www.11ty.dev/docs/config/
70- */
71- export default function ( eleventyConfig ) {
72-
73- // An array of the tasks to be run, in order, with an icon and a pretty name for each
74- // Put the tasks in the order you want them to run, and set echo to false if you don't want to log the task to the console
75- let tasks = [
76- {
77- icon : "📚" ,
78- name : "Collections" ,
79- config : collections ,
80- echo : true ,
81- } ,
82- {
83- icon : "🔌" ,
84- name : "Plugins" ,
85- config : plugins ,
86- echo : true ,
87- } ,
88- {
89- icon : "⏩" ,
90- name : "Shortcodes" ,
91- config : shortcodes ,
92- echo : true ,
93- } ,
94- {
95- icon : "🎛️ " ,
96- name : "Filters" ,
97- config : filters ,
98- echo : true ,
99- } ,
100- {
101- icon : "🚗" ,
102- name : "Transforms" ,
103- config : transforms ,
104- echo : true ,
105- } ,
106- {
107- icon : "📂" ,
108- name : "Passthroughs" ,
109- config : passthroughs ,
110- echo : false ,
111- } ,
112- {
113- icon : "📜" ,
114- name : "Template Languages" ,
115- config : templatelanguages ,
116- echo : false ,
117- } ,
118- {
119- icon : "👀" ,
120- name : "Watch Targets" ,
121- config : watchtargets ,
122- echo : false ,
123- }
124- ] ;
125-
126- /**
127- * Start pretty console output
128- */
129- console . group ( "\n" , " 🪐" , chalk . magenta ( siteName ) ) ;
130- console . log ( chalk . white ( " │" ) ) ;
131-
132- for ( let task of tasks ) {
133- let tree = tasks . indexOf ( task ) === tasks . length - 1 ;
134-
135- // If the next tasks's echo is false, don't log the tree
136- tree = ( tasks [ tasks . indexOf ( task ) + 1 ] && ! tasks [ tasks . indexOf ( task ) + 1 ] . echo ) ;
137-
138- if ( task . echo ) {
139- console . group (
140- chalk . white ( ( tree ) ? " └── " : " ├── " ) +
141- chalk . yellow ( task . icon ) +
142- chalk . yellow ( " " + task . name ) +
143- chalk . gray ( " (/src/config/" + task . name . toLowerCase ( ) . replace ( / \s / g, '' ) + ".js)" )
144- ) ;
145- }
146-
147- Object . keys ( task . config ) . forEach ( ( taskName , index ) => {
148- let len = Object . keys ( task . config ) . length - 1 ;
149- let pre = ( index === len ? "└── " : "├── " ) ;
150-
151- let branch = tasks . indexOf ( task ) === tasks . length - 1 ;
152- branch = ( tasks [ tasks . indexOf ( task ) + 1 ] && ! tasks [ tasks . indexOf ( task ) + 1 ] . echo ) ;
153- if ( task . echo ) {
154- console . log (
155- chalk . white ( ( branch ) ? " " : "│ " ) + pre +
156- chalk . green ( taskName )
157- ) ;
158- }
159-
160- // Run the task
161- task . config [ taskName ] ( eleventyConfig ) ;
162- } ) ;
163-
164- if ( task . echo ) {
165- if ( ! tree ) {
166- console . log ( chalk . white ( "│" ) ) ;
167- }
168- console . groupEnd ( ) ;
23+ /** ANSI color codes for styling terminal output without external dependencies */
24+ const colors = { yellow : '\x1b[33m' , gray : '\x1b[90m' , white : '\x1b[97m' , magenta : '\x1b[35m' , reset : '\x1b[0m' } ;
25+
26+ /** Registry of all Eleventy configuration modules with display metadata for the tree view */
27+ const tasks = [
28+ { icon : '📚' , name : 'Collections' , path : './src/config/collections.js' } ,
29+ { icon : '🔌' , name : 'Plugins' , path : './src/config/plugins.js' } ,
30+ { icon : '⏩' , name : 'Shortcodes' , path : './src/config/shortcodes.js' } ,
31+ { icon : '🔍' , name : 'Filters ' , path : './src/config/filters.js' } ,
32+ { icon : '🔀' , name : 'Transforms' , path : './src/config/transforms.js' } ,
33+ { icon : '🚚' , name : 'Passthroughs' , path : './src/config/passthroughs.js' } ,
34+ { icon : '📜' , name : 'Template Languages' , path : './src/config/templateLanguages.js' } ,
35+ { icon : '👀' , name : 'Watch Targets' , path : './src/config/watchtargets.js' }
36+ ] ;
37+
38+ /** Reads project name and author from package.json for display in the configuration tree */
39+ const getProjectInfo = ( ) => {
40+ try {
41+ const packageJson = JSON . parse ( readFileSync ( join ( dirname ( fileURLToPath ( import . meta. url ) ) , 'package.json' ) , 'utf8' ) ) ;
42+ return { name : packageJson . name , author : packageJson . author } ;
43+ } catch ( error ) {
44+ throw new Error ( `Failed to read package.json: ${ error . message } ` ) ;
45+ }
46+ } ;
47+
48+ /** Displays a folder tree-style visualization showing which config modules loaded and their functions */
49+ const displayConfigTree = ( loadedTasks , siteName , author ) => {
50+ console . log ( `\n 🪐 ${ colors . magenta } ${ siteName } ${ colors . reset } \n ${ colors . gray } by ${ author } ${ colors . reset } \n ${ colors . gray } │${ colors . reset } ` ) ;
51+ const tasksWithChildren = loadedTasks . filter ( task => Object . keys ( task . config ) . length > 0 ) ;
52+ for ( const task of loadedTasks ) {
53+ const taskNames = Object . keys ( task . config ) ;
54+ if ( taskNames . length > 0 ) {
55+ const isLast = tasksWithChildren . indexOf ( task ) === tasksWithChildren . length - 1 ;
56+ const connector = isLast ? '└──' : '├──' ;
57+ console . log ( ` ${ colors . gray } ${ connector } ${ colors . reset } ${ task . icon } ${ colors . yellow } ${ task . name } ${ colors . reset } ${ colors . gray } (${ task . path . replace ( './' , '/' ) } )${ colors . reset } ` ) ;
58+ taskNames . forEach ( ( taskName , index ) => {
59+ const itemConnector = index === taskNames . length - 1 ? '└──' : '├──' ;
60+ const prefix = isLast ? ' ' : ` ${ colors . gray } │${ colors . reset } ` ;
61+ console . log ( `${ prefix } ${ colors . gray } ${ itemConnector } ●${ colors . reset } ${ colors . white } ${ taskName } ${ colors . reset } ` ) ;
62+ } ) ;
63+ if ( ! isLast ) console . log ( ` ${ colors . gray } │${ colors . reset } ` ) ;
16964 }
17065 }
66+ console . log ( '' ) ;
67+ } ;
68+
69+ /** Main Eleventy configuration function - dynamically loads and executes all config modules */
70+ export default async function ( eleventyConfig ) {
71+ const { name : siteName , author } = getProjectInfo ( ) ;
72+ const loadedTasks = await Promise . all ( tasks . map ( async ( task ) => ( { ...task , config : ( await import ( task . path ) ) . default } ) ) ) ;
73+
74+ // Execute all task configurations
75+ for ( const task of loadedTasks ) {
76+ const taskNames = Object . keys ( task . config ) ;
77+ taskNames . forEach ( taskName => task . config [ taskName ] ( eleventyConfig ) ) ;
78+ }
17179
172- console . log ( "\n" ) ;
173- console . groupEnd ( ) ;
174- /**
175- * End pretty console output
176- */
177-
178-
179- /**
180- * Add build configuration from /src/config/build.js
181- */
80+ displayConfigTree ( loadedTasks , siteName , author ) ;
18281 build ( eleventyConfig ) ;
183-
184-
185- /**
186- * Configure dev server
187- * https://www.11ty.dev/docs/watch-serve/#eleventy-dev-server
188- */
189- eleventyConfig . setServerOptions ( {
190- showAllHosts : true ,
191- } ) ;
192-
193- /**
194- * Enable quiet mode
195- */
82+ eleventyConfig . setServerOptions ( { showAllHosts : false } ) ;
19683 eleventyConfig . setQuietMode ( true ) ;
19784
198- /**
199- * Return the config to Eleventy
200- */
20185 return {
202- dir : {
203- input : "src" ,
204- output : "public" ,
205- includes : 'assets/views' ,
206- layouts : 'assets/views/layouts' ,
207- data : 'data' ,
86+ dir : { input : 'content' ,
87+ output : 'public' ,
88+ includes : '../src/assets/views' ,
89+ layouts : '../src/assets/views/layouts' ,
90+ data : '../src/data'
20891 } ,
209- templateFormats : [ 'njk' , 'md' , '11ty.js' ] ,
92+ templateFormats : [ 'njk' , 'md' , '11ty.js' ]
21093 } ;
21194}
0 commit comments