Skip to content

Commit

Permalink
feat: symlinkCreator
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed Dec 28, 2023
1 parent 4d3b7de commit 5697054
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const fs = require('fs');
const path = require('path');

const upload = require('@cocreate/cli/src/commands/upload.js')

class ModuleGenerator {
Expand Down Expand Up @@ -54,6 +56,7 @@ class ModuleGenerator {
});
}
}

class fileUploader {
constructor(env) {
this.env = env;
Expand All @@ -78,5 +81,39 @@ class fileUploader {
}
}

class SymlinkCreator {
constructor(options) {
// Store options if necessary, or just hard-code paths
}

apply(compiler) {
// Use compiler.hooks to tap into the Webpack build process
compiler.hooks.afterEmit.tap('SymlinkPlugin', (compilation) => {
// Perform symlink operations here
symlink('./dist', '../dist', 'dir');
symlink('./node_modules/@cocreate/pwa/src/service-worker.js', '../service-worker.js', 'file');
symlink('./node_modules/@cocreate/pwa/src/manifest.webmanifest', '../manifest.webmanifest', 'file');
symlink('./node_modules/@cocreate/pwa/src/offline.html', '../offline.html', 'file');
});

function symlink(target, destination, option) {
if (fs.existsSync(target)) {
target = path.resolve(target)

if (!fs.existsSync(destination)) {
destination = path.resolve(destination)

fs.symlink(target, destination, option, (err) => {
if (err)
console.log(err);
else
console.log("symlink added: ", target);
})

}
}
}
}
}

module.exports = { ModuleGenerator, fileUploader };
module.exports = { ModuleGenerator, fileUploader, SymlinkCreator };

0 comments on commit 5697054

Please sign in to comment.