onejs-core 0.3.8 → 0.3.9

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.
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Contains code from Nick Janetakis's esbuild-copy-static-files (MIT)
3
+ */
4
+ import path from 'path'
5
+ import fs from 'fs'
6
+ import crypto from 'crypto'
7
+
8
+ function getPackagesWithAssets() {
9
+ let packagesWithAssets = [];
10
+ const nodeModulesPath = path.join(process.cwd(), 'node_modules');
11
+ const packages = fs.readdirSync(nodeModulesPath);
12
+ // console.log("There are " + packages.length + " packages in node_modules");
13
+ for (const packageName of packages) {
14
+ const pkgJsonPath = path.join(nodeModulesPath, packageName, 'package.json');
15
+
16
+ try {
17
+ const pkgJsonContent = fs.readFileSync(pkgJsonPath, 'utf8');
18
+ const pkgJson = JSON.parse(pkgJsonContent);
19
+
20
+ if (pkgJson.onejs && pkgJson.onejs['assets-path']) {
21
+
22
+ packagesWithAssets.push({
23
+ name: packageName,
24
+ src: path.join("node_modules", packageName, pkgJson.onejs['assets-path'])
25
+ });
26
+ }
27
+ } catch (error) {
28
+ if (error.code !== 'ENOENT') {
29
+ console.error(`Error processing ${packageName}:`, error);
30
+ }
31
+ }
32
+ }
33
+
34
+ // console.log("Found " + packagesWithAssets.length + " packages with assets");
35
+ return packagesWithAssets
36
+ }
37
+
38
+ const getDigest = (string) => {
39
+ const hash = crypto.createHash('md5')
40
+ const data = hash.update(string, 'utf-8')
41
+
42
+ return data.digest('hex')
43
+ }
44
+
45
+ const getFileDigest = (path) => {
46
+ if (!fs.existsSync(path)) {
47
+ return null
48
+ }
49
+
50
+ if (fs.statSync(path).isDirectory()) {
51
+ return null
52
+ }
53
+
54
+ return getDigest(fs.readFileSync(path))
55
+ }
56
+
57
+ function filter(src, dest) {
58
+ if (!fs.existsSync(dest)) {
59
+ return true
60
+ }
61
+
62
+ if (fs.statSync(dest).isDirectory()) {
63
+ return true
64
+ }
65
+
66
+ return getFileDigest(src) !== getFileDigest(dest)
67
+ }
68
+
69
+ export function copyAssetsPlugin(options = {}) {
70
+ let dest = options.dest || 'assets'
71
+ return {
72
+ name: "onejs-copy-assets",
73
+ setup(build) {
74
+ build.onEnd(async () => {
75
+ const packagesWithAssets = getPackagesWithAssets();
76
+ console.log(`[esbuild] syncing assets from:`)
77
+ for (const pkg of packagesWithAssets) {
78
+ const destPath = path.join(dest, "@" + pkg.name);
79
+ fs.cpSync(pkg.src, destPath, {
80
+ dereference: options.dereference || true,
81
+ errorOnExist: options.errorOnExist || false,
82
+ filter: options.filter || filter,
83
+ force: options.force || true,
84
+ preserveTimestamps: options.preserveTimestamps || true,
85
+ recursive: options.recursive || true,
86
+ })
87
+ console.log(`[esbuild] > ${pkg.name}`)
88
+ }
89
+ })
90
+ }
91
+ }
92
+ }
@@ -41,22 +41,3 @@ export const importTransformPlugin = {
41
41
  },
42
42
  };
43
43
 
44
- export const watchOutputPlugin = {
45
- name: "onejs-watch-output",
46
- setup(build) {
47
- build.onStart(() => {
48
- // Clear the terminal
49
- process.stdout.write('\x1Bc');
50
- console.log("[esbuild] starting build...");
51
- });
52
-
53
- build.onEnd((result) => {
54
- // if (result.errors.length > 0) {
55
- // console.error("[esbuild] build failed");
56
- // } else {
57
- // console.log("[esbuild] build succeeded");
58
- // }
59
- console.log("[esbuild] watching...");
60
- });
61
- }
62
- }
@@ -0,0 +1,3 @@
1
+ export * from "./import-transform.mjs"
2
+ export * from "./watch-output.mjs"
3
+ export * from "./copy-assets.mjs"
@@ -0,0 +1,19 @@
1
+ export const watchOutputPlugin = {
2
+ name: "onejs-watch-output",
3
+ setup(build) {
4
+ build.onStart(() => {
5
+ // Clear the terminal
6
+ process.stdout.write('\x1Bc');
7
+ console.log("[esbuild] starting build...");
8
+ });
9
+
10
+ build.onEnd((result) => {
11
+ // if (result.errors.length > 0) {
12
+ // console.error("[esbuild] build failed");
13
+ // } else {
14
+ // console.log("[esbuild] build succeeded");
15
+ // }
16
+ console.log("[esbuild] watching...");
17
+ });
18
+ }
19
+ }
@@ -64,30 +64,39 @@ exports.plugins = [
64
64
  ".duration-1000": { "transition-duration": "1000ms" },
65
65
  ".scale-none": { scale: "none" },
66
66
  ".rotate-none": { rotate: "none" },
67
+ ".text-left": { "-unity-text-align": "middle-left" },
68
+ ".text-center": { "-unity-text-align": "middle-center" },
69
+ ".text-right": { "-unity-text-align": "middle-right" },
70
+ ".text-upper-left": { "-unity-text-align": "upper-left" },
71
+ ".text-upper-center": { "-unity-text-align": "upper-center" },
72
+ ".text-upper-right": { "-unity-text-align": "upper-right" },
73
+ ".text-lower-left": { "-unity-text-align": "lower-left" },
74
+ ".text-lower-center": { "-unity-text-align": "lower-center" },
75
+ ".text-lower-right": { "-unity-text-align": "lower-right" },
67
76
  })
68
77
 
69
78
  matchUtilities({
70
79
  fontdef: (value) => ({ "-unity-font-definition": `url("${value}")` }),
71
80
  }, {})
72
81
 
73
- matchUtilities(
74
- {
75
- text: (value) => ({ "-unity-text-align": value }),
76
- },
77
- {
78
- values: {
79
- left: "middle-left",
80
- center: "middle-center",
81
- right: "middle-right",
82
- "upper-left": "upper-left",
83
- "upper-center": "upper-center",
84
- "upper-right": "upper-right",
85
- "lower-left": "lower-left",
86
- "lower-center": "lower-center",
87
- "lower-right": "lower-right",
88
- },
89
- }
90
- )
82
+ // matchUtilities(
83
+ // {
84
+ // text: (value) => ({ "-unity-text-align": value }), // This will conflict with text colors, etc
85
+ // },
86
+ // {
87
+ // values: {
88
+ // left: "middle-left",
89
+ // center: "middle-center",
90
+ // right: "middle-right",
91
+ // "upper-left": "upper-left",
92
+ // "upper-center": "upper-center",
93
+ // "upper-right": "upper-right",
94
+ // "lower-left": "lower-left",
95
+ // "lower-center": "lower-center",
96
+ // "lower-right": "lower-right",
97
+ // },
98
+ // }
99
+ // )
91
100
 
92
101
  matchUtilities(
93
102
  {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "onejs-core",
3
3
  "description": "The JS part of OneJS, a UI framework and Scripting Engine for Unity.",
4
- "version": "0.3.8",
4
+ "version": "0.3.9",
5
5
  "main": "dist/index.js",
6
6
  "types": "typings.d.ts",
7
7
  "dependencies": {