From d6eef511acf4e1b5dd088fd6960c7e5385cd657f Mon Sep 17 00:00:00 2001 From: jycouet Date: Thu, 12 Sep 2024 18:41:55 +0200 Subject: [PATCH] :art: UPDATE: with more styles --- .changeset/nasty-years-obey.md | 5 ++ packages/eslint-config/cmd.js | 98 ++++++++++++++--------- packages/eslint-config/package.json | 1 + pnpm-lock.yaml | 116 ++++++++++++++++++++++++++++ 4 files changed, 183 insertions(+), 37 deletions(-) create mode 100644 .changeset/nasty-years-obey.md diff --git a/.changeset/nasty-years-obey.md b/.changeset/nasty-years-obey.md new file mode 100644 index 00000000..e7eb9ac1 --- /dev/null +++ b/.changeset/nasty-years-obey.md @@ -0,0 +1,5 @@ +--- +'@kitql/eslint-config': patch +--- + +add some spin diff --git a/packages/eslint-config/cmd.js b/packages/eslint-config/cmd.js index 6293ce49..01e998c3 100755 --- a/packages/eslint-config/cmd.js +++ b/packages/eslint-config/cmd.js @@ -1,12 +1,18 @@ #!/usr/bin/env node -import { spawnSync } from 'node:child_process' +import { spawn } from 'node:child_process' import { Option, program } from 'commander' +import ora from 'ora' -import { Log, red } from '@kitql/helpers' +import { bgBlueBright, gray, red } from '@kitql/helpers' import { findFileOrUp } from './helper/findFileOrUp.js' -const log = new Log('kitql-lint') +const spinner = ora({ + // hideCursor: true, + prefixText: bgBlueBright(` kitql-lint `), + text: 'check config', +}) +spinner.start() program.addOption(new Option('-f, --format', 'format')) program.addOption(new Option('-g, --glob ', 'file/dir/glob (. by default)', '.')) @@ -39,34 +45,36 @@ if (pre === 'npm') { preToUse = '' } -function prettierRun() { - const cmdPrettier = - preToUse + - `prettier` + - ` --list-different` + - // ignore? - ` --ignore-path ${pathPrettierIgnore}` + - // config - ` --config ${pathPrettierCjs}` + - // format or not - `${format ? ' --write' : ''}` + - // exec - ` ${glob}` - - if (verbose) { - log.info(cmdPrettier) - } - const result_prettier = spawnSync(cmdPrettier, { +async function customSpawn(cmd) { + const child = spawn(cmd, { shell: true, cwd: process.cwd(), stdio: 'inherit', }) + // console.log(`child`, child) + + let data = '' + // for await (const chunk of child?.stdout) { + // console.log('stdout chunk: ' + chunk) + // data += chunk + // } + let error = '' + // for await (const chunk of child?.stderr) { + // console.error('stderr chunk: ' + chunk) + // error += chunk + // } + const exitCode = await new Promise((resolve, reject) => { + child.on('close', resolve) + }) - return result_prettier + if (exitCode) { + // throw new Error(`subprocess error exit ${exitCode}, ${error}`) + return { status: exitCode, error } + } + return data } -function eslintRun() { - // Then eslint +async function eslintRun() { const cmdEsLint = preToUse + `eslint` + @@ -75,30 +83,46 @@ function eslintRun() { // exec ` ${glob}` - if (verbose) { - log.info(cmdEsLint) - } + spinner.text = verbose ? 'eslint ' + gray(`(${cmdEsLint})`) : 'eslint' - const result_eslint = spawnSync(cmdEsLint, { - shell: true, - cwd: process.cwd(), - stdio: 'inherit', - }) + const result_eslint = await customSpawn(cmdEsLint) return result_eslint } -const eslintCode = eslintRun() +async function prettierRun() { + const cmdPrettier = + preToUse + + `prettier` + + ` --list-different` + + // ignore? + ` --ignore-path ${pathPrettierIgnore}` + + // config + ` --config ${pathPrettierCjs}` + + // format or not + `${format ? ' --write' : ''}` + + // exec + ` ${glob}` + + spinner.text = verbose ? 'prettier ' + gray(`(${cmdPrettier})`) : 'prettier' + + const result_prettier = await customSpawn(cmdPrettier) + + return result_prettier +} + +const eslintCode = await eslintRun() if (eslintCode.status) { - log.error(red(`eslint failed, check logs above.`)) + spinner.fail(red(`eslint failed, check logs above.`)) process.exit(eslintCode.status) } -const prettierCode = prettierRun() +const prettierCode = await prettierRun() if (prettierCode.status) { - log.error(red(`prettier failed, check logs above.`)) + spinner.fail(red(`prettier failed, check logs above.`)) process.exit(eslintCode.status) } -log.success(`All good, your files looks great!`) +spinner.succeed(`All good, your files looks great!`) +spinner.stop() process.exit(0) diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json index 714030ae..99940d1f 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -49,6 +49,7 @@ "eslint-plugin-svelte": "2.43.0", "eslint-plugin-unused-imports": "^4.1.3", "globals": "15.9.0", + "ora": "^8.1.0", "prettier": "3.3.3", "prettier-plugin-svelte": "3.2.6", "prettier-plugin-tailwindcss": "0.6.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e47c3df5..24d5f0e5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -122,6 +122,9 @@ importers: globals: specifier: 15.9.0 version: 15.9.0 + ora: + specifier: ^8.1.0 + version: 8.1.0 prettier: specifier: 3.3.3 version: 3.3.3 @@ -2618,6 +2621,10 @@ packages: resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==} engines: {node: '>=10'} + chalk@5.3.0: + resolution: {integrity: sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==} + engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} + character-entities-html4@2.1.0: resolution: {integrity: sha512-1v7fgQRj6hnSwFpq1Eu0ynr/CDEw0rXo2B61qXrLNdHZmPKgb7fqS1a2JwF0rISo9q77jDI8VMEHoApn8qDoZA==} @@ -2671,10 +2678,18 @@ packages: resolution: {integrity: sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==} engines: {node: '>=8'} + cli-cursor@5.0.0: + resolution: {integrity: sha512-aCj4O5wKyszjMmDT4tZj93kxyydN/K5zPWSCe6/0AV/AA1pqe5ZBIw0a2ZfPQV7lL5/yb5HsUreJ6UFAF1tEQw==} + engines: {node: '>=18'} + cli-spinners@2.6.1: resolution: {integrity: sha512-x/5fWmGMnbKQAaNwN+UZlV79qBLM9JFnJuJ03gIi5whrob0xV0ofNVHy9DhwGdsMJQc2OKv0oGmLzvaqvAVv+g==} engines: {node: '>=6'} + cli-spinners@2.9.2: + resolution: {integrity: sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==} + engines: {node: '>=6'} + client-only@0.0.1: resolution: {integrity: sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==} @@ -3212,6 +3227,9 @@ packages: elliptic@6.5.5: resolution: {integrity: sha512-7EjbcmUm17NQFu4Pmgmq2olYMj8nwMnpcddByChSUjArp8F5DQWcIcpriwO4ZToLNAJig0yiyjswfyGNje/ixw==} + emoji-regex@10.4.0: + resolution: {integrity: sha512-EC+0oUMY1Rqm4O6LLrgjtYDvcVYTy7chDnM4Q7030tP4Kwj3u/pR6gP9ygnp2CJMK5Gq+9Q2oqmrFJAz01DXjw==} + emoji-regex@8.0.0: resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} @@ -3651,6 +3669,10 @@ packages: resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==} engines: {node: 6.* || 8.* || >= 10.*} + get-east-asian-width@1.2.0: + resolution: {integrity: sha512-2nk+7SIVb14QrgXFHcm84tD4bKQz0RxPuMT8Ag5KPOq7J5fEmAg0UbXdTOSHqNuHSU28k55qnceesxXRZGzKWA==} + engines: {node: '>=18'} + get-func-name@2.0.2: resolution: {integrity: sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==} @@ -4040,6 +4062,10 @@ packages: resolution: {integrity: sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w==} engines: {node: '>=8'} + is-interactive@2.0.0: + resolution: {integrity: sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==} + engines: {node: '>=12'} + is-module@1.0.0: resolution: {integrity: sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==} @@ -4097,6 +4123,14 @@ packages: resolution: {integrity: sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==} engines: {node: '>=10'} + is-unicode-supported@1.3.0: + resolution: {integrity: sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==} + engines: {node: '>=12'} + + is-unicode-supported@2.1.0: + resolution: {integrity: sha512-mE00Gnza5EEB3Ds0HfMyllZzbBrmLOX3vfWoj9A9PEnTfratQ/BcaJOuMhnkhjXvb2+FkY3VuHqtAGpTPmglFQ==} + engines: {node: '>=18'} + is-windows@1.0.2: resolution: {integrity: sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==} engines: {node: '>=0.10.0'} @@ -4318,6 +4352,10 @@ packages: resolution: {integrity: sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==} engines: {node: '>=10'} + log-symbols@6.0.0: + resolution: {integrity: sha512-i24m8rpwhmPIS4zscNzK6MSEhk0DUWa/8iYQWxhffV8jkI4Phvs3F+quL5xvS0gdQR0FyTCMMH33Y78dDTzzIw==} + engines: {node: '>=18'} + longest-streak@3.1.0: resolution: {integrity: sha512-9Ri+o0JYgehTaVBBDoMqIl8GXtbWg711O3srftcHhZ0dqnETqLaoIK0x17fUw9rFSlK/0NlsKe0Ahhyl5pXE2g==} @@ -4686,6 +4724,10 @@ packages: resolution: {integrity: sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==} engines: {node: '>=12'} + mimic-function@5.0.1: + resolution: {integrity: sha512-VP79XUPxV2CigYP3jWwAUFSku2aKqBH7uTAapFWCBqutsbmDo96KY5o8uh6U+/YSIn5OxJnXp73beVkpqMIGhA==} + engines: {node: '>=18'} + minimalistic-assert@1.0.1: resolution: {integrity: sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==} @@ -4970,6 +5012,10 @@ packages: resolution: {integrity: sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==} engines: {node: '>=12'} + onetime@7.0.0: + resolution: {integrity: sha512-VXJjc87FScF88uafS3JllDgvAm+c/Slfz06lorj2uAY34rlUu0Nt+v8wreiImcrgAjjIHp1rXpTDlLOGw29WwQ==} + engines: {node: '>=18'} + open@8.4.2: resolution: {integrity: sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ==} engines: {node: '>=12'} @@ -4986,6 +5032,10 @@ packages: resolution: {integrity: sha512-zAKMgGXUim0Jyd6CXK9lraBnD3H5yPGBPPOkC23a2BG6hsm4Zu6OQSjQuEtV0BHDf4aKHcUFvJiGRrFuW3MG8g==} engines: {node: '>=10'} + ora@8.1.0: + resolution: {integrity: sha512-GQEkNkH/GHOhPFXcqZs3IDahXEQcQxsSjEkK4KvEEST4t7eNzoMjxTzef+EZ+JluDEV+Raoi3WQ2CflnRdSVnQ==} + engines: {node: '>=18'} + os-browserify@0.3.0: resolution: {integrity: sha512-gjcpUc3clBf9+210TRaDWbf+rZZZEshZ+DlXMRCeAjp0xhTrnQsKHypIy1J3d5hKdUzj69t708EHtU8P6bUn0A==} @@ -5747,6 +5797,10 @@ packages: resolution: {integrity: sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==} engines: {node: '>=8'} + restore-cursor@5.1.0: + resolution: {integrity: sha512-oMA2dcrw6u0YfxJQXm342bFKX/E4sG9rbTzO9ptUcR/e8A33cHuvStiYOwH7fszkZlZ1z/ta9AAoPk2F4qIOHA==} + engines: {node: '>=18'} + ret@0.1.15: resolution: {integrity: sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==} engines: {node: '>=0.12'} @@ -6015,6 +6069,10 @@ packages: std-env@3.7.0: resolution: {integrity: sha512-JPbdCEQLj1w5GilpiHAx3qJvFndqybBysA3qUOnznweH4QbNYUsW/ea8QzSrnh0vNsezMMw5bcVool8lM0gwzg==} + stdin-discarder@0.2.2: + resolution: {integrity: sha512-UhDfHmA92YAlNnCfhmq0VeNL5bDbiZGg7sZ2IvPsXubGkiNa9EC+tUTsjBRsYUAz87btI6/1wf4XoVvQ3uRnmQ==} + engines: {node: '>=18'} + stream-browserify@2.0.2: resolution: {integrity: sha512-nX6hmklHs/gr2FuxYDltq8fJA1GDlxKQCz8O/IM4atRqBH8OORmBNgfvW5gG10GT/qQ9u0CzIvr2X5Pkt6ntqg==} @@ -6039,6 +6097,10 @@ packages: resolution: {integrity: sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==} engines: {node: '>=12'} + string-width@7.2.0: + resolution: {integrity: sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==} + engines: {node: '>=18'} + string_decoder@1.1.1: resolution: {integrity: sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==} @@ -9038,6 +9100,8 @@ snapshots: ansi-styles: 4.3.0 supports-color: 7.2.0 + chalk@5.3.0: {} + character-entities-html4@2.1.0: {} character-entities-legacy@3.0.0: {} @@ -9115,8 +9179,14 @@ snapshots: dependencies: restore-cursor: 3.1.0 + cli-cursor@5.0.0: + dependencies: + restore-cursor: 5.1.0 + cli-spinners@2.6.1: {} + cli-spinners@2.9.2: {} + client-only@0.0.1: {} clipboardy@1.2.2: @@ -9702,6 +9772,8 @@ snapshots: minimalistic-assert: 1.0.1 minimalistic-crypto-utils: 1.0.1 + emoji-regex@10.4.0: {} + emoji-regex@8.0.0: {} emoji-regex@9.2.2: {} @@ -10237,6 +10309,8 @@ snapshots: get-caller-file@2.0.5: {} + get-east-asian-width@1.2.0: {} + get-func-name@2.0.2: {} get-intrinsic@1.2.1: @@ -10705,6 +10779,8 @@ snapshots: is-interactive@1.0.0: {} + is-interactive@2.0.0: {} + is-module@1.0.0: {} is-nan@1.3.2: @@ -10754,6 +10830,10 @@ snapshots: is-unicode-supported@0.1.0: {} + is-unicode-supported@1.3.0: {} + + is-unicode-supported@2.1.0: {} + is-windows@1.0.2: {} is-wsl@1.1.0: {} @@ -10957,6 +11037,11 @@ snapshots: chalk: 4.1.2 is-unicode-supported: 0.1.0 + log-symbols@6.0.0: + dependencies: + chalk: 5.3.0 + is-unicode-supported: 1.3.0 + longest-streak@3.1.0: {} loose-envify@1.4.0: @@ -11753,6 +11838,8 @@ snapshots: mimic-fn@4.0.0: {} + mimic-function@5.0.1: {} + minimalistic-assert@1.0.1: {} minimalistic-crypto-utils@1.0.1: {} @@ -12155,6 +12242,10 @@ snapshots: dependencies: mimic-fn: 4.0.0 + onetime@7.0.0: + dependencies: + mimic-function: 5.0.1 + open@8.4.2: dependencies: define-lazy-prop: 2.0.0 @@ -12183,6 +12274,18 @@ snapshots: strip-ansi: 6.0.1 wcwidth: 1.0.1 + ora@8.1.0: + dependencies: + chalk: 5.3.0 + cli-cursor: 5.0.0 + cli-spinners: 2.9.2 + is-interactive: 2.0.0 + is-unicode-supported: 2.1.0 + log-symbols: 6.0.0 + stdin-discarder: 0.2.2 + string-width: 7.2.0 + strip-ansi: 7.1.0 + os-browserify@0.3.0: {} os-tmpdir@1.0.2: {} @@ -12965,6 +13068,11 @@ snapshots: onetime: 5.1.2 signal-exit: 3.0.7 + restore-cursor@5.1.0: + dependencies: + onetime: 7.0.0 + signal-exit: 4.1.0 + ret@0.1.15: {} retext-latin@3.1.0: @@ -13265,6 +13373,8 @@ snapshots: std-env@3.7.0: {} + stdin-discarder@0.2.2: {} + stream-browserify@2.0.2: dependencies: inherits: 2.0.4 @@ -13299,6 +13409,12 @@ snapshots: emoji-regex: 9.2.2 strip-ansi: 7.1.0 + string-width@7.2.0: + dependencies: + emoji-regex: 10.4.0 + get-east-asian-width: 1.2.0 + strip-ansi: 7.1.0 + string_decoder@1.1.1: dependencies: safe-buffer: 5.1.2