From d46e0d834ee07c5a649acf592da8e7ba082e3061 Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Fri, 22 Nov 2024 05:02:56 +0000 Subject: [PATCH] Minimize it further and clean it up --- .forgejo/workflows/deploy.yml | 3 +-- build.sh | 5 +++++ in.js | 12 ++++++++++++ index.d.ts | 2 -- index.js | 14 -------------- not.js | 5 +---- package-build.json | 1 - package.json | 13 +++++-------- test.mjs | 6 +++--- 9 files changed, 27 insertions(+), 34 deletions(-) create mode 100755 build.sh create mode 100755 in.js delete mode 100644 index.d.ts delete mode 100755 index.js delete mode 100644 package-build.json diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml index 33a22ed..07e304a 100644 --- a/.forgejo/workflows/deploy.yml +++ b/.forgejo/workflows/deploy.yml @@ -27,8 +27,7 @@ jobs: echo "" echo "------------------------------------" echo "" - mv package.json package-dev.json - mv package-build.json package.json + ./build.sh CURR_VER="$(cat package.json | jq -r .name)_v$(cat package.json | jq -r .version)" CURR_NAME="$(cat package.json | jq -r .name) v$(cat package.json | jq -r .version)" diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..78c321a --- /dev/null +++ b/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +mv package.json package.json.backup + +jq -c 'pick(.name, .version, .description, .main, .bin, .repository, .keywords, .author, .license, .files)' package.json.backup > package.json diff --git a/in.js b/in.js new file mode 100755 index 0000000..9fa08d9 --- /dev/null +++ b/in.js @@ -0,0 +1,12 @@ +#!/usr/bin/env node + +let is = module.exports.insideCi = () => { + // Bail out if CI is overrided + return process.env.CI === 'false' + ? false + : !!['CI','CI_APP_ID','BUILD_NUMBER','CI_NAME','RUN_ID'].some(x => process.env[x]) +} + +if (require.main === module) { + process.exit(is() ? 0 : 1) +} diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4ad18c3..0000000 --- a/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -/** Returns true if current environment is running inside CI. Otherwise returns false. */ -export function insideCi(): boolean diff --git a/index.js b/index.js deleted file mode 100755 index 4759b30..0000000 --- a/index.js +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env node - -function insideCi() { - // Bail out if this is specifically overwritten to false. - if (process.env.CI === 'false') return false - - return !!['CI','CI_APP_ID','BUILD_NUMBER','CI_NAME','RUN_ID'].some(x => process.env[x]) -} - -module.exports.insideCi = insideCi - -if (require.main === module) { - process.exit(insideCi() ? 0 : 1) -} diff --git a/not.js b/not.js index 3c69b09..5edd066 100755 --- a/not.js +++ b/not.js @@ -1,5 +1,2 @@ #!/usr/bin/env node - -const { insideCi } = require("./index.js"); - -process.exit(!insideCi() ? 0 : 1) +process.exit(!require("./in.js").insideCi() ? 0 : 1) diff --git a/package-build.json b/package-build.json deleted file mode 100644 index 122134e..0000000 --- a/package-build.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"inside-ci","version":"1.1.0","description":"Quick tool to check if we are inside CI","main":"index.js","bin":{"inside-ci":"./index.js","in-ci":"./index.js","not-ci":"./not.js"},"repository":{"type":"git","url":"https://git.nfp.is/TheThing/inside-ci.git"},"keywords":["ci","is-ci","inside-ci","environment"],"author":"Jonatan Nilsson","license":"WTFPL","files":["index.js","not.js","index.d.ts","README.md","LICENSE"]} \ No newline at end of file diff --git a/package.json b/package.json index 8bfe31c..d68b824 100644 --- a/package.json +++ b/package.json @@ -8,13 +8,13 @@ "test:watch": "eltro -r dot -w test test.mjs" }, "bin": { - "inside-ci": "./index.js", - "in-ci": "./index.js", + "inside-ci": "./in.js", + "in-ci": "./in.js", "not-ci": "./not.js" }, "watch": { "test": { - "patterns": ["index.js", "test.mjs"] + "patterns": ["in.js", "test.mjs"] } }, "repository": { @@ -23,9 +23,7 @@ }, "keywords": [ "ci", - "is-ci", - "inside-ci", - "environment" + "is-ci" ], "author": "Jonatan Nilsson", "license": "WTFPL", @@ -33,9 +31,8 @@ "eltro": "^1.6.1" }, "files": [ - "index.js", + "in.js", "not.js", - "index.d.ts", "README.md", "LICENSE" ] diff --git a/test.mjs b/test.mjs index a55c463..b7abc6b 100644 --- a/test.mjs +++ b/test.mjs @@ -1,6 +1,6 @@ import { exec } from 'child_process' import { Eltro as t, assert } from 'eltro' -import { insideCi } from './index.js' +import { insideCi } from './in.js' t.describe('#insideCi()', function () { // Most CI use env.CI (travis, Gitlab, etc.) @@ -59,7 +59,7 @@ function runCommand(command, options) { t.describe('CLI in-ci', function() { t.test('should return success/code 0 if CI is filled', async function () { - let result = await runCommand('node index.js', { + let result = await runCommand('node in.js', { env: { CI: 'true' } }) @@ -67,7 +67,7 @@ t.describe('CLI in-ci', function() { }) t.test('should return error code 1 if CI is false', async function () { - let result = await runCommand('node index.js', { + let result = await runCommand('node in.js', { env: { CI: 'false' } })