From d94cf57c5840682b690ec8859d8db28427734dba Mon Sep 17 00:00:00 2001 From: Jairus Date: Fri, 4 Oct 2024 18:47:29 -0700 Subject: [PATCH 1/5] try and fix this ci --- .github/workflows/dev-release.yml | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/dev-release.yml diff --git a/.github/workflows/dev-release.yml b/.github/workflows/dev-release.yml new file mode 100644 index 0000000..b4b5464 --- /dev/null +++ b/.github/workflows/dev-release.yml @@ -0,0 +1,45 @@ +name: Dev Release + +on: + push: + branches: + - main + pull_request: + branches: + - '**' + +jobs: + dev-release: + permissions: write-all + name: Dev Release + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Node + uses: actions/setup-node@v3 + with: + node-version: '22.8.0' + + - name: Get package version + id: package-version + uses: martinbeentjes/npm-get-version-action@v1.3.1 + + - name: Install dependencies + run: npm install + + - name: Build files + run: npm run build + + - name: Build tarballs + run: npm run pack + + - name: Create release + uses: softprops/action-gh-release@v1 + with: + files: ./dist/*.tar.gz + prerelease: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From cf6d709e098a33ad0e000542a4f3f76be8322b09 Mon Sep 17 00:00:00 2001 From: Jairus Date: Fri, 4 Oct 2024 18:52:15 -0700 Subject: [PATCH 2/5] add tag --- .github/workflows/dev-release.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/dev-release.yml b/.github/workflows/dev-release.yml index b4b5464..1df4cdd 100644 --- a/.github/workflows/dev-release.yml +++ b/.github/workflows/dev-release.yml @@ -2,11 +2,17 @@ name: Dev Release on: push: + tags: + - "v*.*.*" branches: - main pull_request: + tags: + - "v*.*.*" branches: - '**' +env: + draft: true jobs: dev-release: @@ -39,6 +45,7 @@ jobs: - name: Create release uses: softprops/action-gh-release@v1 with: + draft: ${{ env.draft }} files: ./dist/*.tar.gz prerelease: true env: From a7332f56109db9287d548b6c03f06cf36e035ae5 Mon Sep 17 00:00:00 2001 From: Jairus Date: Fri, 4 Oct 2024 18:57:39 -0700 Subject: [PATCH 3/5] fix linter --- .eslintignore | 1 + src/commands/login/index.ts | 24 ++++--- src/commands/logout/index.ts | 18 ++--- src/commands/org/switch.ts | 22 +++--- src/custom/help.ts | 132 +++++++++++++++++------------------ src/util/index.ts | 6 +- 6 files changed, 105 insertions(+), 98 deletions(-) diff --git a/.eslintignore b/.eslintignore index 9b1c8b1..414206a 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ /dist +/tmp diff --git a/src/commands/login/index.ts b/src/commands/login/index.ts index bf6d759..ffc55a6 100644 --- a/src/commands/login/index.ts +++ b/src/commands/login/index.ts @@ -4,7 +4,9 @@ import * as http from 'node:http' import {createInterface} from 'node:readline' import open from 'open' -import {fileExists, getEnvDir, getEnvFilePath, promptOrgSelection, sendGraphQLRequest} from '../../util/index.js' +import { + fileExists, getEnvDir, getEnvFilePath, promptOrgSelection, sendGraphQLRequest, +} from '../../util/index.js' export default class LoginIndex extends Command { static override args = {} @@ -97,18 +99,18 @@ export default class LoginIndex extends Command { const content = fs.readFileSync(envFilePath, 'utf8') // Check if the file contains HYP_JWT and HYP_EMAIL, if not add them - const updatedContent = - !content.includes('HYP_JWT=') || !content.includes('HYP_EMAIL=') || !content.includes('HYP_ORG_ID=') + const updatedContent + = !content.includes('HYP_JWT=') || !content.includes('HYP_EMAIL=') || !content.includes('HYP_ORG_ID=') ? content + `HYP_JWT=${jwt}\nHYP_EMAIL=${email}\nHYP_ORG_ID=${orgId}\n` : content - .split('\n') - .map((line) => { - if (line.startsWith('HYP_JWT=')) return `HYP_JWT=${jwt}` - if (line.startsWith('HYP_EMAIL=')) return `HYP_EMAIL=${email}` - if (line.startsWith('HYP_ORG_ID=')) return `HYP_ORG_ID=${orgId}` - return line // Keep other lines unchanged - }) - .join('\n') + .split('\n') + .map(line => { + if (line.startsWith('HYP_JWT=')) return `HYP_JWT=${jwt}` + if (line.startsWith('HYP_EMAIL=')) return `HYP_EMAIL=${email}` + if (line.startsWith('HYP_ORG_ID=')) return `HYP_ORG_ID=${orgId}` + return line // Keep other lines unchanged + }) + .join('\n') // delete the file fs.unlinkSync(envFilePath) diff --git a/src/commands/logout/index.ts b/src/commands/logout/index.ts index d5f3330..b6859d8 100644 --- a/src/commands/logout/index.ts +++ b/src/commands/logout/index.ts @@ -33,15 +33,15 @@ export default class LogoutIndex extends Command { // Remove JWT and email from .env.local file const updatedContent = res.content - .split('\n') - .map((line) => { - if (line.startsWith('HYP_JWT') || line.startsWith('HYP_EMAIL') || line.startsWith('HYP_ORG_ID')) { - return '' - } - - return line - }) - .join('\n') + .split('\n') + .map(line => { + if (line.startsWith('HYP_JWT') || line.startsWith('HYP_EMAIL') || line.startsWith('HYP_ORG_ID')) { + return '' + } + + return line + }) + .join('\n') fs.writeFileSync(envFilePath, updatedContent.trim() + '\n', {flag: 'w'}) } diff --git a/src/commands/org/switch.ts b/src/commands/org/switch.ts index d477009..ab33687 100644 --- a/src/commands/org/switch.ts +++ b/src/commands/org/switch.ts @@ -3,7 +3,9 @@ import chalk from 'chalk' import * as fs from 'node:fs' import {createInterface} from 'node:readline' -import {fileExists, getEnvFilePath, promptOrgSelection, readEnvFile, sendGraphQLRequest} from '../../util/index.js' +import { + fileExists, getEnvFilePath, promptOrgSelection, readEnvFile, sendGraphQLRequest, +} from '../../util/index.js' export default class OrgSwitch extends Command { static override args = {} @@ -37,15 +39,15 @@ export default class OrgSwitch extends Command { const selectedOrg = await promptOrgSelection(rl, orgs) const updatedContent = res.content - .split('\n') - .map((line) => { - if (line.startsWith('HYP_ORG_ID')) { - return `HYP_ORG_ID=${selectedOrg.id}` - } - - return line - }) - .join('\n') + .split('\n') + .map(line => { + if (line.startsWith('HYP_ORG_ID')) { + return `HYP_ORG_ID=${selectedOrg.id}` + } + + return line + }) + .join('\n') fs.writeFileSync(envFilePath, updatedContent.trim() + '\n', {flag: 'w'}) diff --git a/src/custom/help.ts b/src/custom/help.ts index 4c8a16f..fdeee2d 100644 --- a/src/custom/help.ts +++ b/src/custom/help.ts @@ -23,17 +23,17 @@ export default class CustomHelp extends Help { const rawName = command.id.includes(':') ? command.id.split(':')[1] : command.id const name = chalk.bold.blueBright(rawName) const prePadding = ' '.repeat(Math.max(1, this.prePad - rawName.length)) - const args = - Object.keys(command.args).length > 0 + const args + = Object.keys(command.args).length > 0 ? Object.entries(command.args) - .map((v) => { - if (!v[1].hidden && v[1].required && v[1].description && v[1].description.indexOf('-|-') > 0) { - return v[1].description.split('-|-')[0] - } - - return '' - }) - .join(' ') + .map(v => { + if (!v[1].hidden && v[1].required && v[1].description && v[1].description.indexOf('-|-') > 0) { + return v[1].description.split('-|-')[0] + } + + return '' + }) + .join(' ') : '' const postPadding = ' '.repeat(Math.max(1, this.postPad - args.length)) const description = command.description! @@ -47,28 +47,28 @@ export default class CustomHelp extends Help { formatRoot(): string { let out = '' - out += - chalk.bold.blueBright('Hypermode') + ' - Build Intelligent APIs. ' + chalk.dim('(v' + CLI_VERSION + ')') + '\n\n' + out + += chalk.bold.blueBright('Hypermode') + ' - Build Intelligent APIs. ' + chalk.dim('(v' + CLI_VERSION + ')') + '\n\n' // Usage: hyp [...flags] [...args] - out += - chalk.bold('Usage: hyp') + - ' ' + - chalk.dim('') + - ' ' + - chalk.bold.blueBright('[...flags]') + - ' ' + - chalk.bold('[...args]') + out + += chalk.bold('Usage: hyp') + + ' ' + + chalk.dim('') + + ' ' + + chalk.bold.blueBright('[...flags]') + + ' ' + + chalk.bold('[...args]') return out } formatRootFooter(): string { let out = '' - out += - 'View the docs:' + - ' '.repeat(Math.max(1, this.prePad + this.postPad - 12)) + - chalk.blueBright('https://docs.hypermode.com/introduction') + - '\n' + out + += 'View the docs:' + + ' '.repeat(Math.max(1, this.prePad + this.postPad - 12)) + + chalk.blueBright('https://docs.hypermode.com/introduction') + + '\n' // out += "View the repo:" + " ".repeat(Math.max(1, this.pre_pad + this.post_pad - 12)) + chalk.blueBright("https://github.com/HypermodeInc/modus") + "\n"; out += '\n' @@ -87,17 +87,17 @@ export default class CustomHelp extends Help { formatTopics(topics: Interfaces.Topic[]): string { let out = '' - if (topics.some((v) => !v.hidden)) out += chalk.bold('Tools:') + '\n' + if (topics.some(v => !v.hidden)) out += chalk.bold('Tools:') + '\n' else return out for (const topic of topics) { if (topic.hidden) continue - out += - ' ' + - chalk.bold.blue(topic.name) + - ' '.repeat(Math.max(1, this.prePad + this.postPad - topic.name.length)) + - topic.description + - '\n' + out + += ' ' + + chalk.bold.blue(topic.name) + + ' '.repeat(Math.max(1, this.prePad + this.postPad - topic.name.length)) + + topic.description + + '\n' } return out.trim() @@ -114,12 +114,12 @@ export default class CustomHelp extends Help { if (command.description) this.log(chalk.dim(command.description)) this.log( - chalk.bold('Usage:') + - ' ' + - chalk.bold('hyp ' + name) + - (args.length > 0 ? ' [...args]' : '') + - (flags.length > 0 ? chalk.blueBright(' [...flags]') : '') + - '\n', + chalk.bold('Usage:') + + ' ' + + chalk.bold('hyp ' + name) + + (args.length > 0 ? ' [...args]' : '') + + (flags.length > 0 ? chalk.blueBright(' [...flags]') : '') + + '\n', ) // if (examples) { // this.log(); @@ -159,29 +159,29 @@ export default class CustomHelp extends Help { this.log(this.formatRoot()) this.log('') if (!this.opts.all) { - rootTopics = rootTopics.filter((t) => !t.name.includes(':')) - rootCommands = rootCommands.filter((c) => !c.id.includes(':')) + rootTopics = rootTopics.filter(t => !t.name.includes(':')) + rootCommands = rootCommands.filter(c => !c.id.includes(':')) } for (const command of rootCommands) { if (command.id.length > this.prePad) this.prePad = command.id.length - const args = - Object.keys(command.args).length > 0 + const args + = Object.keys(command.args).length > 0 ? Object.entries(command.args) - .map((v) => { - if (!v[1].hidden && v[1].required && v[1].description && v[1].description.indexOf('-|-') > 0) { - return v[1].description.split('-|-')[0] - } - - return '' - }) - .join(' ') + .map(v => { + if (!v[1].hidden && v[1].required && v[1].description && v[1].description.indexOf('-|-') > 0) { + return v[1].description.split('-|-')[0] + } + + return '' + }) + .join(' ') : '' if (args.length > this.postPad) this.postPad = args.length } - this.postPad = - 6 + this.prePad + this.postPad > this.targetPad + this.postPad + = 6 + this.prePad + this.postPad > this.targetPad ? 6 + this.prePad + this.postPad - this.targetPad : this.targetPad - this.prePad this.prePad += 2 @@ -192,7 +192,7 @@ export default class CustomHelp extends Help { } if (rootCommands.length > 0) { - rootCommands = rootCommands.filter((c) => c.id) + rootCommands = rootCommands.filter(c => c.id) this.log(this.formatCommands(rootCommands)) this.log('') } @@ -202,26 +202,26 @@ export default class CustomHelp extends Help { async showTopicHelp(topic: Interfaces.Topic) { const {name} = topic - const commands = this.sortedCommands.filter((c) => c.id.startsWith(name + ':')) + const commands = this.sortedCommands.filter(c => c.id.startsWith(name + ':')) for (const command of commands) { if (command.id.split(':')[1].length > this.prePad) this.prePad = command.id.split(':')[1].length - const args = - Object.keys(command.args).length > 0 + const args + = Object.keys(command.args).length > 0 ? Object.entries(command.args) - .map((v) => { - if (!v[1].hidden && v[1].required && v[1].description && v[1].description.indexOf('-|-') > 0) { - return v[1].description.split('-|-')[0] - } - - return '' - }) - .join(' ') + .map(v => { + if (!v[1].hidden && v[1].required && v[1].description && v[1].description.indexOf('-|-') > 0) { + return v[1].description.split('-|-')[0] + } + + return '' + }) + .join(' ') : '' if (args.length > this.postPad) this.postPad = args.length } - this.postPad = - 6 + this.prePad + this.postPad > this.targetPad + this.postPad + = 6 + this.prePad + this.postPad > this.targetPad ? 6 + this.prePad + this.postPad - this.targetPad : this.targetPad - this.prePad this.prePad += 2 diff --git a/src/util/index.ts b/src/util/index.ts index e8a99ee..46692fa 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -11,7 +11,7 @@ type Org = { export function ask(question: string, rl: Interface, placeholder?: string): Promise { return new Promise((res, _) => { - rl.question(question + (placeholder ? ' ' + placeholder + ' ' : ''), (answer) => { + rl.question(question + (placeholder ? ' ' + placeholder + ' ' : ''), answer => { res(answer) }) }) @@ -96,5 +96,7 @@ export function readEnvFile(filePath: string): { const orgIdMatch = content.match(/HYP_ORG_ID=(.*)/) const orgId = orgIdMatch ? orgIdMatch[1] : null - return {content, email, jwt, orgId} + return { + content, email, jwt, orgId, + } } From 9ecf01f4e36604f63be6606676e2f443273ff093 Mon Sep 17 00:00:00 2001 From: Jairus Date: Fri, 4 Oct 2024 19:00:54 -0700 Subject: [PATCH 4/5] release tag should include version --- .github/workflows/dev-release.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/dev-release.yml b/.github/workflows/dev-release.yml index 1df4cdd..9559d64 100644 --- a/.github/workflows/dev-release.yml +++ b/.github/workflows/dev-release.yml @@ -2,15 +2,12 @@ name: Dev Release on: push: - tags: - - "v*.*.*" branches: - main pull_request: - tags: - - "v*.*.*" branches: - '**' + env: draft: true @@ -31,7 +28,7 @@ jobs: - name: Get package version id: package-version - uses: martinbeentjes/npm-get-version-action@v1.3.1 + run: echo "PACKAGE_VERSION=$(node -p \"require('./package.json').version\")" >> $GITHUB_ENV - name: Install dependencies run: npm install @@ -45,8 +42,10 @@ jobs: - name: Create release uses: softprops/action-gh-release@v1 with: + tag_name: "v${{ env.PACKAGE_VERSION }}-${{ github.sha }}" + name: "Release v${{ env.PACKAGE_VERSION }}-${{ github.sha }}" draft: ${{ env.draft }} - files: ./dist/*.tar.gz prerelease: true + files: ./dist/*.tar.gz env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Token for GitHub API From cd5480cb21b2af251b2522c208536f552b33b89b Mon Sep 17 00:00:00 2001 From: Jairus Date: Fri, 4 Oct 2024 19:04:15 -0700 Subject: [PATCH 5/5] update tag name --- .github/workflows/dev-release.yml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/dev-release.yml b/.github/workflows/dev-release.yml index 9559d64..69549d5 100644 --- a/.github/workflows/dev-release.yml +++ b/.github/workflows/dev-release.yml @@ -7,7 +7,6 @@ on: pull_request: branches: - '**' - env: draft: true @@ -16,7 +15,7 @@ jobs: permissions: write-all name: Dev Release runs-on: ubuntu-latest - + steps: - name: Checkout code uses: actions/checkout@v3 @@ -28,11 +27,11 @@ jobs: - name: Get package version id: package-version - run: echo "PACKAGE_VERSION=$(node -p \"require('./package.json').version\")" >> $GITHUB_ENV - + uses: martinbeentjes/npm-get-version-action@v1.3.1 + - name: Install dependencies run: npm install - + - name: Build files run: npm run build @@ -42,10 +41,9 @@ jobs: - name: Create release uses: softprops/action-gh-release@v1 with: - tag_name: "v${{ env.PACKAGE_VERSION }}-${{ github.sha }}" - name: "Release v${{ env.PACKAGE_VERSION }}-${{ github.sha }}" + tag_name: v${{ steps.package-version.outputs.current-version }}-${{ github.sha }} draft: ${{ env.draft }} - prerelease: true files: ./dist/*.tar.gz + prerelease: true env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Token for GitHub API + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}