@plumeria/compiler 0.2.0 → 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/package.json +4 -8
- package/src/index.ts +25 -5
- package/bin/css.mjs +0 -44
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/compiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Compiler for Plumeria that build and optimizes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -13,12 +13,11 @@
|
|
|
13
13
|
"repository": "github:zss-in-js/plumeria",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"files": [
|
|
16
|
-
"bin",
|
|
17
16
|
"src",
|
|
18
17
|
"tsconfig.json"
|
|
19
18
|
],
|
|
20
|
-
"
|
|
21
|
-
"
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "echo 'No build necessary'"
|
|
22
21
|
},
|
|
23
22
|
"dependencies": {
|
|
24
23
|
"fast-glob": "^3.3.3",
|
|
@@ -28,8 +27,5 @@
|
|
|
28
27
|
},
|
|
29
28
|
"publishConfig": {
|
|
30
29
|
"access": "public"
|
|
31
|
-
},
|
|
32
|
-
"scripts": {
|
|
33
|
-
"build": "echo 'No build necessary'"
|
|
34
30
|
}
|
|
35
|
-
}
|
|
31
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,24 @@ import { buildGlobal } from '@plumeria/core/dist/method/global-build-helper.js';
|
|
|
8
8
|
import postcss from 'postcss';
|
|
9
9
|
import combineSelectors from 'postcss-combine-duplicated-selectors';
|
|
10
10
|
|
|
11
|
+
function findUp(filename: string, startDir = __dirname) {
|
|
12
|
+
let dir = path.resolve(startDir);
|
|
13
|
+
|
|
14
|
+
while (true) {
|
|
15
|
+
const filePath = path.join(dir, filename);
|
|
16
|
+
if (fs.existsSync(filePath)) {
|
|
17
|
+
return filePath;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const parentDir = path.dirname(dir);
|
|
21
|
+
if (dir === parentDir) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
dir = parentDir;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
11
29
|
function isCSS(filePath: string): boolean {
|
|
12
30
|
const content = fs.readFileSync(filePath, 'utf8');
|
|
13
31
|
const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
|
|
@@ -24,11 +42,13 @@ function isCSS(filePath: string): boolean {
|
|
|
24
42
|
return checker(sourceFile);
|
|
25
43
|
}
|
|
26
44
|
|
|
27
|
-
async function getAppRoot()
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
45
|
+
async function getAppRoot() {
|
|
46
|
+
const packageJsonPath = findUp('package.json', __dirname);
|
|
47
|
+
if (packageJsonPath) {
|
|
48
|
+
return path.dirname(packageJsonPath);
|
|
49
|
+
} else {
|
|
50
|
+
throw new Error('Project root directory not found');
|
|
51
|
+
}
|
|
32
52
|
}
|
|
33
53
|
|
|
34
54
|
async function optimizeCSS() {
|
package/bin/css.mjs
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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
|
-
// In the monorepo repository pnpm the right side is executed
|
|
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+core@'));
|
|
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
|
-
}
|