Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Apply Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
artiebits committed Jan 7, 2021
1 parent cfa589e commit 4a2446c
Show file tree
Hide file tree
Showing 20 changed files with 38 additions and 51 deletions.
6 changes: 2 additions & 4 deletions examples/electron-react/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
module.exports = {
extends: [
"plugin:react/recommended"
],
extends: ["plugin:react/recommended"],
settings: {
react: {
version: "latest",
},
},
};
};
1 change: 0 additions & 1 deletion examples/electron-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ yarn
yarn dev
```


### Scripts

```bash
Expand Down
4 changes: 2 additions & 2 deletions examples/electron-react/src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let mainWindow;

function createMainWindow() {
const window = new BrowserWindow({
webPreferences: { nodeIntegration: true }
webPreferences: { nodeIntegration: true },
});

if (isDevelopment) {
Expand All @@ -25,7 +25,7 @@ function createMainWindow() {
formatUrl({
pathname: path.join(__dirname, "index.html"),
protocol: "file",
slashes: true
slashes: true,
})
);
}
Expand Down
14 changes: 4 additions & 10 deletions examples/electron-react/src/renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,22 @@ function App() {
const [selectedPrinter, selectPrinter] = useState(null);

useEffect(() => {
printer
.getPrinters()
.then(setPrinters)
.catch(console.error);
printer.getPrinters().then(setPrinters).catch(console.error);
}, []);

const onPrinterChangeHandler = event => {
const onPrinterChangeHandler = (event) => {
selectPrinter(event.target.value);
};

const onSubmitHandler = event => {
const onSubmitHandler = (event) => {
event.preventDefault();

const options = {};
if (selectedPrinter) {
options.printer = selectedPrinter;
}

printer
.print(pdfUrl, options)
.then(console.log)
.catch(console.error);
printer.print(pdfUrl, options).then(console.log).catch(console.error);
};

const renderPrinter = (printer, index) => {
Expand Down
5 changes: 3 additions & 2 deletions examples/express-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ npm run start
```

It will start a server on http://localhost:8080.
* Open [/list](http://localhost:8080/list) to retrieve a list of printers.
* Open [/print](http://localhost:8080/print?url=https://easypost-files.s3-us-west-2.amazonaws.com/files/postage_label/20190716/15ad63c69e654e228d92a1ee0aa9d536.pdf) to print a PDF file.

- Open [/list](http://localhost:8080/list) to retrieve a list of printers.
- Open [/print](http://localhost:8080/print?url=https://easypost-files.s3-us-west-2.amazonaws.com/files/postage_label/20190716/15ad63c69e654e228d92a1ee0aa9d536.pdf) to print a PDF file.
5 changes: 1 addition & 4 deletions examples/express-server/src/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ function list(request, response) {
response.send({ status: "error", error });
}

printer
.getPrinters()
.then(onSuccess)
.catch(onError);
printer.getPrinters().then(onSuccess).catch(onError);
}

module.exports = list;
8 changes: 3 additions & 5 deletions examples/express-server/src/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ function print(request, response) {
}

fetch(request.query.url)
.then(res => res.buffer())
.then(buffer => {
.then((res) => res.buffer())
.then((buffer) => {
const pdf = save(buffer);

printer
Expand All @@ -36,9 +36,7 @@ function remove(pdf) {
}

function randomString() {
return Math.random()
.toString(36)
.substring(7);
return Math.random().toString(36).substring(7);
}

module.exports = print;
2 changes: 1 addition & 1 deletion src/electron-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ const isUsingAsar =
process.mainModule &&
process.mainModule.filename.includes("app.asar");

export const fixPathForAsarUnpack = path => {
export const fixPathForAsarUnpack = (path) => {
return isUsingAsar ? path.replace("app.asar", "app.asar.unpacked") : path;
};
6 changes: 3 additions & 3 deletions src/electron-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ test("fixes path for Electron apps", () => {
global.process = {
...originalProcess,
versions: {
electron: "0.0.0"
electron: "0.0.0",
},
mainModule: {
filename: "/app.asar/index.html"
}
filename: "/app.asar/index.html",
},
};

expect(require("./electron-util").fixPathForAsarUnpack(path)).toBe(
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ switch (os.platform()) {
module.exports = {
print: require("./unix/print"),
getPrinters: require("./unix/get-printers"),
getDefaultPrinter: require("./unix/get-default-printer")
getDefaultPrinter: require("./unix/get-default-printer"),
};
break;
case "win32":
module.exports = {
print: require("./win32/print"),
getPrinters: require("./win32/get-printers"),
getDefaultPrinter: require("./win32/get-default-printer")
getDefaultPrinter: require("./win32/get-default-printer"),
};
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jest.mock("os");
describe.each([
["Linux", "linux"],
["Darwin", "darwin"],
["Windows", "win32"]
["Windows", "win32"],
])("%i operating system", (_, alias) => {
test("has `print`, `getDefaultPrinter` and `getPrinters` methods", () => {
jest.resetModules();
Expand Down
2 changes: 1 addition & 1 deletion src/unix/get-default-printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const execAsync = require("../execAsync");

const getDefaultPrinter = () => {
const parseResult = output => output.substr(output.indexOf(":") + 1).trim();
const parseResult = (output) => output.substr(output.indexOf(":") + 1).trim();
return execAsync("lpstat", ["-d"], parseResult);
};

Expand Down
4 changes: 2 additions & 2 deletions src/unix/get-printers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
const execAsync = require("../execAsync");

const getPrinters = () => {
const parseResult = output => {
const parseResult = (output) => {
return output
.trim()
.split("\n")
.map(e => e.substr(0, e.indexOf(" ")));
.map((e) => e.substr(0, e.indexOf(" ")));
};
return execAsync("lpstat", ["-a"], parseResult);
};
Expand Down
2 changes: 1 addition & 1 deletion src/unix/get-printers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test("returns list of available printers", () => {
);
return expect(getPrinters()).resolves.toStrictEqual([
"macOS_Printer",
"Zebra"
"Zebra",
]);
});

Expand Down
2 changes: 1 addition & 1 deletion src/unix/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const print = (pdf, options = {}) => {

if (unix) {
if (!Array.isArray(unix)) throw "options.unix should be an array";
unix.map(unixArg => args.push(...unixArg.split(" ")));
unix.map((unixArg) => args.push(...unixArg.split(" ")));
}

return execAsync("lp", args);
Expand Down
4 changes: 2 additions & 2 deletions src/unix/print.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test("sends PDF file to the specific printer", () => {
const filename = "assets/pdf-sample.pdf";
const printer = "Zebra";
const options = {
printer
printer,
};
return print(filename, options).then(() => {
expect(execAsync).toHaveBeenCalledWith("lp", [filename, "-d", printer]);
Expand All @@ -64,7 +64,7 @@ test("allows users to pass OS specific options", () => {
"-d",
printer,
"-o",
"sides=one-sided"
"sides=one-sided",
]);
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/win32/get-default-printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
const execAsync = require("../execAsync");

const getDefaultPrinter = () => {
const stdoutHandler = stdout => {
const stdoutHandler = (stdout) => {
const printers = stdout
.trim()
.split(/\s*[\r\n]+/)
// We remove the first element from the result because
// <code>wmic printer get name</code> will show a list of printers under "Name" title.
.slice(1);
const defaultPrinter = printers.filter(e => e.indexOf("TRUE") === 0);
const defaultPrinter = printers.filter((e) => e.indexOf("TRUE") === 0);
if (defaultPrinter.length === 0) {
return "";
}
Expand Down
2 changes: 1 addition & 1 deletion src/win32/get-printers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const execAsync = require("../execAsync");

const getPrinters = () => {
const stdoutHandler = stdout =>
const stdoutHandler = (stdout) =>
stdout
.trim()
.split(/\s*[\r\n]+/)
Expand Down
2 changes: 1 addition & 1 deletion src/win32/get-printers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test("returns list of available printers", () => {
// Windows will write to stdout a list of printers under "Name" title.
return expect(getPrinters()).resolves.toStrictEqual([
"Windows Printer",
"Zebra"
"Zebra",
]);
});

Expand Down
10 changes: 5 additions & 5 deletions webpack.production.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ module.exports = {
output: {
path: path.resolve(__dirname, "dist"),
filename: "bundle.js",
libraryTarget: "umd"
libraryTarget: "umd",
},
plugins: [
new CleanWebpackPlugin(),
new CopyPlugin([
{ from: "./src/win32/SumatraPDF.exe" },
{ from: "./src/types.d.ts" }
])
{ from: "./src/types.d.ts" },
]),
],
target: "node",
node: {
__dirname: false
}
__dirname: false,
},
};

0 comments on commit 4a2446c

Please sign in to comment.