Browse Source

simplified .cleanignore, added `@` pattern syntax

telamonian 5 years ago
parent
commit
aeb2115a07
2 changed files with 40 additions and 17 deletions
  1. 20 13
      .cleanignore
  2. 20 4
      clean.py

+ 20 - 13
.cleanignore

@@ -1,16 +1,23 @@
-# jetbrains IDE stuff
-*.iml
-.idea/
+# files that match any pattern from .cleanignore are NOT removed by
+# the `jlpm clean:slate` command. Same syntax as .gitignore (plus the @).
+#
+# @: if a pattern starts with "@", some includes are automatically added,
+# in addition to the base exclude pattern. For example:
+#
+# @*.foo
+#
+# will add:
+#
+# *.foo
+# !packages/**/*.foo
+# !**/node_modules/**/*.foo
+#
+# These help ensure that all node_modules dirs are cleaned and that
+# sibling installs of labextensions are not cleaned.
 
-# avoid matching to sibling installs or node_modules
-!packages/**/*.iml
-!packages/**/.idea/
-!**/node_modules/**/*.iml
-!**/node_modules/**/.idea/
+# jetbrains IDE stuff
+@*.iml
+@.idea/
 
 # ms IDE stuff
-.vscode
-
-# avoid matching to sibling installs or node_modules
-!packages/**/.vscode
-!**/node_modules/**/.vscode
+@.vscode

+ 20 - 4
clean.py

@@ -15,12 +15,28 @@ if os.name == 'nt':
 
 subprocess.check_call('python -m pip uninstall -y jupyterlab'.split(), cwd=here)
 
+def resolvePattern(pat):
+    """handle a leading `#` or `@` in a pattern
+    """
+    pat = pat.strip()
+
+    if not pat or pat.startswith('#'):
+        return []
+    elif pat.startswith('@'):
+        raw = pat[1:]
+        return [
+            raw,
+            f'!packages/**/{raw}',
+            f'!**/node_modules/**/{raw}'
+        ]
+    else:
+        return [pat]
+
 # get the exclude patterns listed in .cleanignore
 with open(os.path.join(here, '.cleanignore')) as f:
-    git_clean_exclude = [f'--exclude={stripped}'
-                         for stripped in
-                         (line.strip() for line in f)
-                         if stripped and not stripped.startswith('#')]
+    git_clean_exclude = [f'--exclude={pat}'
+                         for line in f
+                         for pat in resolvePattern(line)]
 
 git_clean_command = ['git', 'clean', '-dfx'] + git_clean_exclude
 subprocess.check_call(git_clean_command, cwd=here)