summaryrefslogtreecommitdiff
path: root/scripts/frontend
diff options
context:
space:
mode:
authorTim Zallmann <tzallmann@gitlab.com>2018-05-26 20:01:02 +0200
committerLukas Eipert <leipert@gitlab.com>2018-06-15 12:43:03 +0200
commit930baeb92af0dbd97931f8308dec6664819863dc (patch)
tree1a25676466209734c26e6e823eda1e6450e96cd9 /scripts/frontend
parent5f3a219e14c27bb2e3a305f8c9170aaca3220be1 (diff)
downloadgitlab-ce-930baeb92af0dbd97931f8308dec6664819863dc.tar.gz
Added possibility to run prettier against one specific directory to make our conversion easier
Diffstat (limited to 'scripts/frontend')
-rw-r--r--scripts/frontend/prettier.js12
1 files changed, 9 insertions, 3 deletions
diff --git a/scripts/frontend/prettier.js b/scripts/frontend/prettier.js
index 4979ec3c409..8304edcecec 100644
--- a/scripts/frontend/prettier.js
+++ b/scripts/frontend/prettier.js
@@ -9,6 +9,8 @@ const getStagedFiles = require('./frontend_script_utils').getStagedFiles;
const mode = process.argv[2] || 'check';
const shouldSave = mode === 'save' || mode === 'save-all';
const allFiles = mode === 'check-all' || mode === 'save-all';
+let dirPath = process.argv[3] || '';
+if (dirPath.charAt(dirPath.length-1) !== '/') dirPath += '/';
const config = {
patterns: ['**/*.js', '**/*.vue', '**/*.scss'],
@@ -39,9 +41,9 @@ prettierIgnore.add(
const availableExtensions = Object.keys(config.parsers);
-console.log(`Loading ${allFiles ? 'All' : 'Staged'} Files ...`);
+console.log(`Loading ${allFiles ? 'All' : 'Selected'} Files ...`);
-const stagedFiles = allFiles ? null : getStagedFiles(availableExtensions.map(ext => `*.${ext}`));
+const stagedFiles = allFiles || dirPath ? null : getStagedFiles(availableExtensions.map(ext => `*.${ext}`));
if (stagedFiles) {
if (!stagedFiles.length || (stagedFiles.length === 1 && !stagedFiles[0])) {
@@ -60,6 +62,11 @@ if (allFiles) {
const patterns = config.patterns;
const globPattern = patterns.length > 1 ? `{${patterns.join(',')}}` : `${patterns.join(',')}`;
files = glob.sync(globPattern, { ignore }).filter(f => allFiles || stagedFiles.includes(f));
+} else if (dirPath) {
+ const ignore = config.ignore;
+ const patterns = config.patterns.map((item) => {return dirPath + item;});
+ const globPattern = patterns.length > 1 ? `{${patterns.join(',')}}` : `${patterns.join(',')}`;
+ files = glob.sync(globPattern, { ignore });
} else {
files = stagedFiles.filter(f => availableExtensions.includes(f.split('.').pop()));
}
@@ -73,7 +80,6 @@ if (!files.length) {
console.log(`${shouldSave ? 'Updating' : 'Checking'} ${files.length} file(s)`);
-
files.forEach(file => {
try {
prettier