microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
553ebfbfe55a98cdc79f040fdb0b8d9c30b06164

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

gulp_scripts/formatter.js

92lines · modecode

1const { series } = require("gulp");
2const cp = require("child_process");
3
4const runPrettier = async fix => {
5 const child = cp.fork(
6 "./node_modules/@mixer/parallel-prettier/dist/index.js",
7 [
8 fix ? "--write" : "--list-different",
9 "test/**/*.ts",
10 "gulpfile.js",
11 "*.md",
12 "!CHANGELOG.md",
13 "!test/smoke/**",
14 "!src/**/*.d.ts",
15 ],
16 {
17 stdio: "inherit",
18 },
19 );
20
21 await new Promise((resolve, reject) => {
22 child.on("exit", code => {
23 code ? reject(`Prettier exited with code ${code}`) : resolve();
24 });
25 });
26};
27
28function formatPrettier(cb) {
29 runPrettier(true);
30 cb();
31}
32
33function lintPrettier(cb) {
34 runPrettier(false);
35 cb();
36}
37
38/**
39 * @typedef {{color: boolean, fix: boolean}} OptionsT
40 */
41
42/**
43 * @param {OptionsT} options_
44 */
45const runEslint = async options_ => {
46 /** @type {OptionsT} */
47 const options = Object.assign({ color: true, fix: false }, options_);
48
49 const files = ["../src/**/*.ts"];
50
51 const args = [
52 ...(options.color ? ["--color"] : ["--no-color"]),
53 ...(options.fix ? ["--fix"] : []),
54 ...files,
55 ];
56
57 const child = cp.fork("../node_modules/eslint/bin/eslint.js", args, {
58 stdio: "inherit",
59 cwd: __dirname,
60 });
61
62 await new Promise((resolve, reject) => {
63 child.on("exit", code => {
64 code ? reject(`Eslint exited with code ${code}`) : resolve();
65 });
66 });
67};
68
69function formatEslint(cb) {
70 runEslint({ fix: true });
71 cb();
72}
73
74function lintEslint(cb) {
75 runEslint({ fix: false });
76 cb();
77}
78
79const lint = series(lintPrettier, lintEslint);
80
81const format = series(formatPrettier, formatEslint);
82
83
84
85module.exports = {
86 formatPrettier,
87 formatEslint,
88 format,
89 lintPrettier,
90 lintEslint,
91 lint: lint,
92};