From c792bc31e13f5a04cb02872fd69ff9f7264b67a0 Mon Sep 17 00:00:00 2001 From: Justin Dalrymple Date: Mon, 7 Jun 2021 15:38:59 -0400 Subject: [PATCH] Fix CLI release compilation (#1838) fixes: #1676 --- .github/dependabot.yml | 10 +++++----- .gitlab-ci.yml | 11 +++++++---- package.json | 4 ++-- packages/cli/package.json | 3 ++- packages/cli/src/cli.ts | 19 ++++++++++++------- .../cli/test/integration/services/Projects.ts | 16 +++++++++------- 6 files changed, 37 insertions(+), 26 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 28d30e5e..4ce90ff9 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,31 +7,31 @@ updates: time: '04:00' open-pull-requests-limit: 10 - package-ecosystem: npm - directory: '/packages/gitbeaker-browser' + directory: '/packages/browser' schedule: interval: daily time: '04:00' open-pull-requests-limit: 10 - package-ecosystem: npm - directory: '/packages/gitbeaker-node' + directory: '/packages/node' schedule: interval: daily time: '04:00' open-pull-requests-limit: 10 - package-ecosystem: npm - directory: '/packages/gitbeaker-cli' + directory: '/packages/cli' schedule: interval: daily time: '04:00' open-pull-requests-limit: 10 - package-ecosystem: npm - directory: '/packages/gitbeaker-core' + directory: '/packages/core' schedule: interval: daily time: '04:00' open-pull-requests-limit: 10 - package-ecosystem: npm - directory: '/packages/gitbeaker-requester-utils' + directory: '/packages/requester-utils' schedule: interval: daily time: '04:00' diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 78105fe6..5b122eaf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -45,12 +45,14 @@ build: # Lint all code, tests and supporting documentation (README, CHANGELOG etc) lint:src: + needs: ['install'] stage: lint script: yarn lint lint:docs: + needs: ['install'] stage: lint - script: yarn lint:doc + script: yarn lint:docs # Unit Tests test:unit:cli: @@ -124,11 +126,12 @@ test:unit:utils: # script: # - yarn workspace @gitbeaker/browser test:integration -# test:integration:node: +# test:integration: # <<: *integration-test # script: -# - yarn workspace @gitbeaker/node test:integration -# - yarn workspace @gitbeaker/node test:integration --moduleNameMapper='{"src":"/dist/index.js"}' +# - yarn workspace @gitbeaker/cli test:integration +# - yarn workspace @gitbeaker/node test:integration +# - yarn workspace @gitbeaker/node test:integration --moduleNameMapper='{"src":"/dist/index.js"}' # Canary canary: diff --git a/package.json b/package.json index fc50295a..44f5629a 100644 --- a/package.json +++ b/package.json @@ -39,8 +39,8 @@ "scripts": { "build": "lerna run build", "lint": "prettier --check 'packages/**/{src,test}/**/*.ts' && eslint 'packages/**/{src,test}/**/*/*.ts'", - "lint:doc": "prettier --check './**/*.json' './**/*.yml' './**/*.js' '!./**/(dist|coverage)/**'", - "lint:doc:fix": "prettier --write './**/*.json' './**/*.yml' './**/*.js' '!./**/(dist|coverage)/**'", + "lint:docs": "prettier --check './**/*.json' './**/*.yml' './**/*.js' '!./**/(dist|coverage)/**'", + "lint:docs:fix": "prettier --write './**/*.json' './**/*.yml' './**/*.js' '!./**/(dist|coverage)/**'", "lint:fix": "prettier --write 'packages/**/{src,test}/**/*.ts' && eslint 'packages/**/{src,test}/**/*/*.ts' --fix", "test:unit": "jest test/unit", "release": "auto shipit --verbose --verbose", diff --git a/packages/cli/package.json b/packages/cli/package.json index 52c32a23..8741f56c 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -25,6 +25,7 @@ "rollup-plugin-preserve-shebangs": "^0.2.0", "rollup-plugin-typescript2": "^0.30.0", "strip-ansi": "^7.0.0", + "uuid": "^8.3.2", "typescript": "^4.2.4" }, "engines": { @@ -48,7 +49,7 @@ }, "scripts": { "build": "rollup -c", - "test:integration": "jest test/integration", + "test:integration": "TEST_ID=$(uuid) jest test/integration", "test:unit": "jest test/unit" } } diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 2d9da438..8ce3945d 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -92,17 +92,22 @@ function param(string: string): string { let cleaned = string; // Handle exceptions - if (string.includes('GitLabCI')) cleaned = cleaned.replace('GitLabCI', 'Gitlabci'); - if (string.includes('YML')) cleaned = cleaned.replace('YML', 'Yml'); - if (string.includes('GPG')) cleaned = cleaned.replace('GPG', 'Gpg'); + const exceptions = ['GitLabCI', 'YML', 'GPG', 'SSH']; - const attempt = decamelize(cleaned, '-'); + const ex = exceptions.find((e) => string.includes(e)); - return attempt !== cleaned ? attempt : depascalize(cleaned, '-'); + if (ex) cleaned = cleaned.replace(ex, ex.charAt(0).toUpperCase() + ex.slice(1)); + + // Decamelize + const decamelized = decamelize(cleaned, '-'); + + return decamelized !== cleaned ? decamelized : depascalize(cleaned, '-'); } -function setupAPIMethods(setupArgs, methodArgs: string[]) { - methodArgs.forEach((name: string) => { +function setupAPIMethods(setupArgs, methodArgs: unknown[]) { + methodArgs.forEach((name) => { + if (typeof name !== 'string') return; + setupArgs.positional(`[--${param(name)}] <${param(name)}>`, { group: 'Required Options', type: 'string', diff --git a/packages/cli/test/integration/services/Projects.ts b/packages/cli/test/integration/services/Projects.ts index cd6768bc..18ef2a94 100644 --- a/packages/cli/test/integration/services/Projects.ts +++ b/packages/cli/test/integration/services/Projects.ts @@ -1,14 +1,16 @@ +import { promisify } from 'util'; +import { exec } from 'child_process'; + +const execP = promisify(exec); + const { TEST_ID = '', GITLAB_PERSONAL_ACCESS_TOKEN = '', GITLAB_URL = '' } = process.env; describe('gitbeaker projects create', () => { it('should create a valid project', async () => { - // eslint-disable-next-line - const { cli } = require('../../../dist/index'); - const { output } = await cli.parse( - `gitbeaker projects create --name="CLI Project ${TEST_ID}" --gb-token="${GITLAB_PERSONAL_ACCESS_TOKEN}" --gb-host="${GITLAB_URL}"`, - ); - const data = JSON.parse(output); + const command = `projects create --name="CLI Project ${TEST_ID}" --gb-token="${GITLAB_PERSONAL_ACCESS_TOKEN}" --gb-host="${GITLAB_URL}"`; + const { stdout } = await execP(`node dist/index.js ${command}`); + const { name } = JSON.parse(stdout); - expect(data.name).toBe(`CLI Project ${TEST_ID}`); + expect(name).toBe(`CLI Project ${TEST_ID}`); }); });