emily-css 1.0.9 → 1.0.15
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/CHANGELOG.md +159 -0
- package/README.md +64 -222
- package/bin/emilyui.js +32 -6
- package/package.json +55 -49
- package/src/generators.js +34 -1
- package/src/index.js +64 -23
- package/src/init.js +240 -198
- package/src/showcase.js +90 -0
package/src/showcase.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
const http = require('http');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const { exec } = require('child_process');
|
|
9
|
+
|
|
10
|
+
const PORT = 3456;
|
|
11
|
+
const ROOT = process.cwd();
|
|
12
|
+
|
|
13
|
+
const MIME = {
|
|
14
|
+
'.html': 'text/html; charset=utf-8',
|
|
15
|
+
'.css': 'text/css',
|
|
16
|
+
'.js': 'application/javascript',
|
|
17
|
+
'.png': 'image/png',
|
|
18
|
+
'.jpg': 'image/jpeg',
|
|
19
|
+
'.svg': 'image/svg+xml',
|
|
20
|
+
'.ico': 'image/x-icon',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Ensure CSS is built before serving
|
|
24
|
+
const cssPath = path.join(ROOT, 'dist/emily.min.css');
|
|
25
|
+
if (!fs.existsSync(cssPath)) {
|
|
26
|
+
console.log(' Building CSS first...\n');
|
|
27
|
+
require('./index.js').build({ keepFull: true });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const server = http.createServer((req, res) => {
|
|
31
|
+
let urlPath = req.url.split('?')[0]; // strip query strings
|
|
32
|
+
if (urlPath === '/') urlPath = '/showcase.html';
|
|
33
|
+
|
|
34
|
+
const filePath = path.join(ROOT, urlPath);
|
|
35
|
+
|
|
36
|
+
// Safety: don't serve files outside ROOT
|
|
37
|
+
if (!filePath.startsWith(ROOT)) {
|
|
38
|
+
res.writeHead(403);
|
|
39
|
+
res.end('Forbidden');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
fs.readFile(filePath, (err, data) => {
|
|
44
|
+
if (err) {
|
|
45
|
+
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
46
|
+
res.end(`Not found: ${urlPath}`);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
51
|
+
const mime = MIME[ext] || 'text/plain';
|
|
52
|
+
|
|
53
|
+
res.writeHead(200, { 'Content-Type': mime });
|
|
54
|
+
res.end(data);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
server.listen(PORT, '127.0.0.1', () => {
|
|
59
|
+
const url = `http://localhost:${PORT}`;
|
|
60
|
+
|
|
61
|
+
console.log('');
|
|
62
|
+
console.log(' emilyCSS showcase');
|
|
63
|
+
console.log(' ' + '─'.repeat(30));
|
|
64
|
+
console.log(` Local: ${url}`);
|
|
65
|
+
console.log('');
|
|
66
|
+
console.log(' Press Ctrl+C to stop');
|
|
67
|
+
console.log('');
|
|
68
|
+
|
|
69
|
+
// Open in default browser
|
|
70
|
+
const openCmd =
|
|
71
|
+
process.platform === 'win32' ? `start "" "${url}"` :
|
|
72
|
+
process.platform === 'darwin' ? `open "${url}"` :
|
|
73
|
+
`xdg-open "${url}"`;
|
|
74
|
+
|
|
75
|
+
exec(openCmd, (err) => {
|
|
76
|
+
if (err) {
|
|
77
|
+
console.log(` Could not open browser automatically.`);
|
|
78
|
+
console.log(` Open manually: ${url}\n`);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
server.on('error', (err) => {
|
|
84
|
+
if (err.code === 'EADDRINUSE') {
|
|
85
|
+
console.error(`\n Port ${PORT} is already in use. Stop the other process and try again.\n`);
|
|
86
|
+
} else {
|
|
87
|
+
console.error('\n Server error:', err.message, '\n');
|
|
88
|
+
}
|
|
89
|
+
process.exit(1);
|
|
90
|
+
});
|