Skip to content

Commit 9636d7c

Browse files
author
Ivan Demidov
committed
feat(*): init project, fixed #1
1 parent fb5e530 commit 9636d7c

19 files changed

+349
-0
lines changed

.editorconfig

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.{json,yml,jade,pss,css,html}]
12+
indent_size = 2
13+
14+
[*.{js,jsx,*sublime-*}]
15+
indent_style = tab
16+
17+
[{lib/*.*,test/**/*.css,*.jpg,*.html}]
18+
insert_final_newline = false
19+
20+
[*.md]
21+
trim_trailing_whitespace = false

.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# OS
2+
.DS_Store
3+
._*
4+
5+
# NODEJS
6+
node_modules
7+
npm-debug.log
8+
lib/
9+
coverage/
10+
# Sublime
11+
*.sublime*
12+
13+
# Nyc
14+
.nyc_output/

.npmignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/
2+
src/
3+
.gitignore
4+
.travis.yml
5+
coverage/

.travis.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- v6
5+
- v5
6+
- v4
7+
8+
after_success:
9+
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'

changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## [0.0.0] - 16-1-2016
2+
### Init
3+
- Init, fixed #1

license

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Ivan Demidov <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

package.json

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{
2+
"name": "post-load-plugins",
3+
"version": "0.0.0",
4+
"description": "Automatically loads plug-ins with configuration",
5+
"engines": {
6+
"node": ">=4"
7+
},
8+
"main": "lib/index.js",
9+
"scripts": {
10+
"pretest": "clinton",
11+
"test": "xo src/**/*.js test/**/*.js && nyc ava",
12+
"clean": "rm -rf lib && mkdir lib",
13+
"build": "npm run clean && babel src/ -d lib/",
14+
"prepublish": "npm run build",
15+
"update": "updtr && ava-codemods --force"
16+
},
17+
"files": [
18+
"lib/"
19+
],
20+
"dependencies": {
21+
"chalk": "^1.1.3",
22+
"indent-string": "^3.0.0",
23+
"log-symbols": "^1.0.2",
24+
"post-config": "0.0.1",
25+
"post-sequence": "^0.1.0",
26+
"text-table": "^0.2.0"
27+
},
28+
"devDependencies": {
29+
"ava": "*",
30+
"ava-codemods": "^0.2.1",
31+
"babel-cli": "^6.10.1",
32+
"babel-plugin-add-module-exports": "^0.2.0",
33+
"babel-plugin-array-includes": "^2.0.3",
34+
"babel-preset-es2015": "^6.9.0",
35+
"babel-preset-min": "^0.1.15",
36+
"babel-register": "^6.7.2",
37+
"clinton": "^0.5.0",
38+
"coveralls": "^2.11.9",
39+
"del": "^2.2.1",
40+
"nyc": "^6.6.1",
41+
"postcss-cli": "^2.5.2",
42+
"posthtml": "^0.9.0",
43+
"posthtml-bem": "^0.2.2",
44+
"posthtml-css-modules": "^0.1.0",
45+
"posthtml-each": "^1.0.1",
46+
"posthtml-include": "^1.1.0",
47+
"posthtml-modules": "^0.4.0",
48+
"posthtml-standard-config": "0.0.5",
49+
"posthtml-style-to-file": "^0.1.1",
50+
"read-pkg": "^1.1.0",
51+
"temp-write": "^2.1.0",
52+
"updtr": "^0.2.1",
53+
"xo": "*"
54+
},
55+
"babel": {
56+
"presets": [
57+
"es2015"
58+
],
59+
"plugins": [
60+
"array-includes",
61+
"add-module-exports"
62+
],
63+
"comments": false,
64+
"compact": true,
65+
"minified": true
66+
},
67+
"ava": {
68+
"require": [
69+
"babel-register"
70+
]
71+
},
72+
"clinton": {
73+
"rules": {
74+
"pkg-main": [
75+
"off"
76+
]
77+
}
78+
},
79+
"posthtml": {
80+
"bem": {
81+
"elemPrefix": "__",
82+
"modPrefix": "--",
83+
"modDlmtr": "-"
84+
},
85+
"styleToFile": {
86+
"path": "./dist/styleToFile.css"
87+
}
88+
},
89+
"license": "MIT",
90+
"repository": {
91+
"type": "git",
92+
"url": "git+https://github.com/posthtml/posthtml-load-plugins.git"
93+
},
94+
"homepage": "https://github.com/posthtml/posthtml-load-plugins#readme",
95+
"bugs": {
96+
"url": "https://github.com/posthtml/posthtml-load-plugins/issues"
97+
},
98+
"author": {
99+
"name": "Michael Ciniawky",
100+
"email": "[email protected]"
101+
},
102+
"contributors": [
103+
{
104+
"name": "Ivan Demidov",
105+
"email": "[email protected]",
106+
"url": "https://twitter.com/Scrum_"
107+
}
108+
]
109+
}

README.md readme.md

File renamed without changes.

