mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-02 18:11:04 +08:00
depot_tools ships a "vpython" binary that is added to the $PATH for all Chromium engineers. This binary is versioned by depot_tools which we roll in ourselves as part of `gclient sync`. By using `vpython` instead of `python`, we are no longer depended on the Python version installed locally and instead use the version we pull in from DEPS. R=liviurau@chromium.org Change-Id: If49a54c24b6cf129ff843cd9ca1140a723a78afb Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2571462 Reviewed-by: Liviu Rau <liviurau@chromium.org> Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
51 lines
1.4 KiB
Python
Executable File
51 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env vpython
|
|
#
|
|
# 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.
|
|
|
|
import sys
|
|
from os import path
|
|
from subprocess import Popen
|
|
|
|
scripts_path = path.dirname(path.dirname(path.abspath(__file__)))
|
|
sys.path.append(scripts_path)
|
|
import devtools_paths
|
|
|
|
ROOT_DIRECTORY = path.dirname(scripts_path)
|
|
|
|
# Note: stylelint requires POSIX-formatted paths/globs, even on Windows.
|
|
# The forward slash is not a bug.
|
|
DEFAULT_GLOB = '**/*.css'
|
|
|
|
|
|
def get_css_files_or_glob():
|
|
files = sys.argv[1:]
|
|
if len(files):
|
|
# TODO(crbug.com/1095940): Use `pathlib.PurePath(...).as_posix`
|
|
# instead of `replace` once we drop support for Python 2.
|
|
files = [f.replace('\\', '/') for f in files]
|
|
return files
|
|
return [DEFAULT_GLOB]
|
|
|
|
|
|
def main():
|
|
exec_command = [
|
|
devtools_paths.node_path(),
|
|
path.join(ROOT_DIRECTORY, 'node_modules', 'stylelint', 'bin',
|
|
'stylelint.js'),
|
|
]
|
|
exec_command.extend(get_css_files_or_glob())
|
|
exec_command.append('--fix')
|
|
# If all affected files are excluded due to .stylelintignore, exit gracefully
|
|
exec_command.append('--allow-empty-input')
|
|
|
|
stylelint_proc = Popen(exec_command, cwd=ROOT_DIRECTORY)
|
|
stylelint_proc.communicate()
|
|
|
|
sys.exit(stylelint_proc.returncode)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|