@plumeria/compiler 0.5.1 → 0.6.1
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/bin/css.mjs +44 -0
- package/package.json +5 -2
- package/src/index.ts +21 -5
package/bin/css.mjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { execSync } from 'child_process';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { styleText } from 'util';
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
|
|
8
|
+
const checkMark = styleText('greenBright', '✓');
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
const isPnpm = fs.existsSync(path.join(process.cwd(), 'node_modules/.pnpm'));
|
|
12
|
+
|
|
13
|
+
const typecheck = process.argv.includes('--type-check');
|
|
14
|
+
if (typecheck)
|
|
15
|
+
execSync('npx tsc --noEmit --incremental false', {
|
|
16
|
+
stdio: 'inherit',
|
|
17
|
+
cwd: process.cwd(),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const plumeriaPath = isPnpm ? findPnpmPlumeriaPath() : path.join(process.cwd(), 'node_modules/@plumeria');
|
|
21
|
+
|
|
22
|
+
const argv = process.argv.includes('--log') ? ' --log' : '';
|
|
23
|
+
execSync('npx tsx compiler/src/index.ts' + argv, {
|
|
24
|
+
stdio: 'inherit',
|
|
25
|
+
cwd: plumeriaPath,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const completed = typecheck ? 'Type-check completed' : '';
|
|
29
|
+
console.log(` ${checkMark} Compiled... ${completed}`);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.error('Compilation failed:', error.message);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function findPnpmPlumeriaPath() {
|
|
36
|
+
const pnpmPath = path.join(process.cwd(), 'node_modules/.pnpm');
|
|
37
|
+
const plumeriaDir = fs.readdirSync(pnpmPath).find(dir => dir.startsWith('@plumeria+compiler@'));
|
|
38
|
+
|
|
39
|
+
if (!plumeriaDir) {
|
|
40
|
+
throw new Error('Could not find @plumeria package in pnpm directory');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return path.join(pnpmPath, plumeriaDir, 'node_modules/@plumeria');
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/compiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Compiler for Plumeria that build and optimizes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -9,13 +9,16 @@
|
|
|
9
9
|
"plumeria",
|
|
10
10
|
"styling"
|
|
11
11
|
],
|
|
12
|
-
"author": "Refirst",
|
|
13
12
|
"repository": "github:zss-in-js/plumeria",
|
|
14
13
|
"license": "MIT",
|
|
15
14
|
"files": [
|
|
15
|
+
"bin",
|
|
16
16
|
"src",
|
|
17
17
|
"tsconfig.json"
|
|
18
18
|
],
|
|
19
|
+
"bin": {
|
|
20
|
+
"css": "./bin/css.mjs"
|
|
21
|
+
},
|
|
19
22
|
"dependencies": {
|
|
20
23
|
"fast-glob": "^3.3.3",
|
|
21
24
|
"postcss": "^8.4.49",
|
package/src/index.ts
CHANGED
|
@@ -10,13 +10,20 @@ import combineSelectors from 'postcss-combine-duplicated-selectors';
|
|
|
10
10
|
|
|
11
11
|
function isCSS(filePath: string): boolean {
|
|
12
12
|
const content = fs.readFileSync(filePath, 'utf8');
|
|
13
|
-
const sourceFile = ts.createSourceFile(
|
|
13
|
+
const sourceFile = ts.createSourceFile(
|
|
14
|
+
filePath,
|
|
15
|
+
content,
|
|
16
|
+
ts.ScriptTarget.Latest,
|
|
17
|
+
true,
|
|
18
|
+
);
|
|
14
19
|
|
|
15
20
|
const checker = (node: ts.Node): boolean => {
|
|
16
21
|
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {
|
|
17
22
|
const expressionText = node.expression.getText(sourceFile);
|
|
18
23
|
const methodName = node.name.getText(sourceFile);
|
|
19
|
-
return
|
|
24
|
+
return (
|
|
25
|
+
expressionText === 'css' && ['create', 'global'].includes(methodName)
|
|
26
|
+
);
|
|
20
27
|
}
|
|
21
28
|
return ts.forEachChild(node, checker) || false;
|
|
22
29
|
};
|
|
@@ -35,7 +42,9 @@ async function optimizeCSS() {
|
|
|
35
42
|
const corePath = path.dirname(require.resolve('@plumeria/core/package.json'));
|
|
36
43
|
const cssPath = path.join(corePath, 'dist/styles/global.css');
|
|
37
44
|
const cssContent = fs.readFileSync(cssPath, 'utf8');
|
|
38
|
-
const result = postcss([
|
|
45
|
+
const result = postcss([
|
|
46
|
+
combineSelectors({ removeDuplicatedProperties: true }),
|
|
47
|
+
]).process(cssContent, {
|
|
39
48
|
from: cssPath,
|
|
40
49
|
to: cssPath,
|
|
41
50
|
});
|
|
@@ -46,10 +55,17 @@ async function optimizeCSS() {
|
|
|
46
55
|
await cleanUp();
|
|
47
56
|
const appRoot = await getAppRoot();
|
|
48
57
|
const files = await fg([path.join(appRoot, '**/*.{js,jsx,ts,tsx}')], {
|
|
49
|
-
ignore: [
|
|
58
|
+
ignore: [
|
|
59
|
+
'**/main.{js,ts}/**',
|
|
60
|
+
'**/dist/**',
|
|
61
|
+
'**/.next/**',
|
|
62
|
+
'**/node_modules/**',
|
|
63
|
+
],
|
|
50
64
|
});
|
|
51
65
|
const styleFiles = files.filter(isCSS);
|
|
52
|
-
const importPromises = styleFiles.map(
|
|
66
|
+
const importPromises = styleFiles.map(
|
|
67
|
+
(styleFile) => import(path.resolve(styleFile)),
|
|
68
|
+
);
|
|
53
69
|
await Promise.all(importPromises);
|
|
54
70
|
|
|
55
71
|
for (let i = 0; i < styleFiles.length; i++) {
|