esm-styles 0.2.7 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/build.js +21 -6
- package/package.json +1 -1
package/dist/lib/build.js
CHANGED
|
@@ -24,7 +24,7 @@ export async function build(configPath = 'esm-styles.config.js') {
|
|
|
24
24
|
const mainCssFile = config.mainCssFile || 'styles.css';
|
|
25
25
|
// Helper function to generate CSS comment header
|
|
26
26
|
const generateCssComment = (sourceName) => {
|
|
27
|
-
const normalizedBasePath = (config.basePath || '.').replace(
|
|
27
|
+
const normalizedBasePath = (config.basePath || '.').replace(/^\.*\//, '');
|
|
28
28
|
const sourceFilePath = path.join(normalizedBasePath, config.sourcePath || '', `${sourceName}${suffix}`);
|
|
29
29
|
return `/* This CSS was automatically generated from ${sourceFilePath}, do not edit directly */\n`;
|
|
30
30
|
};
|
|
@@ -177,9 +177,15 @@ export async function build(configPath = 'esm-styles.config.js') {
|
|
|
177
177
|
// Track output files for each floor
|
|
178
178
|
const floorFiles = [];
|
|
179
179
|
for (const floor of floors) {
|
|
180
|
-
const { source, layer } = floor;
|
|
180
|
+
const { source, layer, outputPath: floorOutputPath } = floor;
|
|
181
181
|
const inputFile = path.join(sourcePath, `${source}${suffix}`);
|
|
182
|
-
|
|
182
|
+
// Use floor's outputPath if provided, otherwise use default
|
|
183
|
+
const floorOutputDir = floorOutputPath
|
|
184
|
+
? path.join(basePath, floorOutputPath)
|
|
185
|
+
: outputPath;
|
|
186
|
+
// Ensure the output directory exists
|
|
187
|
+
await fs.mkdir(floorOutputDir, { recursive: true });
|
|
188
|
+
const outputFile = path.join(floorOutputDir, `${source}.css`);
|
|
183
189
|
const fileUrl = pathToFileUrl(inputFile).href + `?update=${Date.now()}`;
|
|
184
190
|
const stylesObj = (await import(fileUrl)).default;
|
|
185
191
|
const css = getCss(stylesObj, {
|
|
@@ -196,8 +202,17 @@ export async function build(configPath = 'esm-styles.config.js') {
|
|
|
196
202
|
wrappedCss = `${comment}@layer ${layer} {\n${css}\n}`;
|
|
197
203
|
}
|
|
198
204
|
await fs.writeFile(outputFile, wrappedCss, 'utf8');
|
|
199
|
-
|
|
200
|
-
|
|
205
|
+
// Calculate relative path from default output directory for imports
|
|
206
|
+
const relativePath = floorOutputPath
|
|
207
|
+
? path.relative(outputPath, outputFile)
|
|
208
|
+
: `${source}.css`;
|
|
209
|
+
floorFiles.push({
|
|
210
|
+
file: relativePath,
|
|
211
|
+
layer,
|
|
212
|
+
source,
|
|
213
|
+
outputPath: floorOutputPath,
|
|
214
|
+
});
|
|
215
|
+
cssFiles.push({ floor: source, file: relativePath, layer });
|
|
201
216
|
}
|
|
202
217
|
// 5. Create main CSS file
|
|
203
218
|
const mainCssPath = path.join(outputPath, mainCssFile);
|
|
@@ -224,7 +239,7 @@ export async function build(configPath = 'esm-styles.config.js') {
|
|
|
224
239
|
}
|
|
225
240
|
const importedFloorFiles = floorFiles.filter(isImportedFloor);
|
|
226
241
|
const floorImports = importedFloorFiles.map(importStatement).join('\n');
|
|
227
|
-
const normalizedBasePath = (config.basePath || '.').replace(
|
|
242
|
+
const normalizedBasePath = (config.basePath || '.').replace(/^\.*\//, '');
|
|
228
243
|
const mainCssComment = `/* This CSS was automatically generated as the main styles file from ${normalizedBasePath}, do not edit directly */\n`;
|
|
229
244
|
const mainCss = mainCssComment +
|
|
230
245
|
[
|