Skip to content

Commit

Permalink
- dont copy JS / CSS files based on browser / style` field if
Browse files Browse the repository at this point in the history
   `main` folder is by link instead of by copying.
 - instead of copying, making a symlink by following symlink in
   `node_modules`.
   - symlink usually is for local dev files, which may contains many
     things we dont need as a module.
     thus copying isn't the best way which may copy files like `.git` or
`node_modules`.
 - bump version
  • Loading branch information
zbryikt committed Jan 26, 2022
1 parent 734df81 commit 26a6928
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 15 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Logs

## v1.1.4

- don`t copy JS / CSS files based on `browser` / `style` field if `main` folder is by link instead of by copying.
- instead of copying, making a symlink by following symlink in `node_modules`.
- symlink usually is for local dev files, which may contains many things we dont need as a module.
thus copying isn't the best way which may copy files like `.git` or `node_modules`.


## v1.1.3

- copy contente of symlink if module in `node_modules` is a symbolic link.
Expand Down
25 changes: 16 additions & 9 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ cmds['default'] = {
modules: []
}, JSON.parse(fs.readFileSync("package.json").toString()).frontendDependencies || {});
return (fed.modules || []).map(function(obj){
var localModule, root, info, id, mainFile, ref$, i$, name, version, ret, that, desdir, maindir, p, srcdir, srcFile, desFile;
var localModule, root, info, id, mainFile, ref$, i$, name, version, ret, that, desdir, maindir, p, srcdir, realSrcDir, srcFile, desFile;
obj = typeof obj === 'string' ? {
name: obj
} : obj;
Expand Down Expand Up @@ -126,25 +126,32 @@ cmds['default'] = {
fsExtra.removeSync(desdir);
fsExtra.ensureSymlinkSync(srcdir, desdir);
} else {
fsExtra.copySync(srcdir, desdir, {
dereference: true,
filter: function(it){
return !/.+\/node_modules/.exec(it);
}
});
if (fs.lstatSync(srcdir).isSymbolicLink()) {
obj.link = true;
fsExtra.removeSync(desdir);
realSrcDir = path.resolve(path.join(path.dirname(srcdir), fs.readlinkSync(srcdir)));
fsExtra.ensureSymlinkSync(realSrcDir, desdir);
} else {
fsExtra.copySync(srcdir, desdir, {
dereference: true,
filter: function(it){
return !/.+\/node_modules|\/\.git/.exec(it);
}
});
}
}
p = Promise.resolve().then(function(){
return console.log(" -- " + srcdir + " -> " + desdir + " ");
});
if (mainFile.js && !localModule) {
if (!obj.link && mainFile.js && !localModule) {
srcFile = path.join(root, mainFile.js);
desFile = path.join(desdir, "index.js");
if (!fs.existsSync(desFile)) {
fsExtra.copySync(srcFile, desFile);
console.log(" --", "[JS]".green, srcFile + " --> " + desFile + " ");
}
}
if (mainFile.css && !localModule) {
if (!obj.link && mainFile.css && !localModule) {
srcFile = path.join(root, mainFile.css);
desFile = path.join(desdir, "index.css");
if (!fs.existsSync(desFile)) {
Expand Down
17 changes: 14 additions & 3 deletions lib/main.ls
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,27 @@ cmds.default =
if local-module or obj.link =>
fs-extra.remove-sync desdir
fs-extra.ensure-symlink-sync srcdir, desdir
else fs-extra.copy-sync srcdir, desdir, {dereference: true, filter: -> !/.+\/node_modules/.exec(it)}
else
if fs.lstat-sync srcdir .is-symbolic-link! =>
obj.link = true
fs-extra.remove-sync desdir
real-src-dir = path.resolve(path.join(path.dirname(srcdir), fs.readlink-sync(srcdir)))
fs-extra.ensure-symlink-sync real-src-dir, desdir
else
fs-extra.copy-sync(
srcdir, desdir,
{dereference: true, filter: -> !/.+\/node_modules|\/\.git/.exec(it)}
)

p = Promise.resolve!then -> console.log " -- #srcdir -> #desdir "
if main-file.js and !local-module =>
if !obj.link and main-file.js and !local-module =>
src-file = path.join(root, main-file.js)
des-file = path.join(desdir, "index.js")
if !fs.exists-sync(des-file) =>
fs-extra.copy-sync src-file, des-file
console.log " --", "[JS]".green, "#src-file --> #des-file "

if main-file.css and !local-module =>
if !obj.link and main-file.css and !local-module =>
src-file = path.join(root, main-file.css)
des-file = path.join(desdir, "index.css")
if !fs.exists-sync(des-file) =>
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"cli.js"
],
"description": "Frontend dependency installer",
"version": "1.1.3",
"version": "1.1.4",
"homepage": "https://github.com/plotdb/fedep",
"repository": {
"type": "git",
Expand Down

0 comments on commit 26a6928

Please sign in to comment.