@@ -20,10 +20,23 @@ const path = require("path");
20
20
const fg = require ( "fast-glob" ) ;
21
21
22
22
const { processCSS } = require ( "../../tasks/component-builder.js" ) ;
23
- const { copy , fetchContent } = require ( "../../tasks/utilities.js" ) ;
23
+ const { fetchContent } = require ( "../../tasks/utilities.js" ) ;
24
24
25
25
require ( "colors" ) ;
26
26
27
+ /**
28
+ * Create a tagline for the CSS file based on the package.json data
29
+ * @param {Object } [packageJson={}]
30
+ * @param {string } packageJson.name
31
+ * @param {string } packageJson.version
32
+ * @returns
33
+ */
34
+ function generateTagline ( { name, version } = { } ) {
35
+ if ( ! name ) return "" ;
36
+ if ( ! version ) return `/* ${ name } */\n\n` ;
37
+ return `/* ${ name } @v${ version } */\n\n` ;
38
+ }
39
+
27
40
/**
28
41
* The builder for the main entry point
29
42
* @param {object } config
@@ -44,7 +57,14 @@ async function index(inputGlob, outputPath, { cwd = process.cwd(), clean = false
44
57
const contents = inputs . map ( input => `@import "${ input } ";` ) . join ( "\n" ) ;
45
58
if ( ! contents ) return ;
46
59
47
- return processCSS ( contents , undefined , outputPath , { cwd, clean, configPath : cwd , map : false , resolveImports : true , customTagline : `/* Token version: v${ packageJson . version } */\n\n` } ) ;
60
+ return processCSS ( contents , undefined , outputPath , {
61
+ cwd,
62
+ clean,
63
+ configPath : cwd ,
64
+ map : false ,
65
+ resolveImports : true ,
66
+ customTagline : generateTagline ( packageJson ) ,
67
+ } ) ;
48
68
}
49
69
50
70
/**
@@ -53,7 +73,7 @@ async function index(inputGlob, outputPath, { cwd = process.cwd(), clean = false
53
73
* @param {string } [config.cwd=process.cwd()] - Current working directory for the component
54
74
* @returns {Promise<string[]> }
55
75
*/
56
- async function appendCustomOverrides ( { cwd = process . cwd ( ) } = { } ) {
76
+ async function appendCustomOverrides ( { cwd = process . cwd ( ) , packageJson = { } } = { } ) {
57
77
const promises = [ ] ;
58
78
59
79
// Add custom/*-vars.css to the end of the dist/css/*-vars.css files and run through postcss before writing back to the dist/css/*-vars.css file
@@ -75,6 +95,7 @@ async function appendCustomOverrides({ cwd = process.cwd() } = {}) {
75
95
processCSS ( combinedContent [ 0 ] . content , path . join ( cwd , "dist" , "css" , file ) , path . join ( cwd , "dist" , "css" , file ) , {
76
96
cwd,
77
97
configPath : cwd ,
98
+ customTagline : generateTagline ( packageJson ) ,
78
99
} )
79
100
) ;
80
101
}
@@ -103,16 +124,17 @@ async function main({
103
124
104
125
const compiledOutputPath = path . join ( cwd , "dist" ) ;
105
126
127
+ // Read in the package version from the package.json file
128
+ const packageJson = await fsp . readFile ( path . join ( cwd , "package.json" ) , "utf-8" ) . then ( JSON . parse ) ;
129
+
106
130
// Wait for all the custom files to be processed
107
- return appendCustomOverrides ( { cwd } ) . then ( async ( r ) =>
131
+ return appendCustomOverrides ( { packageJson , cwd } ) . then ( async ( r ) =>
108
132
Promise . all ( [
109
133
index (
110
134
[ "dist/css/*-vars.css" ] ,
111
135
path . join ( compiledOutputPath , "css" , "index.css" ) ,
112
- { cwd, clean }
113
- ) . then ( ( reports ) =>
114
- copy ( path . join ( compiledOutputPath , "css" , "index.css" ) , path . join ( cwd , "dist" , "index.css" ) , { cwd, isDeprecated : false } )
115
- . then ( ( reps ) => [ reports , reps ] ) )
136
+ { cwd, clean, packageJson }
137
+ )
116
138
] ) . then ( ( reports ) => {
117
139
const logs = [ reports , r ] . flat ( Infinity ) . filter ( Boolean ) ;
118
140
0 commit comments