Skip to content

Commit

Permalink
Build working nicely.
Browse files Browse the repository at this point in the history
  • Loading branch information
brentlintner committed Mar 17, 2018
1 parent 977c8b2 commit 0347b70
Show file tree
Hide file tree
Showing 17 changed files with 138 additions and 81 deletions.
9 changes: 9 additions & 0 deletions bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ build() {
# copy over all plugins
cp -r $build_dir/node_modules $target_dist/node_modules

# copy over license/readme
cp $root_dir/README.md $target_dist/.
cp $root_dir/CHANGELOG.md $target_dist/.
cp $root_dir/LICENSE $target_dist/.

# copy over all default config
mkdir $target_dist/default
cp $default_yml_config $target_dist/default/.ferret.yml
Expand All @@ -73,6 +78,10 @@ build() {
cp $build_dir/bin/ferret $target_dist/.
fi

# debug..
#cp -rf $root_dir/lib/* $target_dist/node_modules/@forthright/ferret/lib/.
#cp -rf $root_dir/bin/ferret $target_dist/node_modules/@forthright/ferret/bin/.

# copy over node
mkdir $target_dist/lib
cp -r $lib_dir/$target_node $target_dist/lib/node
Expand Down
5 changes: 2 additions & 3 deletions build/bin/ferret
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ basedir=`dirname "$0"`

node_bin="$basedir/lib/node/bin/node"
ferret_bin="$basedir/node_modules/@forthright/ferret/bin/ferret"
ferret_plugins=`realpath "$basedir"`

FERRET_PLUGINS_PATH=""

"$node_bin" "$ferret_bin" "$@"
FERRET_PLUGINS_PATH=$ferret_plugins "$node_bin" "$ferret_bin" "$@"
1 change: 1 addition & 0 deletions build/bin/ferret.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ SETLOCAL

SET "NODE_BIN=%~dp0\lib\node\node.exe"
SET "FERRET_BIN=%~dp0\node_modules\@forthright\ferret\bin\ferret"
SET "FERRET_PLUGINS_PATH=%~dp0"

"%NODE_EXE%" "%FERRET_BIN%" %*
2 changes: 1 addition & 1 deletion build/os/arch_linux/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ package() {
install -m644 "${srcdir}/${_pkg}/LICENSE" "${pkgdir}/usr/share/licenses/${_pkgname}/LICENSE"

cp -r "${srcdir}/${_pkg}/"* "${pkgdir}/opt/${_pkgname}" -R
ln -s /opt/${_pkgname}/bin/ferret "${pkgdir}"/usr/bin/ferret
ln -s /opt/${_pkgname}/ferret "${pkgdir}"/usr/bin/ferret
}
8 changes: 4 additions & 4 deletions build/package-lock.json

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

21 changes: 18 additions & 3 deletions docs/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ Using an [build.opensuse.org](https://build.opensuse.org/):
yum-....
yum install ferret

#### Other Distros

See [build.opensuse.org](https://build.opensuse.org/).

### Platform Binaries

There are binary packages available for Linux, Windows and MacOS.
Expand All @@ -80,7 +84,7 @@ Grab a tarball from the [Releases](https://github.com/forthright/ferret/releases

Or, similarly, on Windows:

ferret.exe -h
ferret.cmd -h

### Install By "Source"

Expand All @@ -95,11 +99,22 @@ To install packages manually, or if you are familiar with an npm setup:
npm i --save-dev @forthright/ferret-comment
npm i --save-dev @forthright/ferret-typescript
npm i --save-dev @forthright/ferret-....
npx ferret analyze

### Installing Custom Plugins

To install custom plugins on top of a binary or package manager install:

cd my_project/
npm i --save-dev @forthright/ferret
npm i --save-dev ferret-my-plugin
ferret analyze -p my-plugin

For more details on installing via `npm` see [here](/lang/#plugins).
Note: If you use something like `npx ferret` in this case,
it will *not* be able to run globally installed plugins.

## Checking The Install

To see exactly what plugins and versions are being used, you can run:

ferret modules
ferret version
2 changes: 0 additions & 2 deletions lib/cli/analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ var analyze = function (opts, paths) {
format: opts.format,
plugins: custom_plugins,
additional_plugins: additional_plugins,
skip_core_plugins: opts.withoutCorePlugins,
skip_snippets: opts.skipSnippets,
spinner: !(opts.quiet || !opts.decorations)
};
Expand Down Expand Up @@ -129,7 +128,6 @@ var create = function (cli) {
.option("-g, --git-diff [rev]", "only check files patched in latest HEAD commit, or rev")
.option("-d, --dont-post-process", "don't post process data in any way (ex: adding ok data)- " +
"useful for per file checking")
.option("-w, --without-core-plugins", "don't use plugins bundled with core lib")
.option("-l, --log [level]", "specify the log level (info=default|warn|error|debug)")
.option("-i, --issue-log [level]", "specify data types to log (ex: '-i security,dependency')")
.option("-e, --exit-on-issues", "exit with bad code " +
Expand Down
12 changes: 5 additions & 7 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,11 @@ var exec = function (config, opts) {
var installed_plugins = _.map(mods, function (mod) {
return _.last(_.split(mod[0], "/"));
});
log.debug("available:", "\n" + installed_plugins.join("\n"));
log.debug("allow via .ferret.yml =>", allowed_plugins_via_config.join(", ") || "any");
log.debug("allow via opts =>", allowed_plugins_via_opts.join(", ") || "any");
log.debug("allow via additional_opts =>", allowed_plugins_via_additional_opts.join(", ") || "any");
log.debug("skip core plugins =>", !!opts.skip_core_plugins);
var to_run = plugin_require.filter(installed_plugins, allowed_plugins_via_config, allowed_plugins_via_opts, allowed_plugins_via_additional_opts, !!opts.skip_core_plugins);
log.debug("to run: ", to_run.join(", "));
log.debug(".ferret.yml =>", allowed_plugins_via_config.join(", ") || "any");
log.debug("cli =>", allowed_plugins_via_opts.join(", ") || "any");
log.debug("extra =>", allowed_plugins_via_additional_opts.join(", ") || "any");
var to_run = plugin_require.filter(installed_plugins, allowed_plugins_via_config, allowed_plugins_via_opts, allowed_plugins_via_additional_opts);
log.debug("to run:", "\n=> ", to_run.join("\n=> "));
return execute_plugins(to_run, config, opts);
});
};
Expand Down
29 changes: 12 additions & 17 deletions lib/plugin/require.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@ var logger = require("./../logger");
var PluginNotFoundError = require("./plugin_not_found_error");
var readdirAsync = Promise.promisify(fs.readdir);
var log = logger.create("plugin");
var BUNDLED_PLUGINS = [];
var NODE_MODULES = "node_modules";
var OFFICIAL_SCOPE = "@forthright";
var is_plugin = function (name) {
return !!/^ferret-/.test(name);
};
var cannot_find_module = function (err) {
return /cannot find module/i.test(_.get(err, "stack", err));
var cannot_find_module = function (err, module_loc) {
return new RegExp("cannot find module '" + module_loc + "'", "i")
.test(_.get(err, "stack", err));
};
var _locate = function (base_path, module_name, org_name) {
if (org_name === void 0) { org_name = ""; }
var modules_path = path.join(base_path, NODE_MODULES, org_name);
var plugin;
log.debug("looking in:", modules_path);
log.debug("looking for " + module_name + " in:", modules_path);
var module_loc = path.join(modules_path, module_name);
try {
var module_loc = path.join(modules_path, module_name);
plugin = require(module_loc);
log.debug("found", module_loc);
log.debug("using", module_loc);
}
catch (e) {
if (cannot_find_module(e)) {
if (cannot_find_module(e, module_loc)) {
throw new PluginNotFoundError(e);
}
else {
throw e;
log.error(e);
}
}
return plugin;
Expand Down Expand Up @@ -91,13 +91,10 @@ var node_modules_list = function (base, org) {
return Promise.resolve([]);
}
};
var filter_plugins_to_run = function (installed, via_config, via_opts, via_additional_opts, skip_core_plugins) {
var filter_plugins_to_run = function (installed, via_config, via_opts, via_additional_opts) {
var allowed_plugins = _
.isEmpty(via_opts) ? via_config : _.concat([], via_opts);
var to_run = skip_core_plugins ?
installed :
_.concat(installed, BUNDLED_PLUGINS);
to_run = _.uniq(to_run.concat(via_additional_opts));
var to_run = _.uniq(_.concat([], installed, via_additional_opts));
return _.isEmpty(allowed_plugins) ?
to_run :
_.filter(to_run, function (p) {
Expand All @@ -108,22 +105,21 @@ var filter_plugins_to_run = function (installed, via_config, via_opts, via_addit
};
var available_plugins = function () {
var cwd = process.cwd();
log.debug("searching:", cwd);
var potential_locations = [
node_modules_list(cwd),
node_modules_list(cwd, "@forthright")
];
var bundled_modules = _.get(process, "env.FERRET_PLUGINS_PATH");
if (bundled_modules) {
var abs_path = path.resolve(bundled_modules);
log.debug("searching:", abs_path);
potential_locations.push(node_modules_list(abs_path), node_modules_list(abs_path, "@forthright"));
}
return Promise
.all(potential_locations)
.then(_.flatten)
.then(function (list) {
log.debug("found:", "\n" + list.join("\n"));
log.debug("known locations...", "\n=> " +
(list.join("\n=> ") || "none"));
return _.map(_.uniq(list), function (mod_path) {
var version = require(path.join(mod_path, "package.json")).version;
return [mod_path, version];
Expand All @@ -132,7 +128,6 @@ var available_plugins = function () {
};
module.exports = {
available_modules: available_plugins,
bundled: BUNDLED_PLUGINS,
filter: filter_plugins_to_run,
locate: locate
};
11 changes: 9 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var _ = require("lodash");
var Bluebird = require("bluebird");
var ignore = require("ignore");
var logger = require("./logger");
var log = logger.create("util");
var fs_readFile = Bluebird.promisify(fs.readFile);
var matches = function (filepath, to_match) {
var matcher = ignore();
Expand Down Expand Up @@ -63,6 +64,12 @@ var spawn = function (bin, opts) {
cwd: process.cwd(),
path: process.env.PATH
}));
var ferret_plugins_path = _.get(process, "env.FERRET_PLUGINS_PATH");
if (_.isString(ferret_plugins_path)) {
var bin_path = path.join(ferret_plugins_path, "node_modules", ".bin");
new_path = bin_path + ":" + new_path;
}
log.debug("spawn", bin, "PATH =>", new_path);
var new_env = _.assign({}, process.env);
new_env.Path = new_path;
new_env.PATH = new_path;
Expand All @@ -82,8 +89,8 @@ var spawn = function (bin, opts) {
var stderr_str = stderr
.map(function (err) { return err.toString("utf-8"); }).join("");
if (stderr_str) {
var log_1 = logger.create(bin);
log_1.warn("\n", stderr_str);
var nlog = logger.create(bin);
nlog.warn("\n", stderr_str);
}
var data = {
code: code,
Expand Down
40 changes: 39 additions & 1 deletion package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"unixify": "^1.0.0"
},
"devDependencies": {
"@forthright/ferret": "^0.19.6",
"@forthright/ferret-depcheck": "^0.1.17",
"@forthright/ferret-license": "^0.4.3",
"chai": "^4.1.2",
Expand Down
2 changes: 0 additions & 2 deletions src/@types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ declare namespace ferret {
format? : string;
combine? : string;
dont_post_process? : boolean;
skip_core_plugins? : boolean
skip_snippets? : boolean;
plugins? : PluginList;
additional_plugins? : PluginList;
Expand All @@ -318,7 +317,6 @@ declare namespace ferret {
spinner? : boolean;
terminalSnippets? : boolean;
upload? : string;
withoutCorePlugins? : boolean
}

export interface CLIModule {
Expand Down
3 changes: 0 additions & 3 deletions src/cli/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ const analyze = (
format: opts.format,
plugins: custom_plugins,
additional_plugins: additional_plugins,
skip_core_plugins: opts.withoutCorePlugins,
skip_snippets: opts.skipSnippets,
spinner: !(opts.quiet || !opts.decorations)
}
Expand Down Expand Up @@ -172,8 +171,6 @@ const create = (cli : commander.CommanderStatic) =>
.option("-d, --dont-post-process",
"don't post process data in any way (ex: adding ok data)- " +
"useful for per file checking")
.option("-w, --without-core-plugins",
"don't use plugins bundled with core lib")
.option("-l, --log [level]",
"specify the log level (info=default|warn|error|debug)")
.option("-i, --issue-log [level]",
Expand Down
13 changes: 5 additions & 8 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,26 +351,23 @@ const exec = (
(mod : string[]) =>
_.last(_.split(mod[0], "/")))

log.debug("available:", "\n" + installed_plugins.join("\n"))
log.debug(
"allow via .ferret.yml =>",
".ferret.yml =>",
allowed_plugins_via_config.join(", ") || "any")
log.debug(
"allow via opts =>",
"cli =>",
allowed_plugins_via_opts.join(", ") || "any")
log.debug(
"allow via additional_opts =>",
"extra =>",
allowed_plugins_via_additional_opts.join(", ") || "any")
log.debug("skip core plugins =>", !!opts.skip_core_plugins)

const to_run = plugin_require.filter(
installed_plugins,
allowed_plugins_via_config,
allowed_plugins_via_opts,
allowed_plugins_via_additional_opts,
!!opts.skip_core_plugins)
allowed_plugins_via_additional_opts)

log.debug("to run: ", to_run.join(", "))
log.debug("to run:", "\n=>", to_run.join("\n=> "))

return execute_plugins(
to_run,
Expand Down
Loading

0 comments on commit 0347b70

Please sign in to comment.