Skip to content

Commit

Permalink
- add local option for installing frontend modules from local repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
zbryikt committed Sep 22, 2021
1 parent 95cbdac commit 518afe2
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Logs

## v0.0.14

- add `local` option for installing frontend modules from local repo.


## v0.0.13

- bump `path-parse` and `elliptic` version for vulnerability fixing
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,24 @@ Frontend dependency installer. copy frontend modules to desired directory, with

by executing `npx fedep` or invoking via postinstall when `npm i`, `fedep` will do:

- copy content of `dist` directory (configurable as `dir` option, see below) in specified packages to static/assets/lib/<name>/<version>/ after install
- lookup package with given name in `node_modules` folder.
- once found, copy content to `<root>/<name>/<version>` from folders of give source packages in following priority:
- `<dir>` folder if `dir` option is given ( see below ).
- `dist` folder if `<dir>` is omitted and `dist` exists
- otherwise, the whole package is copied.
- build a symbolic link from <version> to /main/


Once configuration is prepared, run:

npx fedep


You can also use local repo for a specific module:

npx fedep -l <some-module>:<path-to-local-repo>


## Modules Format

you can use either string or object to list modules to be used. e.g.,
Expand Down
30 changes: 27 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
#!/usr/bin/env node
// Generated by LiveScript 1.6.0
var fs, path, fsExtra, browserify, yargs, argv, useSymlink, fed, slice$ = [].slice;
var fs, path, os, fsExtra, browserify, yargs, argv, ret, localModule, useSymlink, fed, slice$ = [].slice;
fs = require('fs');
path = require('path');
os = require('os');
fsExtra = require('fs-extra');
browserify = require('browserify');
yargs = require('yargs');
argv = yargs.option('symlink', {
alias: 's',
description: "use symlink instead of hard copy to make main folder. default true",
type: 'boolean'
}).option('local', {
alias: 'l',
description: "use local folder for a specific module, with module:dir syntax"
}).help('help').alias('help', 'h').check(function(argv, options){
return true;
}).argv;
if (argv.l) {
ret = argv.l.split(':');
localModule = {
name: ret[0],
path: path.resolve(ret[1].replace(/^~/, os.homedir()))
};
} else {
localModule = null;
}
useSymlink = argv.s != null ? argv.s : true;
fed = import$({
root: '.',
Expand All @@ -23,7 +36,14 @@ fed = import$({
obj = typeof obj === 'string' ? {
name: obj
} : obj;
root = path.join("node_modules", obj.name);
if (localModule && obj.name !== localModule.name) {
return;
}
if (localModule) {
root = localModule.path;
} else {
root = path.join("node_modules", obj.name);
}
info = JSON.parse(fs.readFileSync(path.join(root, "package.json")).toString());
id = info._id || info.name + "@" + info.version;
if (/\.\.|^\//.exec(id)) {
Expand All @@ -41,7 +61,11 @@ fed = import$({
: name[1]
? "@" + name[1]
: name.join('@');
desdir = path.join(fed.root, name, version);
if (localModule) {
desdir = path.join(fed.root, name, 'local');
} else {
desdir = path.join(fed.root, name, version);
}
maindir = path.join(fed.root, name, "main");
fsExtra.removeSync(desdir);
fsExtra.ensureDirSync(desdir);
Expand Down
18 changes: 15 additions & 3 deletions lib/main.ls
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
#!/usr/bin/env node
require! <[fs path fs-extra browserify yargs]>
require! <[fs path os fs-extra browserify yargs]>

argv = yargs
.option \symlink, do
alias: \s
description: "use symlink instead of hard copy to make main folder. default true"
type: \boolean
.option \local, do
alias: \l
description: "use local folder for a specific module, with module:dir syntax"
.help \help
.alias \help, \h
.check (argv, options) -> return true
.argv

if argv.l =>
ret = argv.l.split(\:)
local-module = name: ret.0, path: path.resolve(ret.1.replace(/^~/, os.homedir!))

else local-module = null

use-symlink = if argv.s? => argv.s else true

fed = {root: '.', modules: []} <<< (JSON.parse(fs.read-file-sync "package.json" .toString!).frontendDependencies or {})

(fed.modules or []).map (obj) ->
obj = if typeof(obj) == \string => {name: obj} else obj
root = path.join("node_modules", obj.name)
if local-module and obj.name != local-module.name => return
if local-module => root = local-module.path
else root = path.join("node_modules", obj.name)
info = JSON.parse(fs.read-file-sync path.join(root, "package.json") .toString!)
id = info._id or "#{info.name}@#{info.version}"
if /\.\.|^\//.exec(id) => throw new Error("fedep: not supported name in module #{obj.name}.")
Expand All @@ -35,7 +46,8 @@ fed = {root: '.', modules: []} <<< (JSON.parse(fs.read-file-sync "package.json"
name = if name.0 => that else if name.1 => "@#{name.1}"
# if there are any exception, just join them back to provide raw name.
else name.join(\@)
desdir = path.join(fed.root, name, version)
if local-module => desdir = path.join(fed.root, name, 'local')
else desdir = path.join(fed.root, name, version)
maindir = path.join(fed.root, name, "main")
fs-extra.remove-sync desdir
fs-extra.ensure-dir-sync desdir
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": "0.0.13",
"version": "0.0.14",
"homepage": "https://github.com/plotdb/fedep",
"repository": {
"type": "git",
Expand Down

0 comments on commit 518afe2

Please sign in to comment.