Skip to content

Commit

Permalink
Merge 7878ede into b722c15
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrum committed Jun 11, 2021
2 parents b722c15 + 7878ede commit bc0fcfb
Show file tree
Hide file tree
Showing 9 changed files with 4,174 additions and 20,220 deletions.
10 changes: 10 additions & 0 deletions changelog.md
@@ -1,5 +1,15 @@
## 0.10.0 (2021-06-11)

* feat: resolve local plugin, close #336, close #338 ([44d877b](https://github.com/posthtml/posthtml-cli/commit/44d877b)), closes [#336](https://github.com/posthtml/posthtml-cli/issues/336) [#338](https://github.com/posthtml/posthtml-cli/issues/338)
* test: resolve local plugin, issue #336, #338 ([2a0cb7d](https://github.com/posthtml/posthtml-cli/commit/2a0cb7d)), closes [#336](https://github.com/posthtml/posthtml-cli/issues/336) [#338](https://github.com/posthtml/posthtml-cli/issues/338)
* fix: fails without config, close #337 ([8307ed3](https://github.com/posthtml/posthtml-cli/commit/8307ed3)), closes [#337](https://github.com/posthtml/posthtml-cli/issues/337)
* build: update dep dev ([36e5996](https://github.com/posthtml/posthtml-cli/commit/36e5996))



## <small>0.9.2 (2021-05-07)</small>

* 0.9.2 ([b722c15](https://github.com/posthtml/posthtml-cli/commit/b722c15))
* Fix homepage link in package.json ([a07a0ea](https://github.com/posthtml/posthtml-cli/commit/a07a0ea))


Expand Down
24,264 changes: 4,073 additions & 20,191 deletions package-lock.json

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "posthtml-cli",
"version": "0.9.2",
"version": "0.10.0",
"description": "CLI for posthtml",
"license": "MIT",
"repository": "posthtml/posthtml-cli",
Expand Down Expand Up @@ -35,47 +35,47 @@
],
"dependencies": {
"cosmiconfig": "^7.0.0",
"fast-glob": "^3.2.4",
"fast-glob": "^3.2.5",
"make-dir": "^3.0.0",
"meow": "^7.1.1",
"merge-options": "^3.0.4",
"normalize-path": "^3.0.0",
"posthtml": "^0.15.1",
"posthtml": "^0.16.4",
"to-camel-case": "^1.0.0",
"update-notifier": "^5.0.0"
"update-notifier": "^5.1.0"
},
"devDependencies": {
"@babel/cli": "^7.12.8",
"@babel/core": "^7.12.9",
"@babel/node": "^7.10.5",
"@babel/preset-env": "^7.12.7",
"@babel/register": "^7.11.5",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-angular": "^11.0.0",
"acorn": "^8.0.4",
"ava": "^3.13.0",
"@babel/cli": "^7.14.5",
"@babel/core": "^7.14.5",
"@babel/node": "^7.14.5",
"@babel/preset-env": "^7.14.5",
"@babel/register": "^7.14.5",
"@commitlint/cli": "^12.1.4",
"@commitlint/config-angular": "^12.1.4",
"acorn": "^8.3.0",
"ava": "^3.15.0",
"babel-eslint": "^10.0.3",
"babel-preset-minify": "^0.5.1",
"clinton": "^0.14.0",
"conventional-changelog-cli": "^2.1.0",
"coveralls": "^3.0.9",
"cpy": "^8.1.1",
"eslint": "^7.14.0",
"eslint-config-xo": "^0.33.1",
"eslint-config-xo-space": "^0.25.0",
"eslint-plugin-ava": "^11.0.0",
"cpy": "^8.1.2",
"eslint": "^7.28.0",
"eslint-config-xo": "^0.36.0",
"eslint-config-xo-space": "^0.27.0",
"eslint-plugin-ava": "^12.0.0",
"eslint-plugin-babel": "^5.3.1",
"eslint-plugin-html": "^6.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-markdown": "^1.0.1",
"eslint-plugin-html": "^6.1.2",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-markdown": "^2.2.0",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^4.1.1",
"eslint-plugin-unicorn": "^23.0.0",
"execa": "^4.0.3",
"husky": "^4.3.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-unicorn": "^33.0.1",
"execa": "^5.1.1",
"husky": "^6.0.0",
"is-promise": "^4.0.0",
"lint-staged": "^10.5.2",
"merge": "^2.1.0",
"lint-staged": "^11.0.0",
"merge": "^2.1.1",
"nyc": "^15.0.0",
"posthtml-bem": "^0.2.2",
"posthtml-css-modules": "^0.1.3",
Expand Down
3 changes: 2 additions & 1 deletion src/cfg-resolve.js
Expand Up @@ -57,7 +57,8 @@ export default ({input, flags = {}}) => {
}

if (!config && !use) {
({config} = explorer.search());
const search = explorer.search();
config = search?.config;
}

if (config?.root) {
Expand Down
3 changes: 2 additions & 1 deletion src/cli.js
Expand Up @@ -9,6 +9,7 @@ import updateNotifier from 'update-notifier';
import posthtml from 'posthtml';
import outResolve from './out-resolve';
import cfgResolve from './cfg-resolve';
import pluginResolve from './plugin-resolve';

const package_ = require('../package.json');
updateNotifier({pkg: package_}).notify();
Expand Down Expand Up @@ -93,7 +94,7 @@ const read = file => new Promise(resolve => {
const interopRequire = object => object && object.__esModule ? object.default : object;

const getPlugins = config => Object.keys(config.plugins || {})
.map(plugin => interopRequire(require(plugin))(config.plugins[plugin]));
.map(plugin => interopRequire(require(pluginResolve(plugin, config.root)))(config.plugins[plugin]));

const config = cfgResolve(cli);

Expand Down
23 changes: 23 additions & 0 deletions src/plugin-resolve.js
@@ -0,0 +1,23 @@
import path from 'path';

const pluginExist = (pluginPath) => {
try {
require(pluginPath);
return true;
} catch {}

return false;
}

export default (pluginName, root = './') => {
if (pluginExist(pluginName)) {
return pluginName;
}

const pluginResolvePath = path.resolve(path.join(root, pluginName));
if (pluginExist(pluginResolvePath)) {
return pluginResolvePath;
}

return pluginName;
}
5 changes: 5 additions & 0 deletions test/plugins/custom-plugin.js
@@ -0,0 +1,5 @@
module.exports = function (options) {
return function (tree) {
return tree;
};
}
13 changes: 13 additions & 0 deletions test/test-cli.js
Expand Up @@ -65,6 +65,19 @@ test('Transform html from two file', async t => {
t.is((await read('test/expected/output-indent.html')), (await read(`${folder}/input-indent.html`)));
});

test('Dont not transform html with local plugin', async t => {
const filename = tempfile('.html');
await execa(cli, [
'test/fixtures/input.html',
'-o',
filename,
'-u',
'test/plugins/custom-plugin.js',
]);
t.true(await pathExists(filename));
t.is((await read('test/fixtures/input.html')), (await read(filename)));
});

// test('Transform html with options replace', async t => {
// t.plan(2);
// const folder = await tempfile();
Expand Down
19 changes: 19 additions & 0 deletions test/test-plugin-resolve.js
@@ -0,0 +1,19 @@
import path from 'path';
import test from 'ava';
import pluginResolve from '../src/plugin-resolve';

test('should return function', t => {
t.true(typeof pluginResolve === 'function');
});

test('should return node_modules module path', t => {
const pluginName = 'posthtml-custom-elements';
const pluginPath = pluginResolve(pluginName);
t.is(pluginPath, pluginName);
});

test('should return custom module path', t => {
const pluginName = 'test/plugins/custom-plugin.js';
const pluginPath = pluginResolve(pluginName);
t.is(pluginPath, path.resolve(path.join('./', pluginName)));
});

0 comments on commit bc0fcfb

Please sign in to comment.