microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
6ffe6391b47139538590a461d4e09100fcc1fb9d

Branches

Tags

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

Clone

HTTPS

Download ZIP

gulp_scripts/formatter.js

91lines · 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 "!SECURITY.md",
16 ],
17 {
18 stdio: "inherit",
19 },
20 );
21
22 await new Promise((resolve, reject) => {
23 child.on("exit", code => {
24 code ? reject(`Prettier exited with code ${code}`) : resolve();
25 });
26 });
27};
28
29function formatPrettier(cb) {
30 runPrettier(true);
31 cb();
32}
33
34function lintPrettier(cb) {
35 runPrettier(false);
36 cb();
37}
38
39/**
40 * @typedef {{color: boolean, fix: boolean}} OptionsT
41 */
42
43/**
44 * @param {OptionsT} options_
45 */
46const runEslint = async options_ => {
47 /** @type {OptionsT} */
48 const options = Object.assign({ color: true, fix: false }, options_);
49
50 const files = ["../src/**/*.ts"];
51
52 const args = [
53 ...(options.color ? ["--color"] : ["--no-color"]),
54 ...(options.fix ? ["--fix"] : []),
55 ...files,
56 ];
57
58 const child = cp.fork("../node_modules/eslint/bin/eslint.js", args, {
59 stdio: "inherit",
60 cwd: __dirname,
61 });
62
63 await new Promise((resolve, reject) => {
64 child.on("exit", code => {
65 code ? reject(`Eslint exited with code ${code}`) : resolve();
66 });
67 });
68};
69
70function formatEslint(cb) {
71 runEslint({ fix: true });
72 cb();
73}
74
75function lintEslint(cb) {
76 runEslint({ fix: false });
77 cb();
78}
79
80const lint = series(lintPrettier, lintEslint);
81
82const format = series(formatPrettier, formatEslint);
83
84module.exports = {
85 formatPrettier,
86 formatEslint,
87 format,
88 lintPrettier,
89 lintEslint,
90 lint: lint,
91};