Skip to content

Commit

Permalink
Chore: prepare 3.0.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Oct 9, 2017
1 parent 820c369 commit 8adae27
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 99 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](http://semver.org).

## 3.0.0 - 2017-10-09

- Changed: rename from `dest` to `filePath`.
- Changed: `dest` should contain file name (example - `/path/to/robots.txt`).

## 2.0.0 - 2017-06-20

- Chore: support `webpack` v3.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default {
## Options

- `General options` - see [generate-robotstxt](https://github.com/itgalaxy/generate-robotstxt) options.
- `dest` - (optional) directory which will be saved robots.txt (relatively of the option `output.path` value).
- `filePath` - (optional) directory which will be saved robots.txt (should be contain full path include `robots.txt` name, example - `path/to/robots.txt`).

## Related

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "robotstxt-webpack-plugin",
"version": "2.0.0",
"version": "3.0.0",
"description": "A webpack plugin to output a robots.txt file",
"license": "MIT",
"author": "itgalaxy <[email protected]>",
Expand Down Expand Up @@ -73,11 +73,11 @@
},
"scripts": {
"precommit": "lint-staged",
"lint:prettier": "prettier --list-different '{src,__tests__}/**/*.{js,jsx}' '*.js'",
"lint:prettier": "prettier --list-different '{src,__tests__}/**/*.{js,jsx}' '!src/__tests__/build/**' '*.js'",
"lint:remark": "remark . -i .gitignore -f -q",
"lint:eslint": "eslint . '.*.js' --ignore-path .gitignore --ext '.js,.jsx'",
"lint": "npm-run-all -l -p 'lint:**'",
"fix:prettier": "prettier --write '{src,__tests__}/**/*.{js,jsx}' '*.js'",
"fix:prettier": "prettier --write '{src,__tests__}/**/*.{js,jsx}' '!src/__tests__/build/**' '*.js'",
"fix:eslint": "eslint . '.*.js' --fix --ignore-path .gitignore --ext '.js,.jsx'",
"fix": "npm-run-all -l -p 'fix:**'",
"pretest": "npm run lint",
Expand Down
18 changes: 8 additions & 10 deletions src/RobotstxtWebpackPlugin.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import nodeify from "nodeify";
import path from "path";
import robotstxt from "generate-robotstxt";

export default class RobotstxtWebpackPlugin {
constructor(options = {}) {
this.options = Object.assign({}, options);
this.options = Object.assign(
{
filePath: "robots.txt"
},
options
);
}

apply(compiler) {
Expand All @@ -14,15 +18,9 @@ export default class RobotstxtWebpackPlugin {
}

generate(compilation, callback) {
const { options } = this;

return nodeify(
robotstxt(options).then(contents => {
const dest = options.dest
? path.join(options.dest, "robots.txt")
: "robots.txt";

compilation.assets[dest] = {
robotstxt(this.options).then(contents => {
compilation.assets[this.options.filePath] = {
size() {
return Buffer.byteLength(this.source(), "utf8");
},
Expand Down
139 changes: 64 additions & 75 deletions src/__tests__/build.js
Original file line number Diff line number Diff line change
@@ -1,108 +1,97 @@
import RobotstxtPlugin from "../RobotstxtWebpackPlugin";
import path from "path";
// eslint-disable-next-line node/no-unpublished-import
import test from "ava";
// eslint-disable-next-line node/no-unpublished-import
import webpack from "webpack";
import webpackConfigBase from "./configs/config-base";

const robotstxtPluginBaseOptions = {};

test.cb("should execute successfully", t => {
t.plan(4);
t.plan(4);

const options = Object.assign({}, robotstxtPluginBaseOptions);
const options = Object.assign({}, robotstxtPluginBaseOptions);

webpackConfigBase.plugins = [new RobotstxtPlugin(options)];
webpackConfigBase.plugins = [new RobotstxtPlugin(options)];

webpack(webpackConfigBase, (error, stats) => {
if (error) {
throw error;
}
webpack(webpackConfigBase, (error, stats) => {
if (error) {
throw error;
}

t.true(stats.compilation.errors.length === 0, "no compilation error");
t.true(
stats.compilation.assets["robots.txt"] !== null,
"robots.txt in assets"
);
t.true(stats.compilation.assets["robots.txt"].size() > 0);
t.true(stats.compilation.assets["robots.txt"].source().length > 0);
t.true(stats.compilation.errors.length === 0, "no compilation error");
t.true(
stats.compilation.assets["robots.txt"] !== null,
"robots.txt in assets"
);
t.true(stats.compilation.assets["robots.txt"].size() > 0);
t.true(stats.compilation.assets["robots.txt"].source().length > 0);

t.end();
});
t.end();
});
});

test.cb("should execute successfully without options", t => {
t.plan(4);
t.plan(4);

webpackConfigBase.plugins = [new RobotstxtPlugin()];
webpackConfigBase.plugins = [new RobotstxtPlugin()];

webpack(webpackConfigBase, (error, stats) => {
if (error) {
throw error;
}
webpack(webpackConfigBase, (error, stats) => {
if (error) {
throw error;
}

t.true(stats.compilation.errors.length === 0, "no compilation error");
t.true(
stats.compilation.assets["robots.txt"] !== null,
"robots.txt in assets"
);
t.true(stats.compilation.assets["robots.txt"].size() > 0);
t.true(stats.compilation.assets["robots.txt"].source().length > 0);
t.true(stats.compilation.errors.length === 0, "no compilation error");
t.true(
stats.compilation.assets["robots.txt"] !== null,
"robots.txt in assets"
);
t.true(stats.compilation.assets["robots.txt"].size() > 0);
t.true(stats.compilation.assets["robots.txt"].source().length > 0);

t.end();
});
t.end();
});
});

test.cb("should execute successfully using `dest` option", t => {
t.plan(4);

const options = Object.assign({}, robotstxtPluginBaseOptions);

options.dest = "build/nested/dir";
webpackConfigBase.plugins = [new RobotstxtPlugin(options)];

webpack(webpackConfigBase, (error, stats) => {
if (error) {
throw error;
}

t.true(stats.compilation.errors.length === 0, "no compilation error");
t.true(
stats.compilation.assets[path.join(options.dest, "robots.txt")] !==
null,
"robots.txt in assets"
);
t.true(
stats.compilation.assets[
path.join(options.dest, "robots.txt")
].size() > 0
);
t.true(
stats.compilation.assets[
path.join(options.dest, "robots.txt")
].source().length > 0
);

t.end();
});
t.plan(4);

const options = Object.assign({}, robotstxtPluginBaseOptions);

options.filePath = "build/nested/dir/robots.txt";
webpackConfigBase.plugins = [new RobotstxtPlugin(options)];

webpack(webpackConfigBase, (error, stats) => {
if (error) {
throw error;
}

t.true(stats.compilation.errors.length === 0, "no compilation error");
t.true(
stats.compilation.assets[options.filePath] !== null,
"robots.txt in assets"
);
t.true(stats.compilation.assets[options.filePath].size() > 0);
t.true(stats.compilation.assets[options.filePath].source().length > 0);

t.end();
});
});

test.cb("should throw error on invalid `generate-robotstxt` options", t => {
t.plan(1);
t.plan(1);

const options = Object.assign({}, robotstxtPluginBaseOptions);
const options = Object.assign({}, robotstxtPluginBaseOptions);

options.policy = {};
options.policy = {};

webpackConfigBase.plugins = [new RobotstxtPlugin(options)];
webpackConfigBase.plugins = [new RobotstxtPlugin(options)];

webpack(webpackConfigBase, (error, stats) => {
if (error) {
throw error;
}
webpack(webpackConfigBase, (error, stats) => {
if (error) {
throw error;
}

t.true(stats.compilation.errors.length === 1, "compilation error");
t.end();
});
t.true(stats.compilation.errors.length === 1, "compilation error");
t.end();
});
});
18 changes: 9 additions & 9 deletions src/__tests__/configs/config-base.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import path from "path";

export default {
entry: path.resolve(__dirname, "../fixtures/entry.js"),
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "../build")
},
plugins: [],
resolve: {
modules: ["web_modules", "node_modules"]
}
entry: path.resolve(__dirname, "../fixtures/entry.js"),
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "../build")
},
plugins: [],
resolve: {
modules: ["web_modules", "node_modules"]
}
};

0 comments on commit 8adae27

Please sign in to comment.