Skip to content

Commit 5697054

Browse files
committed
feat: symlinkCreator
1 parent 4d3b7de commit 5697054

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/index.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const fs = require('fs');
2+
const path = require('path');
3+
24
const upload = require('@cocreate/cli/src/commands/upload.js')
35

46
class ModuleGenerator {
@@ -54,6 +56,7 @@ class ModuleGenerator {
5456
});
5557
}
5658
}
59+
5760
class fileUploader {
5861
constructor(env) {
5962
this.env = env;
@@ -78,5 +81,39 @@ class fileUploader {
7881
}
7982
}
8083

84+
class SymlinkCreator {
85+
constructor(options) {
86+
// Store options if necessary, or just hard-code paths
87+
}
88+
89+
apply(compiler) {
90+
// Use compiler.hooks to tap into the Webpack build process
91+
compiler.hooks.afterEmit.tap('SymlinkPlugin', (compilation) => {
92+
// Perform symlink operations here
93+
symlink('./dist', '../dist', 'dir');
94+
symlink('./node_modules/@cocreate/pwa/src/service-worker.js', '../service-worker.js', 'file');
95+
symlink('./node_modules/@cocreate/pwa/src/manifest.webmanifest', '../manifest.webmanifest', 'file');
96+
symlink('./node_modules/@cocreate/pwa/src/offline.html', '../offline.html', 'file');
97+
});
98+
99+
function symlink(target, destination, option) {
100+
if (fs.existsSync(target)) {
101+
target = path.resolve(target)
102+
103+
if (!fs.existsSync(destination)) {
104+
destination = path.resolve(destination)
105+
106+
fs.symlink(target, destination, option, (err) => {
107+
if (err)
108+
console.log(err);
109+
else
110+
console.log("symlink added: ", target);
111+
})
112+
113+
}
114+
}
115+
}
116+
}
117+
}
81118

82-
module.exports = { ModuleGenerator, fileUploader };
119+
module.exports = { ModuleGenerator, fileUploader, SymlinkCreator };

0 commit comments

Comments
 (0)