Skip to content

Commit

Permalink
refactor: better tsconfig and ts support
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoRCD committed Apr 1, 2024
1 parent 9519fd3 commit 8ebcbd9
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 31 deletions.
2 changes: 1 addition & 1 deletion apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
"unbuild": "^2.0.0"
},
"license": "Apache-2.0"
}
}
2 changes: 1 addition & 1 deletion apps/cli/src/commands/create.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineCommand } from 'citty'
import consola from 'consola'
import { createProject } from '../utils/projects.ts'
import { createProject } from '../utils/projects'

export default defineCommand({
meta: {
Expand Down
4 changes: 2 additions & 2 deletions apps/cli/src/commands/link.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineCommand } from 'citty'
import { consola } from 'consola'
import { getProjectByName, getProjects, writeProjectConfig } from '../utils/projects.ts'
import { suggestCreateProject } from '../utils/suggest.ts'
import { getProjectByName, getProjects, writeProjectConfig } from '../utils/projects'
import { suggestCreateProject } from '../utils/suggest'

export default defineCommand({
meta: {
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/commands/login.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineCommand } from 'citty'
import { consola } from 'consola'
import { getComputerName, loadUserConfig, writeUserConfig } from '../utils/config'
import { $api } from '../utils/connection.ts'
import { $api } from '../utils/connection'

export default defineCommand({
meta: {
Expand Down
4 changes: 2 additions & 2 deletions apps/cli/src/commands/open.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { defineCommand } from 'citty'
import { consola } from 'consola'
import open from 'open'
import { getProjectId } from '../utils/projects.ts'
import { suggestLinkProjects } from '../utils/suggest.ts'
import { getProjectId } from '../utils/projects'
import { suggestLinkProjects } from '../utils/suggest'

export default defineCommand({
meta: {
Expand Down
6 changes: 3 additions & 3 deletions apps/cli/src/commands/pull.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { defineCommand } from 'citty'
import consola from 'consola'
import { createEnvFile, getProjectVariable } from '../utils/env.ts'
import { getProjectId } from '../utils/projects.ts'
import { suggestLinkProjects } from '../utils/suggest.ts'
import { createEnvFile, getProjectVariable } from '../utils/env'
import { getProjectId } from '../utils/projects'
import { suggestLinkProjects } from '../utils/suggest'

export default defineCommand({
meta: {
Expand Down
6 changes: 3 additions & 3 deletions apps/cli/src/commands/push.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { defineCommand } from 'citty'
import consola from 'consola'
import { pushProjectVariable } from '../utils/env.ts'
import { getProjectId } from '../utils/projects.ts'
import { suggestLinkProjects } from '../utils/suggest.ts'
import { pushProjectVariable } from '../utils/env'
import { getProjectId } from '../utils/projects'
import { suggestLinkProjects } from '../utils/suggest'

export default defineCommand({
meta: {
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/commands/unlink.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineCommand } from 'citty'
import { consola } from 'consola'
import { deleteProjectConfig } from '../utils/projects.ts'
import { deleteProjectConfig } from '../utils/projects'

export default defineCommand({
meta: {
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/commands/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineCommand } from 'citty'
import consola from 'consola'
import { execa } from 'execa'
import { name, version } from '../../package.json'
import { isLatestVersion } from '../utils/update.ts'
import { isLatestVersion } from '../utils/update'

export default defineCommand({
meta: {
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/commands/whoami.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineCommand } from 'citty'
import consola from 'consola'
import { loadUserConfig } from '../utils/config.ts'
import { loadUserConfig } from '../utils/config'

export default defineCommand({
meta: {
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import { runMain } from 'citty'
import { main } from './main.ts'
import { main } from './main'

runMain(main).then(() => process.exit(0)).catch(() => process.exit(1))
2 changes: 1 addition & 1 deletion apps/cli/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineCommand } from 'citty'
import { version, description } from '../package.json'
import { checkForUpdates } from './utils/update.ts'
import { checkForUpdates } from './utils/update'

export const main = defineCommand({
meta: {
Expand Down
4 changes: 2 additions & 2 deletions apps/cli/src/utils/connection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ofetch } from 'ofetch'
import consola from 'consola'
import { loadUserConfig, writeUserConfig } from './config.ts'
import { suggestLogin } from './suggest.ts'
import { loadUserConfig, writeUserConfig } from './config'
import { suggestLogin } from './suggest'

const SHELVE_API_URL = process.env.NODE_ENV === 'development' ? 'http://localhost:3000/api' : 'https://shelve.hrcd.fr/api'

Expand Down
3 changes: 2 additions & 1 deletion apps/cli/src/utils/env.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import type { EnvFile, VariablesCreateInput } from '@shelve/types'
import consola from 'consola'
import { $api } from './connection.ts'
import { $api } from './connection'

export function isEnvFileExist(): boolean {
return fs.existsSync('.env')
Expand All @@ -22,6 +22,7 @@ export function getEnvFile(): EnvFile {
const envFileContent = envFile.split('\n').filter((item) => item && !item.startsWith('#')).join('\n')
return envFileContent.split('\n').map((item) => {
const [key, value] = item.split('=')
if (!key || !value) throw new Error('Invalid .env file')
return {key, value}
})
}
Expand Down
4 changes: 2 additions & 2 deletions apps/cli/src/utils/projects.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs'
import type { Project } from '@shelve/types'
import consola from 'consola'
import { $api } from './connection.ts'
import { suggestLinkProject } from './suggest.ts'
import { $api } from './connection'
import { suggestLinkProject } from './suggest'

export async function getProjects(): Promise<Project[]> {
return await $api('/project', {
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/utils/string.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function capitalize(str: string): string {
return str[0].toUpperCase() + str.slice(1)
return str.charAt(0).toUpperCase() + str.slice(1)
}
6 changes: 3 additions & 3 deletions apps/cli/src/utils/suggest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import consola from 'consola'
import { runCommand } from 'citty'
import type { Project } from '@shelve/types'
import link from '../commands/link.ts'
import login from '../commands/login.ts'
import { createProject } from './projects.ts'
import link from '../commands/link'
import login from '../commands/login'
import { createProject } from './projects'

export async function suggestCreateProject(name?: string): Promise<Project | null> {
const accept = await consola.prompt(`Do you want to create ${name ? 'the project' : 'a project'}? (y/n)`, {
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/utils/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as semver from 'semver'
import { $fetch } from 'ofetch'
import consola from 'consola'
import { name, version, repository } from '../../package.json'
import { capitalize } from './string.ts'
import { capitalize } from './string'

export async function checkForUpdates(): Promise<void> {
const { version: latestVersion = '' } = await $fetch(
Expand Down
10 changes: 7 additions & 3 deletions apps/cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
{
"compilerOptions": {
"esModuleInterop": false,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"noUncheckedIndexedAccess": true,
"moduleResolution": "Bundler",
"strict": true,
"moduleDetection": "force",
"isolatedModules": true,
"noImplicitAny": true,
"allowJs": true,
"noEmit": true,
"noUnusedLocals": true,
"resolveJsonModule": true,
"types": ["node", "./types"],
"declaration": true,
"types": ["node"],
},
"include": ["src"]
}

0 comments on commit 8ebcbd9

Please sign in to comment.