@plumeria/compiler 0.1.1 → 0.2.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/LICENSE +21 -0
- package/bin/css.mjs +44 -0
- package/package.json +17 -3
- package/src/index.ts +9 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 zss-in-js contributer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
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
|
+
// 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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/compiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Compiler for Plumeria that build and optimizes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -12,10 +12,24 @@
|
|
|
12
12
|
"author": "Refirst",
|
|
13
13
|
"repository": "github:zss-in-js/plumeria",
|
|
14
14
|
"license": "MIT",
|
|
15
|
+
"files": [
|
|
16
|
+
"bin",
|
|
17
|
+
"src",
|
|
18
|
+
"tsconfig.json"
|
|
19
|
+
],
|
|
20
|
+
"bin": {
|
|
21
|
+
"css": "./bin/css.mjs"
|
|
22
|
+
},
|
|
15
23
|
"dependencies": {
|
|
16
|
-
"
|
|
24
|
+
"fast-glob": "^3.3.3",
|
|
17
25
|
"postcss": "^8.4.49",
|
|
18
26
|
"postcss-combine-duplicated-selectors": "^10.0.3",
|
|
19
27
|
"tsx": "^4.19.2"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "echo 'No build necessary'"
|
|
20
34
|
}
|
|
21
|
-
}
|
|
35
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import ts from 'typescript';
|
|
4
|
-
import
|
|
4
|
+
import fg from 'fast-glob';
|
|
5
5
|
import { cleanUp } from './clean-up';
|
|
6
6
|
import { buildCreate } from '@plumeria/core/dist/method/create-build-helper.js';
|
|
7
7
|
import { buildGlobal } from '@plumeria/core/dist/method/global-build-helper.js';
|
|
@@ -26,21 +26,26 @@ function isCSS(filePath: string): boolean {
|
|
|
26
26
|
|
|
27
27
|
async function getAppRoot(): Promise<string> {
|
|
28
28
|
const threeLevelsUp = path.join(process.cwd(), '../../../../..');
|
|
29
|
-
return fs.existsSync(path.join(threeLevelsUp, 'node_modules/.pnpm'))
|
|
29
|
+
return fs.existsSync(path.join(threeLevelsUp, 'node_modules/.pnpm'))
|
|
30
|
+
? path.join(process.cwd(), '../../../../../')
|
|
31
|
+
: path.join(process.cwd(), '../../');
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
async function optimizeCSS() {
|
|
33
35
|
const corePath = path.dirname(require.resolve('@plumeria/core/package.json'));
|
|
34
36
|
const cssPath = path.join(corePath, 'dist/styles/global.css');
|
|
35
37
|
const cssContent = fs.readFileSync(cssPath, 'utf8');
|
|
36
|
-
const result = postcss([combineSelectors({ removeDuplicatedProperties: true })]).process(cssContent, {
|
|
38
|
+
const result = postcss([combineSelectors({ removeDuplicatedProperties: true })]).process(cssContent, {
|
|
39
|
+
from: cssPath,
|
|
40
|
+
to: cssPath,
|
|
41
|
+
});
|
|
37
42
|
fs.writeFileSync(cssPath, result.css);
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
(async () => {
|
|
41
46
|
await cleanUp();
|
|
42
47
|
const appRoot = await getAppRoot();
|
|
43
|
-
const files = await
|
|
48
|
+
const files = await fg([path.join(appRoot, '**/*.{js,jsx,ts,tsx}')], {
|
|
44
49
|
ignore: ['**/main.{js,ts}/**', '**/dist/**', '**/.next/**', '**/node_modules/**'],
|
|
45
50
|
});
|
|
46
51
|
const styleFiles = files.filter(isCSS);
|