-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
executable file
·73 lines (66 loc) · 1.89 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const plugin = require('tailwindcss/plugin');
module.exports = plugin.withOptions(
function () {
// Use an empty plugin function to accept the options object.
return function () {};
},
function (themejson) {
// If the theme.json object is not provided, attempt to load it.
if (typeof themejson !== 'object' || themejson === null) {
const fs = require('fs');
const path = require('path');
let themejsonPath;
if (typeof themejson === 'string') {
// If `themejson` is a string, use it as the path to the theme.json
// file relative to the current working directory.
themejsonPath = path.join(process.cwd(), themejson);
} else {
// Otherwise, use the default path from _tw.
themejsonPath = path.join(process.cwd(), 'theme/theme.json');
}
if (fs.existsSync(themejsonPath)) {
try {
themejson = JSON.parse(
fs.readFileSync(themejsonPath, 'utf8')
);
} catch (e) {
// Handle JSON parsing error.
console.error('Error parsing JSON:', e);
return false;
}
} else {
return false;
}
}
// Create an empty object for the theme.json properties.
const themejsonProps = {};
// Load all of the colors from the theme.json file.
if (Array.isArray(themejson.settings.color.palette)) {
themejsonProps.colors = {};
themejson.settings.color.palette.forEach(function (color) {
themejsonProps.colors[color.slug] = color.color;
});
}
// Load all of the widths from the theme.json file.
themejsonProps.widths = {};
['content', 'wide'].forEach(function (width) {
if (undefined !== themejson.settings.layout[width + 'Size']) {
themejsonProps.widths[width] =
themejson.settings.layout[width + 'Size'];
}
});
// Update the configuration.
return {
theme: {
extend: {
colors: {
...themejsonProps.colors,
},
maxWidth: {
...themejsonProps.widths,
},
},
},
};
}
);