@windwalker-io/core 4.0.6 → 4.0.7

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.6",
3
+ "version": "4.0.7",
4
4
  "type": "module",
5
5
  "description": "Windwalker Core JS package",
6
6
  "scripts": {
@@ -14,6 +14,7 @@ import fs from 'fs';
14
14
  export async function installVendors(npmVendors, composerVendors = [], to = 'www/assets/vendor') {
15
15
  const root = to;
16
16
  let vendors = npmVendors;
17
+ const action = process.env.INSTALL_VENDOR === 'hard' ? 'Copy' : 'Link';
17
18
 
18
19
  if (!fs.existsSync(root)) {
19
20
  fs.mkdirSync(root);
@@ -26,7 +27,7 @@ export async function installVendors(npmVendors, composerVendors = [], to = 'www
26
27
  dirs.unshift(root);
27
28
 
28
29
  dirs.forEach((dir) => {
29
- deleteLinks(dir);
30
+ deleteExists(dir);
30
31
  });
31
32
 
32
33
  vendors = findVendors().concat(vendors);
@@ -34,20 +35,28 @@ export async function installVendors(npmVendors, composerVendors = [], to = 'www
34
35
 
35
36
  vendors.forEach((vendor) => {
36
37
  if (fs.existsSync(`node_modules/${vendor}/`)) {
37
- console.log(`[Link NPM] node_modules/${vendor}/ => ${root}/${vendor}/`);
38
- src(`node_modules/${vendor}/`).pipe(symlink(`${root}/${vendor}`));
38
+ console.log(`[${action} NPM] node_modules/${vendor}/ => ${root}/${vendor}/`);
39
+ doInstall(`node_modules/${vendor}/`, `${root}/${vendor}/`);
39
40
  }
40
41
  });
41
42
 
42
43
  composerVendors.forEach((vendor) => {
43
44
  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}/`));
45
+ console.log(`[${action} Composer] vendor/${vendor}/assets => ${root}/${vendor}/`);
46
+ doInstall(`vendor/${vendor}/assets/`, `${root}/${vendor}/`);
46
47
  }
47
48
  });
48
49
 
49
- console.log(`[Link Local] resources/assets/vendor/**/* => ${root}/`);
50
- src('resources/assets/vendor/*').pipe(symlink(`${root}/`));
50
+ console.log(`[${action} Local] resources/assets/vendor/**/* => ${root}/`);
51
+ doInstall('resources/assets/vendor/*', `${root}/`);
52
+ }
53
+
54
+ function doInstall(source, dest) {
55
+ if (process.env.INSTALL_VENDOR === 'hard') {
56
+ copy(source + '/**/*', dest);
57
+ } else {
58
+ src(source).pipe(symlink(dest));
59
+ }
51
60
  }
52
61
 
53
62
  function findVendors() {
@@ -66,13 +75,20 @@ function findVendors() {
66
75
  return [ ...new Set(vendors) ];
67
76
  }
68
77
 
69
- function deleteLinks(dir) {
70
- const links = fs.readdirSync(dir, { withFileTypes: true })
71
- .filter(d => d.isSymbolicLink());
78
+ function deleteExists(dir) {
79
+ if (!fs.existsSync(dir)) {
80
+ return;
81
+ }
82
+
83
+ const subDirs = fs.readdirSync(dir, { withFileTypes: true });
72
84
 
73
- links.forEach((link) => {
74
- fs.unlink(path.join(dir, link.name), () => {});
85
+ subDirs.forEach((subDir) => {
86
+ if (subDir.isSymbolicLink() || subDir.isFile()) {
87
+ fs.unlinkSync(path.join(dir, subDir.name));
88
+ } else if (subDir.isDirectory()) {
89
+ deleteExists(path.join(dir, subDir.name));
90
+ }
75
91
  });
76
92
 
77
- fs.rmdir(dir, () => {});
93
+ fs.rmdirSync(dir);
78
94
  }