src/index.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* eslint import/no-dynamic-require: 0 */
2+
import postSequence from 'post-sequence';
3+
import logSymbols from 'log-symbols';
4+
import chalk from 'chalk';
5+
import table from 'text-table';
6+
import indentString from 'indent-string';
7+
import postConfig from 'post-config';
8+
9+
const toKebabCase = plugin => plugin.replace(/[A-Z]/g, match => `-${match.toLowerCase()}`);
10+
const getModuleName = plugin => `posthtml-${toKebabCase(plugin)}`;
11+
12+
function processor(plugin, warning) {
13+
try {
14+
return require(getModuleName(plugin));
15+
} catch (err) {
16+
warning.push(Array.of(indentString(`${logSymbols.error}`, 4), `posthtml-${plugin}`));
17+
return () => {};
18+
}
19+
}
20+
21+
export default (cfg, extCfg) => {
22+
let warning = [];
23+
const config = postSequence(postConfig(cfg, extCfg), {processor: 'posthtml'});
24+
const plugins = Object.keys(config)
25+
.map(plugin => processor(plugin, warning)(config[plugin]))
26+
.filter(plugin => plugin !== undefined);
27+
28+
if (warning.length > 0) {
29+
console.log(indentString(`${logSymbols.warning} ${chalk.yellow('warning'.toUpperCase())} plugins is not installed`, 2));
30+
console.log(`${table(warning)}`);
31+
}
32+
33+
return plugins;
34+
};

test/dist/css-modules.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"title": "_title_116zl_1 _heading_9dkf",
3+
"profile": {
4+
"user": "_profile_user_f93j"
5+
}
6+
}

test/dist/style.css

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
div.content{background: #fff;}
3+
h1.content__title{font-size: 3em;}
4+
p.content__text.content__text-red{color: red;}

test/dist/styleToFile.css

Whitespace-only changes.

test/expected/output-config-pkg.html

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>PostHTML</title>
7+
<link rel="stylesheet" href="index.css">
8+
</head>
9+
10+
<body>
11+
<div class="container">
12+
<header class="header">
13+
<h1 class="header__title">PostHTML Example</h1>
14+
</header>
15+
<main class="main">
16+
<div style="background: #fff;" class="content">
17+
<h1 style="font-size: 3em;" class="content__title">Title</h1>
18+
<p style="color: red;" class="content__text content__text-red">Text</p>
19+
</div>
20+
</main>
21+
</div>
22+
23+
<script src="index.js"></script>
24+
</body>
25+
26+
</html>

test/expected/output-modules.html

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head></head>
4+
<body>
5+
<h1 class="_title_116zl_1 _heading_9dkf">My profile</h1>
6+
<div class="_profile_user_f93j">John</div>
7+
</body>
8+
</html>

test/fixtures/input-modules.html

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head></head>
4+
<body>
5+
<h1 css-module="title">My profile</h1>
6+
<div css-module="profile.user">John</div>
7+
</body>
8+
</html>

test/fixtures/input.html

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>PostHTML</title>
7+
<link rel="stylesheet" href="index.css">
8+
</head>
9+
10+
<body>
11+
<div class="container">
12+
<header block="header">
13+
<h1 elem="title">PostHTML Example</h1>
14+
</header>
15+
<main block="main">
16+
<div block="content" style="background: #fff;">
17+
<h1 elem="title" style="font-size: 3em;">Title</h1>
18+
<p elem="text" mods="red" style="color: red;">Text</p>
19+
</div>
20+
</main>
21+
</div>
22+
23+
<script src="index.js"></script>
24+
</body>
25+
26+
</html>

test/fixtures/modules.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"include": ""
3+
}

test/fixtures/posthtml.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"bem": {
3+
"elemPrefix": "__",
4+
"modPrefix": "-",
5+
"modDlmtr": "--"
6+
},
7+
"include": {
8+
"root": "test/",
9+
"encoding": "utf-8"
10+
},
11+
"styleToFile": {
12+
"path": "dist/style.css"
13+
}
14+
}

test/test.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const readFile = require('fs').readFile;
2+
const posthtml = require('posthtml');
3+
const test = require('ava');
4+
const plugin = require('../src/index.js');
5+
6+
const read = path => new Promise((resolve, reject) => {
7+
readFile(path, 'utf8', (err, data) => {
8+
if (err) {
9+
reject(err);
10+
}
11+
return resolve(data);
12+
});
13+
});
14+
15+
test('Plugin return array', t => {
16+
t.true(Array.isArray(plugin()));
17+
});
18+
19+
test('Plugin reads custom json config from posthtml.json', async t => {
20+
t.is(
21+
(await read('expected/output-config-pkg.html')),
22+
(await posthtml(plugin('fixtures/posthtml.json')).process(await read('fixtures/input.html'))).html
23+
);
24+
});
25+
26+
test('test witch posthtml-css-modules', async t => {
27+
t.is(
28+
(await read('expected/output-modules.html')),
29+
(await posthtml(plugin('fixtures/modules.json', {'posthtml-css-modules': 'dist/css-modules.json', 'posthtml-each': {}})).process(await read('fixtures/input-modules.html'))).html
30+
);
31+
});
32+
33+
test('should throw not install plugin posthtml-css', async t => {
34+
t.is(
35+
(await read('expected/output-config-pkg.html')),
36+
(await posthtml(plugin('fixtures/posthtml.json', {css: {}, postcss: {}})).process(await read('fixtures/input.html'))).html
37+
);
38+
});

0 commit comments

Comments
 (0)