@windwalker-io/core 4.0.2 → 4.0.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windwalker-io/core",
3
- "version": "4.0.2",
3
+ "version": "4.0.6",
4
4
  "type": "module",
5
5
  "description": "Windwalker Core JS package",
6
6
  "scripts": {
@@ -8,7 +8,9 @@
8
8
  import { dest as toDest, src } from '@windwalker-io/fusion';
9
9
  import { postStream, prepareStream } from '@windwalker-io/fusion/src/lifecycles.js';
10
10
  import { extractDest } from '@windwalker-io/fusion/src/utilities/utilities.js';
11
+ import { loadJson } from './utils.mjs';
11
12
  import rename from 'gulp-rename';
13
+ import path from 'path';
12
14
 
13
15
  export function jsSync(source = 'src/Module', dest) {
14
16
  // const root = source + '/**/assets/';
@@ -27,10 +29,13 @@ export function jsSync(source = 'src/Module', dest) {
27
29
  // }
28
30
  // });
29
31
 
30
- source += '/**/assets/*.{js,mjs}';
32
+ const sourceList = [];
33
+
34
+ sourceList.push(...findModules('**/assets/*.{js,mjs}'));
35
+ sourceList.push(source + '**/assets/*.{js,mjs}');
36
+
37
+ let stream = prepareStream(src(sourceList));
31
38
 
32
- let stream = prepareStream(src(source));
33
- //
34
39
  stream = stream.pipe(rename((path) => {
35
40
  path.dirname = path.dirname.replace(/assets$/, '').toLowerCase();
36
41
  }));
@@ -57,3 +62,23 @@ export function jsSync(source = 'src/Module', dest) {
57
62
  });
58
63
  });
59
64
  }
65
+
66
+ export function findModules(suffix = '') {
67
+ const pkg = path.resolve(process.cwd(), 'composer.json');
68
+
69
+ const pkgJson = loadJson(pkg);
70
+
71
+ const vendors = Object.keys(pkgJson['require'] || {})
72
+ .concat(Object.keys(pkgJson['require-dev'] || {}))
73
+ .map(id => `vendor/${id}/composer.json`)
74
+ .map((file) => loadJson(file))
75
+ .filter(pkgJson => pkgJson?.extra?.windwalker != null)
76
+ .map(pkgJson => {
77
+ return pkgJson?.extra?.windwalker?.modules?.map((module) => {
78
+ return `vendor/${pkgJson.name}/${module}/${suffix}`;
79
+ }) || [];
80
+ })
81
+ .flat();
82
+
83
+ return [ ...new Set(vendors) ];
84
+ }
package/src/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
- /**
2
- * Part of funclass project.
3
- *
4
- * @copyright Copyright (C) 2021 LYRASOFT.
5
- * @license __LICENSE__
6
- */
7
-
8
- export * from './asset-sync.mjs';
9
- export * from './install-vendors.mjs';
1
+ /**
2
+ * Part of funclass project.
3
+ *
4
+ * @copyright Copyright (C) 2021 LYRASOFT.
5
+ * @license __LICENSE__
6
+ */
7
+
8
+ export * from './asset-sync.mjs';
9
+ export * from './install-vendors.mjs';
@@ -7,11 +7,13 @@
7
7
 
8
8
  import { src, symlink, copy } from '@windwalker-io/fusion';
9
9
  import { extractDest } from '@windwalker-io/fusion/src/utilities/utilities.js';
10
+ import { loadJson } from './utils.mjs';
10
11
  import path from 'path';
11
12
  import fs from 'fs';
12
13
 
13
- export async function installVendors(vendors) {
14
- const root = 'www/assets/vendor';
14
+ export async function installVendors(npmVendors, composerVendors = [], to = 'www/assets/vendor') {
15
+ const root = to;
16
+ let vendors = npmVendors;
15
17
 
16
18
  if (!fs.existsSync(root)) {
17
19
  fs.mkdirSync(root);
@@ -32,13 +34,20 @@ export async function installVendors(vendors) {
32
34
 
33
35
  vendors.forEach((vendor) => {
34
36
  if (fs.existsSync(`node_modules/${vendor}/`)) {
35
- console.log(`[Link] node_modules/${vendor}/ => www/assets/vendor/${vendor}/`);
36
- src(`node_modules/${vendor}/`).pipe(symlink(`www/assets/vendor/${vendor}`));
37
+ console.log(`[Link NPM] node_modules/${vendor}/ => ${root}/${vendor}/`);
38
+ src(`node_modules/${vendor}/`).pipe(symlink(`${root}/${vendor}`));
37
39
  }
38
40
  });
39
41
 
40
- console.log('[Link] resources/assets/vendor/**/* => www/assets/vendor/');
41
- src('resources/assets/vendor/*').pipe(symlink('www/assets/vendor/'));
42
+ composerVendors.forEach((vendor) => {
43
+ if (fs.existsSync(`vendor/${vendor}/assets`)) {
44
+ console.log(`[Link Composer] vendor/${vendor}/assets => ${root}/${vendor}/`);
45
+ src(`vendor/${vendor}/assets/`).pipe(symlink(`${root}/${vendor}/`));
46
+ }
47
+ });
48
+
49
+ console.log(`[Link Local] resources/assets/vendor/**/* => ${root}/`);
50
+ src('resources/assets/vendor/*').pipe(symlink(`${root}/`));
42
51
  }
43
52
 
44
53
  function findVendors() {
@@ -57,14 +66,6 @@ function findVendors() {
57
66
  return [ ...new Set(vendors) ];
58
67
  }
59
68
 
60
- function loadJson(file) {
61
- if (!fs.existsSync(file)) {
62
- return null;
63
- }
64
-
65
- return JSON.parse(fs.readFileSync(file));
66
- }
67
-
68
69
  function deleteLinks(dir) {
69
70
  const links = fs.readdirSync(dir, { withFileTypes: true })
70
71
  .filter(d => d.isSymbolicLink());
package/src/utils.mjs ADDED
@@ -0,0 +1,17 @@
1
+ import fs from 'fs';
2
+
3
+ /**
4
+ * Part of earth project.
5
+ *
6
+ * @copyright Copyright (C) 2021 __ORGANIZATION__.
7
+ * @license __LICENSE__
8
+ */
9
+
10
+
11
+ export function loadJson(file) {
12
+ if (!fs.existsSync(file)) {
13
+ return null;
14
+ }
15
+
16
+ return JSON.parse(fs.readFileSync(file));
17
+ }