microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
361fa169c488daa76e86cd7bbd50e5e1798a4e33

Branches

Tags

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

Clone

HTTPS

Download ZIP

gulp_scripts/formatter.js

94lines · modeblame

589d9b66benjaminbi3 years ago1const { series } = require("gulp");
2const cp = require("child_process");
3
4const runPrettier = async fix => {
5const child = cp.fork(
6"./node_modules/@mixer/parallel-prettier/dist/index.js",
7[
8fix ? "--write" : "--list-different",
9"test/**/*.ts",
10"gulpfile.js",
11"*.md",
12"!CHANGELOG.md",
4cfdeb8fEzio Li9 months ago13"!test/smoke/node_modules/**",
14"!test/smoke/out/**",
15"!test/smoke/.vscode-test/**",
589d9b66benjaminbi3 years ago16"!src/**/*.d.ts",
3eacedf2microsoft-github-policy-service[bot]3 years ago17"!SECURITY.md",
acccf52dEzio Li9 months ago18"!test/smoke/resources/sampleReactNativeProject/**"
589d9b66benjaminbi3 years ago19],
20{
21stdio: "inherit",
22},
23);
24
25await new Promise((resolve, reject) => {
26child.on("exit", code => {
27code ? reject(`Prettier exited with code ${code}`) : resolve();
28});
29});
30};
31
32function formatPrettier(cb) {
33runPrettier(true);
34cb();
35}
36
37function lintPrettier(cb) {
38runPrettier(false);
39cb();
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} */
51const options = Object.assign({ color: true, fix: false }, options_);
52
53const files = ["../src/**/*.ts"];
54
55const args = [
56...(options.color ? ["--color"] : ["--no-color"]),
57...(options.fix ? ["--fix"] : []),
58...files,
59];
60
61const child = cp.fork("../node_modules/eslint/bin/eslint.js", args, {
62stdio: "inherit",
63cwd: __dirname,
64});
65
66await new Promise((resolve, reject) => {
67child.on("exit", code => {
68code ? reject(`Eslint exited with code ${code}`) : resolve();
69});
70});
71};
72
73function formatEslint(cb) {
74runEslint({ fix: true });
75cb();
76}
77
78function lintEslint(cb) {
79runEslint({ fix: false });
80cb();
81}
82
83const lint = series(lintPrettier, lintEslint);
84
85const format = series(formatPrettier, formatEslint);
86
87module.exports = {
88formatPrettier,
89formatEslint,
90format,
91lintPrettier,
92lintEslint,
93lint: lint,
e4001e74benjaminbi3 years ago94};