Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try and fix this ci #7

Merged
merged 6 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/dist
/tmp
13 changes: 7 additions & 6 deletions .github/workflows/dev-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ on:
pull_request:
branches:
- '**'
env:
draft: true

jobs:
dev-release:
permissions: write-all
name: Dev Release
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -26,10 +28,10 @@ jobs:
- name: Get package version
id: package-version
uses: martinbeentjes/[email protected]

- name: Install dependencies
run: npm install

- name: Build files
run: npm run build

Expand All @@ -38,11 +40,10 @@ jobs:

- name: Create release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
tag_name: ${{ github.ref }}
tag_name: v${{ steps.package-version.outputs.current-version }}-${{ github.sha }}
draft: ${{ env.draft }}
files: ./dist/*.tar.gz
draft: false
prerelease: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24 changes: 13 additions & 11 deletions src/commands/login/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions src/commands/logout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'})
}
Expand Down
22 changes: 12 additions & 10 deletions src/commands/org/switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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'})

Expand Down
132 changes: 66 additions & 66 deletions src/custom/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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 <command> [...flags] [...args]
out +=
chalk.bold('Usage: hyp') +
' ' +
chalk.dim('<command>') +
' ' +
chalk.bold.blueBright('[...flags]') +
' ' +
chalk.bold('[...args]')
out
+= chalk.bold('Usage: hyp')
+ ' '
+ chalk.dim('<command>')
+ ' '
+ 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'
Expand All @@ -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()
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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('')
}
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Org = {

export function ask(question: string, rl: Interface, placeholder?: string): Promise<string> {
return new Promise<string>((res, _) => {
rl.question(question + (placeholder ? ' ' + placeholder + ' ' : ''), (answer) => {
rl.question(question + (placeholder ? ' ' + placeholder + ' ' : ''), answer => {
res(answer)
})
})
Expand Down Expand Up @@ -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,
}
}
Loading