@moondreamsdev/dreamer-ui 1.3.4 ā 1.3.5
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/postinstall.js +150 -0
- package/package.json +5 -4
- package/scripts/postinstall.js +150 -0
@@ -0,0 +1,150 @@
|
|
1
|
+
const fs = require('fs');
|
2
|
+
const path = require('path');
|
3
|
+
const readline = require('readline');
|
4
|
+
|
5
|
+
function extractColorsFromSource() {
|
6
|
+
try {
|
7
|
+
const sourceFile = path.join(__dirname, '../src/styles.lib.css');
|
8
|
+
const sourceContent = fs.readFileSync(sourceFile, 'utf8');
|
9
|
+
|
10
|
+
// Extract the @theme colors block
|
11
|
+
const themeMatch = sourceContent.match(/@theme colors \{([\s\S]*?)\}/);
|
12
|
+
|
13
|
+
if (themeMatch) {
|
14
|
+
const themeContent = themeMatch[1];
|
15
|
+
return `:root {${themeContent}}`;
|
16
|
+
} else {
|
17
|
+
throw new Error('Could not find @theme colors block in source file');
|
18
|
+
}
|
19
|
+
} catch (error) {
|
20
|
+
console.error('ā Error reading source file:', error.message);
|
21
|
+
process.exit(1);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
function createCSSFile(targetPath, cssContent) {
|
26
|
+
try {
|
27
|
+
// Check if file already exists
|
28
|
+
if (fs.existsSync(targetPath)) {
|
29
|
+
console.log(`š CSS file already exists at: ${targetPath}`);
|
30
|
+
|
31
|
+
// Ask user if they want to overwrite (only in interactive mode)
|
32
|
+
const isCI = process.env.CI || process.env.NODE_ENV === 'production' || !process.stdin.isTTY;
|
33
|
+
|
34
|
+
if (!isCI) {
|
35
|
+
const rl = readline.createInterface({
|
36
|
+
input: process.stdin,
|
37
|
+
output: process.stdout
|
38
|
+
});
|
39
|
+
|
40
|
+
return new Promise((resolve) => {
|
41
|
+
rl.question('Do you want to overwrite it? (y/N): ', (answer) => {
|
42
|
+
rl.close();
|
43
|
+
if (answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes') {
|
44
|
+
writeFile();
|
45
|
+
} else {
|
46
|
+
console.log('āļø Skipping CSS generation');
|
47
|
+
}
|
48
|
+
resolve();
|
49
|
+
});
|
50
|
+
});
|
51
|
+
} else {
|
52
|
+
// In CI, skip overwriting
|
53
|
+
console.log('āļø Skipping CSS generation (file exists)');
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
writeFile();
|
59
|
+
|
60
|
+
function writeFile() {
|
61
|
+
// Ensure target directory exists
|
62
|
+
const targetDir = path.dirname(targetPath);
|
63
|
+
if (!fs.existsSync(targetDir)) {
|
64
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
65
|
+
}
|
66
|
+
|
67
|
+
// Write the CSS file
|
68
|
+
fs.writeFileSync(targetPath, cssContent);
|
69
|
+
console.log(`ā
Generated dreamer-ui colors at: ${targetPath}`);
|
70
|
+
}
|
71
|
+
} catch (error) {
|
72
|
+
console.error('ā Error writing CSS file:', error.message);
|
73
|
+
process.exit(1);
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
function getDefaultPath() {
|
78
|
+
// Look for common CSS directories
|
79
|
+
const possiblePaths = [
|
80
|
+
'./src/styles/dreamer-ui-colors.css',
|
81
|
+
'./styles/dreamer-ui-colors.css',
|
82
|
+
'./css/dreamer-ui-colors.css',
|
83
|
+
'./src/dreamer-ui-colors.css',
|
84
|
+
'./dreamer-ui-colors.css'
|
85
|
+
];
|
86
|
+
|
87
|
+
for (const p of possiblePaths) {
|
88
|
+
const dir = path.dirname(p);
|
89
|
+
if (fs.existsSync(dir)) {
|
90
|
+
return p;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
return './dreamer-ui-colors.css';
|
95
|
+
}
|
96
|
+
|
97
|
+
async function promptUserForPath() {
|
98
|
+
const rl = readline.createInterface({
|
99
|
+
input: process.stdin,
|
100
|
+
output: process.stdout
|
101
|
+
});
|
102
|
+
|
103
|
+
const defaultPath = getDefaultPath();
|
104
|
+
|
105
|
+
return new Promise((resolve) => {
|
106
|
+
rl.question(
|
107
|
+
`Where would you like to save the Dreamer UI colors CSS file? (default: ${defaultPath}): `,
|
108
|
+
(answer) => {
|
109
|
+
rl.close();
|
110
|
+
resolve(answer.trim() || defaultPath);
|
111
|
+
}
|
112
|
+
);
|
113
|
+
});
|
114
|
+
}
|
115
|
+
|
116
|
+
async function main() {
|
117
|
+
console.log('šØ Setting up Dreamer UI colors...');
|
118
|
+
|
119
|
+
// Check if running in CI or non-interactive environment
|
120
|
+
const isCI = process.env.CI || process.env.NODE_ENV === 'production' || !process.stdin.isTTY;
|
121
|
+
|
122
|
+
let targetPath;
|
123
|
+
|
124
|
+
if (isCI) {
|
125
|
+
// In CI/non-interactive, use default path
|
126
|
+
targetPath = getDefaultPath();
|
127
|
+
console.log(`š Using default path: ${targetPath}`);
|
128
|
+
} else {
|
129
|
+
// Interactive mode
|
130
|
+
targetPath = await promptUserForPath();
|
131
|
+
}
|
132
|
+
|
133
|
+
// Generate CSS content
|
134
|
+
const cssContent = extractColorsFromSource();
|
135
|
+
|
136
|
+
// Create the file
|
137
|
+
createCSSFile(targetPath, cssContent);
|
138
|
+
|
139
|
+
console.log('\nš To use the colors, import the CSS file in your project:');
|
140
|
+
console.log(` @import '${targetPath}';`);
|
141
|
+
console.log(' or');
|
142
|
+
console.log(` import '${targetPath}';`);
|
143
|
+
}
|
144
|
+
|
145
|
+
// Run if called directly
|
146
|
+
if (require.main === module) {
|
147
|
+
main().catch(console.error);
|
148
|
+
}
|
149
|
+
|
150
|
+
module.exports = main;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@moondreamsdev/dreamer-ui",
|
3
|
-
"version": "1.3.
|
3
|
+
"version": "1.3.5",
|
4
4
|
"type": "module",
|
5
5
|
"description": "A collection of Tailwind CSS components for React",
|
6
6
|
"main": "dist/index.js",
|
@@ -8,7 +8,7 @@
|
|
8
8
|
"types": "dist/index.lib.d.ts",
|
9
9
|
"files": [
|
10
10
|
"dist",
|
11
|
-
"scripts
|
11
|
+
"scripts"
|
12
12
|
],
|
13
13
|
"exports": {
|
14
14
|
".": {
|
@@ -38,13 +38,14 @@
|
|
38
38
|
},
|
39
39
|
"scripts": {
|
40
40
|
"dev": "vite",
|
41
|
-
"build": "npm run build:lib && npm run build:types",
|
41
|
+
"build": "npm run build:lib && npm run build:types && npm run build:scripts",
|
42
42
|
"build:lib": "vite build --config vite.config.lib.mts",
|
43
43
|
"build:types": "tsc --project tsconfig.lib.json",
|
44
44
|
"build:demo": "tsc -b && vite build",
|
45
|
+
"build:scripts": "cp scripts/* dist/",
|
45
46
|
"lint": "eslint .",
|
46
47
|
"preview": "vite preview",
|
47
|
-
"postinstall": "node
|
48
|
+
"postinstall": "node postinstall.js",
|
48
49
|
"prepublishOnly": "npm run build",
|
49
50
|
"publish": "npm publish --access public"
|
50
51
|
},
|
@@ -0,0 +1,150 @@
|
|
1
|
+
const fs = require('fs');
|
2
|
+
const path = require('path');
|
3
|
+
const readline = require('readline');
|
4
|
+
|
5
|
+
function extractColorsFromSource() {
|
6
|
+
try {
|
7
|
+
const sourceFile = path.join(__dirname, '../src/styles.lib.css');
|
8
|
+
const sourceContent = fs.readFileSync(sourceFile, 'utf8');
|
9
|
+
|
10
|
+
// Extract the @theme colors block
|
11
|
+
const themeMatch = sourceContent.match(/@theme colors \{([\s\S]*?)\}/);
|
12
|
+
|
13
|
+
if (themeMatch) {
|
14
|
+
const themeContent = themeMatch[1];
|
15
|
+
return `:root {${themeContent}}`;
|
16
|
+
} else {
|
17
|
+
throw new Error('Could not find @theme colors block in source file');
|
18
|
+
}
|
19
|
+
} catch (error) {
|
20
|
+
console.error('ā Error reading source file:', error.message);
|
21
|
+
process.exit(1);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
function createCSSFile(targetPath, cssContent) {
|
26
|
+
try {
|
27
|
+
// Check if file already exists
|
28
|
+
if (fs.existsSync(targetPath)) {
|
29
|
+
console.log(`š CSS file already exists at: ${targetPath}`);
|
30
|
+
|
31
|
+
// Ask user if they want to overwrite (only in interactive mode)
|
32
|
+
const isCI = process.env.CI || process.env.NODE_ENV === 'production' || !process.stdin.isTTY;
|
33
|
+
|
34
|
+
if (!isCI) {
|
35
|
+
const rl = readline.createInterface({
|
36
|
+
input: process.stdin,
|
37
|
+
output: process.stdout
|
38
|
+
});
|
39
|
+
|
40
|
+
return new Promise((resolve) => {
|
41
|
+
rl.question('Do you want to overwrite it? (y/N): ', (answer) => {
|
42
|
+
rl.close();
|
43
|
+
if (answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes') {
|
44
|
+
writeFile();
|
45
|
+
} else {
|
46
|
+
console.log('āļø Skipping CSS generation');
|
47
|
+
}
|
48
|
+
resolve();
|
49
|
+
});
|
50
|
+
});
|
51
|
+
} else {
|
52
|
+
// In CI, skip overwriting
|
53
|
+
console.log('āļø Skipping CSS generation (file exists)');
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
writeFile();
|
59
|
+
|
60
|
+
function writeFile() {
|
61
|
+
// Ensure target directory exists
|
62
|
+
const targetDir = path.dirname(targetPath);
|
63
|
+
if (!fs.existsSync(targetDir)) {
|
64
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
65
|
+
}
|
66
|
+
|
67
|
+
// Write the CSS file
|
68
|
+
fs.writeFileSync(targetPath, cssContent);
|
69
|
+
console.log(`ā
Generated dreamer-ui colors at: ${targetPath}`);
|
70
|
+
}
|
71
|
+
} catch (error) {
|
72
|
+
console.error('ā Error writing CSS file:', error.message);
|
73
|
+
process.exit(1);
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
function getDefaultPath() {
|
78
|
+
// Look for common CSS directories
|
79
|
+
const possiblePaths = [
|
80
|
+
'./src/styles/dreamer-ui-colors.css',
|
81
|
+
'./styles/dreamer-ui-colors.css',
|
82
|
+
'./css/dreamer-ui-colors.css',
|
83
|
+
'./src/dreamer-ui-colors.css',
|
84
|
+
'./dreamer-ui-colors.css'
|
85
|
+
];
|
86
|
+
|
87
|
+
for (const p of possiblePaths) {
|
88
|
+
const dir = path.dirname(p);
|
89
|
+
if (fs.existsSync(dir)) {
|
90
|
+
return p;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
return './dreamer-ui-colors.css';
|
95
|
+
}
|
96
|
+
|
97
|
+
async function promptUserForPath() {
|
98
|
+
const rl = readline.createInterface({
|
99
|
+
input: process.stdin,
|
100
|
+
output: process.stdout
|
101
|
+
});
|
102
|
+
|
103
|
+
const defaultPath = getDefaultPath();
|
104
|
+
|
105
|
+
return new Promise((resolve) => {
|
106
|
+
rl.question(
|
107
|
+
`Where would you like to save the Dreamer UI colors CSS file? (default: ${defaultPath}): `,
|
108
|
+
(answer) => {
|
109
|
+
rl.close();
|
110
|
+
resolve(answer.trim() || defaultPath);
|
111
|
+
}
|
112
|
+
);
|
113
|
+
});
|
114
|
+
}
|
115
|
+
|
116
|
+
async function main() {
|
117
|
+
console.log('šØ Setting up Dreamer UI colors...');
|
118
|
+
|
119
|
+
// Check if running in CI or non-interactive environment
|
120
|
+
const isCI = process.env.CI || process.env.NODE_ENV === 'production' || !process.stdin.isTTY;
|
121
|
+
|
122
|
+
let targetPath;
|
123
|
+
|
124
|
+
if (isCI) {
|
125
|
+
// In CI/non-interactive, use default path
|
126
|
+
targetPath = getDefaultPath();
|
127
|
+
console.log(`š Using default path: ${targetPath}`);
|
128
|
+
} else {
|
129
|
+
// Interactive mode
|
130
|
+
targetPath = await promptUserForPath();
|
131
|
+
}
|
132
|
+
|
133
|
+
// Generate CSS content
|
134
|
+
const cssContent = extractColorsFromSource();
|
135
|
+
|
136
|
+
// Create the file
|
137
|
+
createCSSFile(targetPath, cssContent);
|
138
|
+
|
139
|
+
console.log('\nš To use the colors, import the CSS file in your project:');
|
140
|
+
console.log(` @import '${targetPath}';`);
|
141
|
+
console.log(' or');
|
142
|
+
console.log(` import '${targetPath}';`);
|
143
|
+
}
|
144
|
+
|
145
|
+
// Run if called directly
|
146
|
+
if (require.main === module) {
|
147
|
+
main().catch(console.error);
|
148
|
+
}
|
149
|
+
|
150
|
+
module.exports = main;
|