microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
5b0c8906f37aa1a6e91a95bd3c3350e9e0b8bbb5

Branches

Tags

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

Clone

HTTPS

Download ZIP

gulp_scripts/formatter.js

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