Browse Source

manage bin directory with biome

Yuki Takei 2 months ago
parent
commit
d8e3d33a28

+ 13 - 9
bin/data-migrations/src/index.js

@@ -1,4 +1,3 @@
-
 /* eslint-disable no-undef, regex/invalid, import/extensions */
 // ignore lint error because this file is js as mongoshell
 
@@ -20,12 +19,17 @@ var migrationModule = process.env.MIGRATION_MODULE;
 var migrationModules = require(`./migrations/${migrationModule}`);
 
 if (migrationModules.length === 0) {
-  throw Error('No valid migrationModules found. Please enter a valid environment variable');
+  throw Error(
+    'No valid migrationModules found. Please enter a valid environment variable',
+  );
 }
 
 /** @type {ReplaceLatestRevisions} */
 function replaceLatestRevisions(body, migrationModules) {
-  return migrationModules.reduce((replacedBody, module) => module(replacedBody), body);
+  return migrationModules.reduce(
+    (replacedBody, module) => module(replacedBody),
+    body,
+  );
 }
 
 var pipeline = [
@@ -51,7 +55,6 @@ var pipeline = [
   },
 ];
 
-
 try {
   /** @type {Operations} */
   var operations = [];
@@ -70,7 +73,9 @@ try {
     }
 
     try {
-      var replacedBody = replaceLatestRevisions(doc.body, [...migrationModules]);
+      var replacedBody = replaceLatestRevisions(doc.body, [
+        ...migrationModules,
+      ]);
 
       operations.push({
         updateOne: {
@@ -91,15 +96,14 @@ try {
 
         operations = [];
       }
-    }
-    catch (err) {
+    } catch (err) {
       print(`Error processing document ${doc?._id}: ${err}`);
     }
   }
 
   print('Migration complete!');
-}
-catch (err) {
+  print(`Processed documents count: ${processedCount}`);
+} catch (err) {
   print(`Fatal error during migration: ${err}`);
   throw err;
 }

+ 0 - 1
bin/data-migrations/src/migrations/v60x/bracketlink.js

@@ -8,7 +8,6 @@ module.exports = [
    */
   (body) => {
     // https://regex101.com/r/btZ4hc/1
-    // eslint-disable-next-line regex/invalid
     const oldBracketLinkRegExp = /(?<!\[)\[{1}(\/.*?)\]{1}(?!\])/g; // Page Link old format
     return body.replace(oldBracketLinkRegExp, '[[$1]]');
   },

+ 8 - 1
bin/data-migrations/src/migrations/v60x/index.js

@@ -5,4 +5,11 @@ const plantUML = require('./plantuml');
 const remarkGrowiDirective = require('./remark-growi-directive');
 const tsv = require('./tsv');
 
-module.exports = [...bracketlink, ...csv, ...drawio, ...plantUML, ...tsv, ...remarkGrowiDirective];
+module.exports = [
+  ...bracketlink,
+  ...csv,
+  ...drawio,
+  ...plantUML,
+  ...tsv,
+  ...remarkGrowiDirective,
+];

+ 7 - 2
bin/data-migrations/src/migrations/v60x/remark-growi-directive/remark-growi-directive.js

@@ -25,10 +25,15 @@ module.exports = [
         // 1. Previous line contains an HTML tag (ends with >)
         // 2. Previous line is not empty
         // 3. Previous line is not a directive line
-        const isPrevLineHtmlTag = prevLine.match(/>[^\n]*$/) && !prevLine.match(directivePattern);
+        const isPrevLineHtmlTag =
+          prevLine.match(/>[^\n]*$/) && !prevLine.match(directivePattern);
         const isNotAfterDirective = i - 1 !== lastDirectiveLineIndex;
 
-        if (isPrevLineHtmlTag && prevLine.trim() !== '' && isNotAfterDirective) {
+        if (
+          isPrevLineHtmlTag &&
+          prevLine.trim() !== '' &&
+          isNotAfterDirective
+        ) {
           lines.splice(i, 0, '');
           i++;
         }

+ 23 - 9
bin/data-migrations/src/migrations/v60x/remark-growi-directive/remark-growi-directive.spec.js

@@ -1,23 +1,34 @@
 import fs from 'node:fs';
 import path from 'node:path';
-
-import { describe, test, expect } from 'vitest';
+import { describe, expect, test } from 'vitest';
 
 import migrations from './remark-growi-directive';
 
 describe('remark-growi-directive migrations', () => {
   test('should transform example.md to match example-expected.md', () => {
     const input = fs.readFileSync(path.join(__dirname, 'example.md'), 'utf8');
-    const expected = fs.readFileSync(path.join(__dirname, 'example-expected.md'), 'utf8');
-
-    const result = migrations.reduce((text, migration) => migration(text), input);
+    const expected = fs.readFileSync(
+      path.join(__dirname, 'example-expected.md'),
+      'utf8',
+    );
+
+    const result = migrations.reduce(
+      (text, migration) => migration(text),
+      input,
+    );
     expect(result).toBe(expected);
   });
 
   test('should not modify example-expected.md', () => {
-    const input = fs.readFileSync(path.join(__dirname, 'example-expected.md'), 'utf8');
-
-    const result = migrations.reduce((text, migration) => migration(text), input);
+    const input = fs.readFileSync(
+      path.join(__dirname, 'example-expected.md'),
+      'utf8',
+    );
+
+    const result = migrations.reduce(
+      (text, migration) => migration(text),
+      input,
+    );
     expect(result).toBe(input);
   });
 
@@ -37,7 +48,10 @@ $bar-2(except=BBB)
 $baz_3(filter=CCC, except=DDD)
 </div>`;
 
-    const result = migrations.reduce((text, migration) => migration(text), input);
+    const result = migrations.reduce(
+      (text, migration) => migration(text),
+      input,
+    );
     expect(result).toBe(expected);
   });
 });

+ 10 - 3
bin/data-migrations/src/migrations/v70x/bootstrap5.js

@@ -669,12 +669,19 @@ module.exports = [
     );
 
     replacedBody = replacedBody.replace(
-      /<select([^>]*)\bclass=['"]([^'"]*)form-control(-lg|-sm)?([^'"]*)['"]([^>]*)>/g, '<select$1class="$2form-select$3$4"$5>',
+      /<select([^>]*)\bclass=['"]([^'"]*)form-control(-lg|-sm)?([^'"]*)['"]([^>]*)>/g,
+      '<select$1class="$2form-select$3$4"$5>',
     );
 
-    replacedBody = replacedBody.replace(/<select([^>]*)\bclass=['"]([^'"]*)form-control\b([^'"]*['"])/g, '<select$1class="$2form-select$3');
+    replacedBody = replacedBody.replace(
+      /<select([^>]*)\bclass=['"]([^'"]*)form-control\b([^'"]*['"])/g,
+      '<select$1class="$2form-select$3',
+    );
 
-    replacedBody = replacedBody.replace('<span aria-hidden="true">&times;</span>', '');
+    replacedBody = replacedBody.replace(
+      '<span aria-hidden="true">&times;</span>',
+      '',
+    );
 
     return replacedBody;
   },

+ 10 - 9
bin/data-migrations/src/types.d.ts

@@ -1,14 +1,15 @@
 export type MigrationModule = (body: string) => string;
-export type ReplaceLatestRevisions = (body: string, migrationModules: MigrationModule[]) => string;
+export type ReplaceLatestRevisions = (
+  body: string,
+  migrationModules: MigrationModule[],
+) => string;
 
-export type Operatioins = Array<
-  {
-    updateOne: {
-      filter: { _id: string }
-      update: { $set: { body: string }}
-    }
-  }
->
+export type Operatioins = Array<{
+  updateOne: {
+    filter: { _id: string };
+    update: { $set: { body: string } };
+  };
+}>;
 
 export declare global {
   const db;

+ 1 - 1
bin/data-migrations/tsconfig.json

@@ -3,6 +3,6 @@
   "extends": "../../tsconfig.base.json",
   "compilerOptions": {
     "checkJs": true,
-    "strict": true,
+    "strict": true
   }
 }

+ 21 - 21
bin/github-actions/list-branches.js

@@ -7,8 +7,8 @@
  *  --illegal : Return illegal named branches
  */
 
-const { execSync } = require('child_process');
-const url = require('url');
+const { execSync } = require('node:child_process');
+const url = require('node:url');
 
 const EXCLUDE_TERM_DAYS = 14;
 const EXCLUDE_PATTERNS = [
@@ -26,7 +26,6 @@ const LEGAL_PATTERNS = [
 const GITHUB_REPOS_URI = 'https://github.com/growilabs/growi/';
 
 class BranchSummary {
-
   constructor(line) {
     const splitted = line.split('\t'); // split with '%09'
 
@@ -35,7 +34,6 @@ class BranchSummary {
     this.branchName = splitted[2].trim().replace(/^origin\//, '');
     this.subject = splitted[3].trim();
   }
-
 }
 
 function getExcludeTermDate() {
@@ -55,10 +53,13 @@ function getBranchSummaries() {
   // parse
   const summaries = out
     .split('\n')
-    .filter(v => v !== '') // trim empty string
-    .map(line => new BranchSummary(line))
-    .filter((summary) => { // exclude branches that matches to patterns
-      return !EXCLUDE_PATTERNS.some(pattern => pattern.test(summary.branchName));
+    .filter((v) => v !== '') // trim empty string
+    .map((line) => new BranchSummary(line))
+    .filter((summary) => {
+      // exclude branches that matches to patterns
+      return !EXCLUDE_PATTERNS.some((pattern) =>
+        pattern.test(summary.branchName),
+      );
     });
 
   return summaries;
@@ -82,12 +83,10 @@ function getGitHubComparingLink(branchName) {
  * @param {BranchSummary} summaries
  */
 function printSlackAttachments(mode, summaries) {
-  const color = (mode === 'illegal') ? 'warning' : '#999999';
+  const color = mode === 'illegal' ? 'warning' : '#999999';
 
   const attachments = summaries.map((summary) => {
-    const {
-      authorName, authorDate, branchName, subject,
-    } = summary;
+    const { authorName, authorDate, branchName, subject } = summary;
 
     return {
       color,
@@ -119,24 +118,25 @@ function printSlackAttachments(mode, summaries) {
   console.log(JSON.stringify(attachments));
 }
 
-async function main(mode) {
+function main(mode) {
   const summaries = getBranchSummaries();
 
   let filteredSummaries;
 
   switch (mode) {
     case 'illegal':
-      filteredSummaries = summaries
-        .filter((summary) => { // exclude branches that matches to patterns
-          return !LEGAL_PATTERNS.some(pattern => pattern.test(summary.branchName));
-        });
+      filteredSummaries = summaries.filter((summary) => {
+        // exclude branches that matches to patterns
+        return !LEGAL_PATTERNS.some((pattern) =>
+          pattern.test(summary.branchName),
+        );
+      });
       break;
     default: {
       const excludeTermDate = getExcludeTermDate();
-      filteredSummaries = summaries
-        .filter((summary) => {
-          return summary.authorDate < excludeTermDate;
-        });
+      filteredSummaries = summaries.filter((summary) => {
+        return summary.authorDate < excludeTermDate;
+      });
       break;
     }
   }

+ 23 - 1
biome.json

@@ -18,7 +18,6 @@
       "!.turbo",
       "!.vscode",
       "!.claude",
-      "!bin",
       "!tsconfig.base.json",
       "!apps/app/src/styles/prebuilt",
       "!apps/app/tmp",
@@ -91,6 +90,29 @@
     }
   },
   "overrides": [
+    {
+      "includes": ["bin/**"],
+      "linter": {
+        "rules": {
+          "suspicious": {
+            "noConsole": "off"
+          }
+        }
+      }
+    },
+    {
+      "includes": ["bin/data-migrations/**"],
+      "linter": {
+        "rules": {
+          "suspicious": {
+            "noVar": "off"
+          },
+          "correctness": {
+            "noInnerDeclarations": "off"
+          }
+        }
+      }
+    },
     {
       "includes": ["apps/pdf-converter/**", "./apps/slackbot-proxy/**"],
       "linter": {

+ 1 - 0
package.json

@@ -29,6 +29,7 @@
     "app:server": "cd apps/app && pnpm run server",
     "slackbot-proxy:build": "turbo run build --filter @growi/slackbot-proxy",
     "slackbot-proxy:server": "cd apps/slackbot-proxy && pnpm run start:prod",
+    "lint": "biome check bin",
     "version-subpackages": "changeset version && pnpm update \"@growi/*\" -r && pnpm dedupe",
     "release-subpackages": "turbo run build --filter @growi/core --filter @growi/pluginkit && changeset publish",
     "release-subpackages:snapshot": "turbo run build --filter @growi/core --filter @growi/pluginkit && changeset version --snapshot next && changeset publish --no-git-tag --snapshot --tag next",

+ 2 - 0
turbo.json

@@ -72,6 +72,8 @@
     },
     "lint": {
     },
+    "//#lint": {
+    },
 
     "@growi/preset-templates#test": {
       "dependsOn": ["@growi/pluginkit#dev"],