mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-01 01:38:07 +08:00
It now takes a flag to customise the CWD that it runs, and also correctly passes all stylelint arguments through. Before any stylelint argument that had a dash in would be passed through twice, and that would cause stylelint to error. Bug: 1184228 Change-Id: I21c0d9561dcd055968cf4bf9b4514b8184040b88 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2732368 Commit-Queue: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Auto-Submit: Jack Franklin <jacktfranklin@chromium.org> Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
61 lines
2.3 KiB
JavaScript
61 lines
2.3 KiB
JavaScript
// Copyright 2020 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
const path = require('path');
|
|
const childProcess = require('child_process');
|
|
const {
|
|
devtoolsRootPath,
|
|
stylelintExecutablePath,
|
|
nodePath,
|
|
} = require('../devtools_paths.js');
|
|
|
|
const yargsObject = require('yargs')
|
|
.option('files', {type: 'array', desc: 'One or more files to lint.'})
|
|
.option('glob', {default: '**/*.css', desc: 'A glob to choose which files to lint.'})
|
|
.option('cwd', {default: devtoolsRootPath(), desc: 'Working directory to glob from'})
|
|
.parserConfiguration({
|
|
// So that if we pass --foo-bar, Yargs only populates
|
|
// argv with '--foo-bar', not '--foo-bar' and
|
|
// 'fooBar'. This is important because if we have both
|
|
// versions and pass them to stylelint, it errors
|
|
// saying that we've passed the same argument twice.
|
|
'camel-case-expansion': false
|
|
})
|
|
.argv;
|
|
|
|
// Note: stylelint requires POSIX-formatted paths/globs, even on Windows.
|
|
// The forward slash is not a bug.
|
|
const DEFAULT_GLOB = '**/*.css';
|
|
|
|
function getCSSFilesOrGlobList() {
|
|
const files = yargsObject.files || [];
|
|
if (files.length > 0) {
|
|
return files.map(file => {
|
|
// Enforce posix file paths even on Windows
|
|
return file.split(path.sep).join(path.posix.sep);
|
|
});
|
|
}
|
|
|
|
return [yargsObject.glob || DEFAULT_GLOB];
|
|
}
|
|
|
|
function run() {
|
|
// eslint-disable-next-line no-unused-vars
|
|
const {glob, files, cwd, _, $0, ...flagsForStylelint} = yargsObject;
|
|
|
|
/*
|
|
* This reduce is a flatten, because our Node version
|
|
* doesn't have flatMap :(
|
|
*/
|
|
const extraFlagsForStylelint = Object.keys(flagsForStylelint).flatMap(key => [`--${key}`, flagsForStylelint[key]]);
|
|
|
|
const args = [
|
|
stylelintExecutablePath(), ...getCSSFilesOrGlobList(), '--fix', '--allow-empty-input', ...extraFlagsForStylelint
|
|
];
|
|
const result = childProcess.spawnSync(nodePath(), args, {encoding: 'utf-8', cwd, stdio: 'inherit'});
|
|
process.exit(result.status);
|
|
}
|
|
|
|
run();
|