Trim the fat and fix typings
Some checks failed
/ deploy (push) Failing after 15s

Clean the code a bit.
Move comments to test to decrease dependency size
Minify package.json for extra.
This commit is contained in:
Jonatan Nilsson 2024-11-19 00:11:46 +00:00
parent b5312312ba
commit afac31914a
7 changed files with 15 additions and 14 deletions

View file

@ -27,6 +27,9 @@ jobs:
echo "" echo ""
echo "------------------------------------" echo "------------------------------------"
echo "" echo ""
mv package.json package-dev.json
mv package-build.json package.json
CURR_VER="$(cat package.json | jq -r .name)_v$(cat package.json | jq -r .version)" 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)" CURR_NAME="$(cat package.json | jq -r .name) v$(cat package.json | jq -r .version)"

View file

@ -15,6 +15,7 @@ Returns true if inside CI. Otherwise returns false.
Returns code 0 if inside CI. Otherwise returns an error code of 1. Returns code 0 if inside CI. Otherwise returns an error code of 1.
`inside-ci || echo 'We are not inside CI, install some stuff'` `inside-ci || echo 'We are not inside CI, install some stuff'`
`inside-ci && echo 'We are inside CI, install some stuff'` `inside-ci && echo 'We are inside CI, install some stuff'`
Example: Example:

2
index.d.ts vendored
View file

@ -1,2 +1,2 @@
/** Returns true if current environment is running inside CI. Otherwise returns false. */ /** Returns true if current environment is running inside CI. Otherwise returns false. */
export function insideCi() export function insideCi(): boolean

View file

@ -1,22 +1,12 @@
#!/usr/bin/env node #!/usr/bin/env node
/** Returns true if current environment is running inside CI. Otherwise returns false. */ module.exports.insideCi = function insideCi() {
function insideCi() {
// Bail out if this is specifically overwritten to false. // Bail out if this is specifically overwritten to false.
// Some users seem to wanna be able to do that
if (process.env.CI === 'false') return false if (process.env.CI === 'false') return false
// Most CI use env.CI (travis, Gitlab, etc.) return !!['CI','CI_APP_ID','BUILD_NUMBER','CI_NAME','RUN_ID'].some(x => process.env[x])
// There are some exceptions though:
// CI_APP_ID is used by Appflow: https://ionic.io/docs/appflow/package/environments#predefined-environments
// CI_NAME is used by Codeship:https://docs.cloudbees.com/docs/cloudbees-codeship/latest/pro-builds-and-configuration/environment-variables
// BUILD_NUMBER is used by TeamCity: https://www.jetbrains.com/help/teamcity/predefined-build-parameters.html#Predefined+Server+Build+Parameters
// RUN_ID is used by Taskcluster: https://docs.taskcluster.net/docs/reference/workers/docker-worker/environment
return Boolean(['CI','CI_APP_ID','BUILD_NUMBER','CI_NAME','RUN_ID'].some(x => process.env[x]))
} }
module.exports.insideCi = insideCi
if (require.main === module) { if (require.main === module) {
process.exit(insideCi() ? 0 : 1) process.exit(insideCi() ? 0 : 1)
} }

1
package-build.json Normal file
View file

@ -0,0 +1 @@
{"name":"inside-ci","version":"1.0.1","description":"Quick tool to check if we are inside CI","main":"index.js","bin":{"inside-ci":"./index.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","index.d.ts","README.md","LICENSE"]}

View file

@ -1,6 +1,6 @@
{ {
"name": "inside-ci", "name": "inside-ci",
"version": "1.0.0", "version": "1.0.1",
"description": "Quick tool to check if we are inside CI", "description": "Quick tool to check if we are inside CI",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View file

@ -3,6 +3,12 @@ import { Eltro as t, assert } from 'eltro'
import { insideCi } from './index.js' import { insideCi } from './index.js'
t.describe('#insideCi()', function () { t.describe('#insideCi()', function () {
// Most CI use env.CI (travis, Gitlab, etc.)
// There are some exceptions though:
// CI_APP_ID is used by Appflow: https://ionic.io/docs/appflow/package/environments#predefined-environments
// CI_NAME is used by Codeship:https://docs.cloudbees.com/docs/cloudbees-codeship/latest/pro-builds-and-configuration/environment-variables
// BUILD_NUMBER is used by TeamCity: https://www.jetbrains.com/help/teamcity/predefined-build-parameters.html#Predefined+Server+Build+Parameters
// RUN_ID is used by Taskcluster: https://docs.taskcluster.net/docs/reference/workers/docker-worker/environment
const testVariables = [ const testVariables = [
'CI', 'CI',
'CI_APP_ID', 'CI_APP_ID',