• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tinyhttp / cli / 5870074099

pending completion
5870074099

push

github

talentlessguy
update ci

3 of 3 branches covered (100.0%)

Branch coverage included in aggregate %.

43 of 124 relevant lines covered (34.68%)

0.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

36.22
/src/utils.ts
1
import { writeFile, mkdir } from 'node:fs/promises'
1✔
2
import ora from 'ora'
1✔
3
import { fetch, RequestInit } from 'undici'
1✔
4
import editPkgJson from 'edit-json-file'
1✔
5
import * as colorette from 'colorette'
1✔
6
import { exec } from 'node:child_process'
1✔
7
import { promisify } from 'node:util'
1✔
8

1✔
9
export const msg = (m: string, color: string) => console.log(colorette[color](m))
1✔
10

1✔
11
export const runCmd = promisify(exec)
1✔
12

1✔
13
export const install = async (pkg: string, pkgs: string[], dev = true) =>
1✔
14
  await runCmd(`${pkg} ${pkg === 'yarn' ? 'add' : 'i'} ${dev ? '-D' : '-S'} ${pkgs.join(' ')}`)
×
15

1✔
16
export const httpHeaders: RequestInit = {
1✔
17
  headers: { 'user-agent': 'node.js' }
1✔
18
}
1✔
19

1✔
20
export const fileFetcher = async (data: any, statusCode: number, dir?: string) => {
1✔
21
  const spinner = ora()
×
22

×
23
  spinner.start(colorette.blue(`Fetching ${data.length} files...`))
×
24

×
25
  if (statusCode !== 200) console.warn(`Bad status code: ${statusCode}`)
×
26

×
27
  // Download files
×
28
  for (const { name, download_url, type, url } of data) {
×
29
    if (type !== 'dir') {
×
30
      spinner.text = `Fetching ${name} file`
×
31
      const res = await fetch(download_url, httpHeaders)
×
32
      const data = (await res.json()) as string
×
33
      try {
×
34
        await writeFile(dir ? `${dir}/${name}` : name, data)
×
35
      } catch {
×
36
        throw new Error('Failed to create a project file')
×
37
      }
×
38
    } else {
×
39
      spinner.text = `Scanning ${name} directory`
×
40
      try {
×
41
        await mkdir(name)
×
42
      } catch {
×
43
        throw new Error('Failed to create a project subdirectory')
×
44
      }
×
45
      const res = await fetch(url, httpHeaders)
×
46
      const data = await res.json()
×
47
      await fileFetcher(data, res.status, name)
×
48
    }
×
49
  }
×
50

×
51
  spinner.stop()
×
52
}
×
53

1✔
54
export const installPackages = async (pkg: string) => {
1✔
55
  // Edit package.json
×
56

×
57
  const file = editPkgJson('package.json')
×
58

×
59
  const allDeps = Object.keys(file.get('dependencies'))
×
60

×
61
  // Replace "workspace:*" with "latest"
×
62

×
63
  const thDeps = allDeps.filter((x) => x.startsWith('@tinyhttp'))
×
64

×
65
  const newDeps = {}
×
66

×
67
  for (const dep of thDeps) newDeps[dep] = 'latest'
×
68

×
69
  file
×
70
    .set('dependencies', {
×
71
      ...file.get('dependencies'),
×
72
      ...newDeps
×
73
    })
×
74
    .save()
×
75

×
76
  const depCount =
×
77
    (Object.keys(file.get('dependencies')) || []).length + (Object.keys(file.get('devDependencies') || {}) || []).length
×
78

×
79
  const spinner = ora()
×
80

×
81
  spinner.start(colorette.cyan(`Installing ${depCount} package${depCount > 1 ? 's' : ''} with ${pkg} 📦`))
×
82

×
83
  try {
×
84
    await runCmd(`${pkg} ${pkg === 'yarn' ? 'add' : 'i'}`)
×
85
  } catch {
×
86
    throw new Error('Failed to install packages')
×
87
  }
×
88

×
89
  spinner.stop()
×
90
}
×
91

1✔
92
const ESLINT_JS_CONFIG = `
1✔
93
{
1✔
94
  "env": {
1✔
95
    "es6": true,
1✔
96
    "node": true
1✔
97
  },
1✔
98
  "parserOptions": {
1✔
99
    "ecmaVersion": 2020,
1✔
100
    "sourceType": "module"
1✔
101
  },
1✔
102
  "plugins": ["prettier"],
1✔
103
  "extends": ["eslint:recommended", "prettier"],
1✔
104
}
1✔
105
`
1✔
106

1✔
107
export const setupEslint = async (pkg: string) => {
1✔
108
  msg(`Setting up ESLint`, 'green')
×
109
  try {
×
110
    await install(pkg, ['eslint', 'prettier', 'eslint-config-prettier', 'eslint-plugin-prettier'], true)
×
111
  } catch {
×
112
    throw new Error('Failed to install ESLint')
×
113
  }
×
114
  try {
×
115
    await writeFile('.eslintrc', ESLINT_JS_CONFIG)
×
116
  } catch {
×
117
    throw new Error('Failed to create ESLint config')
×
118
  }
×
119
}
×
120

1✔
121
export const setPackageJsonName = (name: string) => {
1✔
122
  const file = editPkgJson('package.json')
1✔
123
  file.set('name', name).save()
1✔
124
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc