@plumeria/compiler 0.1.0 → 0.1.2

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 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/compiler",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Compiler for Plumeria that build and optimizes",
5
5
  "keywords": [
6
6
  "react",
@@ -12,10 +12,20 @@
12
12
  "author": "Refirst",
13
13
  "repository": "github:zss-in-js/plumeria",
14
14
  "license": "MIT",
15
+ "files": [
16
+ "src",
17
+ "tsconfig.json"
18
+ ],
15
19
  "dependencies": {
16
- "globby": "^14.0.2",
20
+ "fast-glob": "^3.3.3",
17
21
  "postcss": "^8.4.49",
18
22
  "postcss-combine-duplicated-selectors": "^10.0.3",
19
23
  "tsx": "^4.19.2"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "scripts": {
29
+ "build": "echo 'No build necessary'"
20
30
  }
21
- }
31
+ }
package/src/clean-up.ts CHANGED
@@ -1,13 +1,17 @@
1
- import { writeFileSync } from "fs";
2
- import { join } from "path";
1
+ import { writeFileSync } from 'fs';
2
+ import path from 'path';
3
3
 
4
4
  export const cleanUp = async () => {
5
- const createFilePath = join(__dirname, "../../core/dist/styles/create.css");
6
- const globalFilePath = join(__dirname, "../../core/dist/styles/global.css");
5
+ const projectRoot = process.cwd().split('node_modules')[0];
6
+ const directPath = path.join(projectRoot, 'node_modules/@plumeria/core');
7
+
8
+ const createFilePath = directPath + '/dist/styles/create.css';
9
+ const globalFilePath = directPath + '/dist/styles/global.css';
10
+
7
11
  try {
8
- writeFileSync(createFilePath, "", "utf-8");
9
- writeFileSync(globalFilePath, "", "utf-8");
12
+ writeFileSync(createFilePath, '', 'utf-8');
13
+ writeFileSync(globalFilePath, '', 'utf-8');
10
14
  } catch (err) {
11
- console.error("An error occurred:", err);
15
+ console.error('An error occurred:', err);
12
16
  }
13
17
  };
package/src/index.ts CHANGED
@@ -1,29 +1,22 @@
1
- import * as path from "path";
2
- import * as fs from "fs";
3
- import ts from "typescript";
4
- import { globby } from "globby";
5
- import { cleanUp } from "./clean-up";
6
- import { buildCreate } from "../../core/dist/method/create-build-helper.js";
7
- import { buildGlobal } from "../../core/dist/method/global-build-helper.js";
8
- import postcss from "postcss";
9
- import combineSelectors from "postcss-combine-duplicated-selectors";
1
+ import * as path from 'path';
2
+ import * as fs from 'fs';
3
+ import ts from 'typescript';
4
+ import fg from 'fast-glob';
5
+ import { cleanUp } from './clean-up';
6
+ import { buildCreate } from '@plumeria/core/dist/method/create-build-helper.js';
7
+ import { buildGlobal } from '@plumeria/core/dist/method/global-build-helper.js';
8
+ import postcss from 'postcss';
9
+ import combineSelectors from 'postcss-combine-duplicated-selectors';
10
10
 
11
11
  function isCSS(filePath: string): boolean {
12
- const content = fs.readFileSync(filePath, "utf8");
13
- const sourceFile = ts.createSourceFile(
14
- filePath,
15
- content,
16
- ts.ScriptTarget.Latest,
17
- true
18
- );
12
+ const content = fs.readFileSync(filePath, 'utf8');
13
+ const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
19
14
 
20
15
  const checker = (node: ts.Node): boolean => {
21
16
  if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {
22
17
  const expressionText = node.expression.getText(sourceFile);
23
18
  const methodName = node.name.getText(sourceFile);
24
- return (
25
- expressionText === "css" && ["create", "global"].includes(methodName)
26
- );
19
+ return expressionText === 'css' && ['create', 'global'].includes(methodName);
27
20
  }
28
21
  return ts.forEachChild(node, checker) || false;
29
22
  };
@@ -32,31 +25,31 @@ function isCSS(filePath: string): boolean {
32
25
  }
33
26
 
34
27
  async function getAppRoot(): Promise<string> {
35
- const threeLevelsUp = path.join(process.cwd(), "../../../../..");
36
- return fs.existsSync(path.join(threeLevelsUp, "node_modules/.pnpm"))
37
- ? path.join(process.cwd(), "../../../../../")
38
- : path.join(process.cwd(), "../../");
28
+ const threeLevelsUp = path.join(process.cwd(), '../../../../..');
29
+ return fs.existsSync(path.join(threeLevelsUp, 'node_modules/.pnpm'))
30
+ ? path.join(process.cwd(), '../../../../../')
31
+ : path.join(process.cwd(), '../../');
39
32
  }
40
33
 
41
34
  async function optimizeCSS() {
42
- const cssPath = path.join(__dirname, "../../core/dist/styles/global.css");
43
- const cssContent = fs.readFileSync(cssPath, "utf8");
44
- const result = postcss([
45
- combineSelectors({ removeDuplicatedProperties: true }),
46
- ]).process(cssContent, { from: cssPath, to: cssPath });
35
+ const corePath = path.dirname(require.resolve('@plumeria/core/package.json'));
36
+ const cssPath = path.join(corePath, 'dist/styles/global.css');
37
+ const cssContent = fs.readFileSync(cssPath, 'utf8');
38
+ const result = postcss([combineSelectors({ removeDuplicatedProperties: true })]).process(cssContent, {
39
+ from: cssPath,
40
+ to: cssPath,
41
+ });
47
42
  fs.writeFileSync(cssPath, result.css);
48
43
  }
49
44
 
50
45
  (async () => {
51
46
  await cleanUp();
52
47
  const appRoot = await getAppRoot();
53
- const files = await globby([path.join(appRoot, "**/*.{js,jsx,ts,tsx}")], {
54
- ignore: ["**/main.{js,ts}/**", "**/.next/**", "**/node_modules/**"],
48
+ const files = await fg([path.join(appRoot, '**/*.{js,jsx,ts,tsx}')], {
49
+ ignore: ['**/main.{js,ts}/**', '**/dist/**', '**/.next/**', '**/node_modules/**'],
55
50
  });
56
51
  const styleFiles = files.filter(isCSS);
57
- const importPromises = styleFiles.map(
58
- (styleFile) => import(path.resolve(styleFile))
59
- );
52
+ const importPromises = styleFiles.map(styleFile => import(path.resolve(styleFile)));
60
53
  await Promise.all(importPromises);
61
54
 
62
55
  for (let i = 0; i < styleFiles.length; i++) {