Skip to content

Commit 239f70b

Browse files
committed
More fixes
1 parent 816e10c commit 239f70b

File tree

33 files changed

+1046
-1465
lines changed

33 files changed

+1046
-1465
lines changed

.lefthook.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ pre-commit:
33
commands:
44
deno-lint:
55
run: deno lint
6+
deno-check:
7+
run: deno check

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"window.title": "${folderName} ${separator}${activeRepositoryBranchName}${separator}${remoteName} (python)",
2+
"window.title": "${folderName} ${separator}${activeRepositoryBranchName}${separator}${remoteName} (deno)",
33
"files.exclude": {
44
"**/.git": true,
55
"**/.data": true,

bin/dev.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { cleanupTerminal, run as runInstall } from '../commands/install.ts'
77
import { run as runRepos } from '../commands/repos.ts'
88
import { run as runTask } from '../commands/task.ts'
99
import { startServer } from '../devserver/webframework/webframework.ts'
10+
import process from "node:process";
1011

1112
const version = '0.4.0' // TODO
1213

commands/install.ts

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import path from 'node:path'
22
import fs from 'node:fs/promises'
33
import os from 'node:os'
4-
import util, { styleText } from 'node:util'
4+
import { styleText } from 'node:util'
55

66
import ansiEscapes from 'ansi-escapes'
77
import dedent from 'dedent'
88
import { execa } from 'execa'
99
import semver from 'semver'
1010
import { fileExists } from '#common'
11-
import type { CommandInstallOptions, InstalledProject } from '#types'
11+
import type { CommandFixOptions, InstalledProject } from '#types'
12+
import process from 'node:process'
13+
14+
function writeStdout(str: string) {
15+
Deno.stdout.write(new TextEncoder().encode(str))
16+
}
1217

1318
const Projects: InstalledProject[] = [
1419
{
@@ -82,7 +87,7 @@ const Projects: InstalledProject[] = [
8287
try {
8388
await execa({ shell: true })`command -v woof`
8489
return true
85-
} catch (err) {
90+
} catch {
8691
return false
8792
}
8893
},
@@ -114,27 +119,27 @@ const Ctx = {
114119
currentProject: Projects[0].name,
115120
}
116121
export function cleanupTerminal() {
117-
process.stdout.write(ansiEscapes.cursorRestorePosition)
118-
process.stdout.write(ansiEscapes.cursorShow)
119-
process.stdout.write(ansiEscapes.exitAlternativeScreen)
122+
writeStdout(ansiEscapes.cursorRestorePosition)
123+
writeStdout(ansiEscapes.cursorShow)
124+
writeStdout(ansiEscapes.exitAlternativeScreen)
120125
}
121126
let ignoreKeystrokes = false
122-
export async function run(values: CommandInstallOptions, positionals: string[]) {
127+
export async function run(options: CommandFixOptions, positionals: string[]) {
123128
await fs.mkdir(Ctx.devDir, { recursive: true })
124129
await fs.mkdir(Ctx.repositoryDir, { recursive: true })
125130

126131
process.stdin.setRawMode(true)
127-
process.stdout.write(ansiEscapes.cursorSavePosition)
128-
process.stdout.write(ansiEscapes.cursorHide)
129-
process.stdout.write(ansiEscapes.enterAlternativeScreen)
132+
writeStdout(ansiEscapes.cursorSavePosition)
133+
writeStdout(ansiEscapes.cursorHide)
134+
writeStdout(ansiEscapes.enterAlternativeScreen)
130135
process.on('exit', () => {
131136
if (!globalThis.skipTerminalCleanup) {
132137
cleanupTerminal()
133138
}
134139
})
135-
process.on('uncaughtException', (err) => {})
140+
process.on('uncaughtException', () => {})
136141

137-
process.stdout.write(`Fetching data...\n`)
142+
writeStdout(`Fetching data...\n`)
138143
await updateProjectData()
139144
await render('')
140145

@@ -164,9 +169,9 @@ async function renderMainScreen(char: string) {
164169
}
165170

166171
if (char === '\x1B' || char === 'q') {
167-
process.stdout.write(ansiEscapes.cursorRestorePosition)
168-
process.stdout.write(ansiEscapes.cursorShow)
169-
process.stdout.write(ansiEscapes.exitAlternativeScreen)
172+
writeStdout(ansiEscapes.cursorRestorePosition)
173+
writeStdout(ansiEscapes.cursorShow)
174+
writeStdout(ansiEscapes.exitAlternativeScreen)
170175
Deno.exit()
171176
} else if (char === 'j') {
172177
const idx = Projects.findIndex((project) => project.name === Ctx.currentProject)
@@ -178,12 +183,12 @@ async function renderMainScreen(char: string) {
178183
Ctx.currentProject = Projects[newIdx].name
179184
} else if (char === 'c') {
180185
if (project.data.isCloned) {
181-
process.stdout.write(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
182-
process.stdout.write('Repository already cloned...\n')
186+
writeStdout(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
187+
writeStdout('Repository already cloned...\n')
183188
} else {
184189
const dir = path.join(Ctx.repositoryDir, project.name)
185190

186-
process.stdout.write(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
191+
writeStdout(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
187192
ignoreKeystrokes = true
188193
await execa({
189194
stdio: 'inherit',
@@ -196,16 +201,16 @@ async function renderMainScreen(char: string) {
196201
if (project.data.isCloned) {
197202
const dir = path.join(Ctx.repositoryDir, project.name)
198203

199-
process.stdout.write(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
200-
process.stdout.write(
204+
writeStdout(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
205+
writeStdout(
201206
`REMOVING DIRECTORY: ${path.join(Ctx.repositoryDir, project.name)}\n`,
202207
)
203-
process.stdout.write(`Exit with "q/esc" to abort in less than 5 seconds\n`)
208+
writeStdout(`Exit with "q/esc" to abort in less than 5 seconds\n`)
204209
await new Promise((resolve, reject) => {
205210
setTimeout(async () => {
206211
try {
207212
await fs.rm(dir, { recursive: true })
208-
process.stdout.write('Done. Updating project data...\n')
213+
writeStdout('Done. Updating project data...\n')
209214
await updateProjectData()
210215
await waitOnConfirmInput()
211216
} catch (err) {
@@ -216,15 +221,15 @@ async function renderMainScreen(char: string) {
216221
}, 5000)
217222
})
218223
} else {
219-
process.stdout.write(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
220-
process.stdout.write('Repository already removed...\n')
224+
writeStdout(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
225+
writeStdout('Repository already removed...\n')
221226
await waitOnConfirmInput()
222227
}
223228
} else if (char === 'i') {
224229
if (project.data.isCloned) {
225230
const dir = path.join(Ctx.repositoryDir, project.name)
226231

227-
process.stdout.write(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
232+
writeStdout(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
228233
const scriptFile = path.join(os.tmpdir(), `dev-${crypto.randomUUID()}.sh`)
229234
await fs.writeFile(scriptFile, project.install)
230235
ignoreKeystrokes = true
@@ -235,15 +240,15 @@ async function renderMainScreen(char: string) {
235240
ignoreKeystrokes = false
236241
await updateProjectData()
237242
} else {
238-
process.stdout.write(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
239-
process.stdout.write('Repository does not exist...\n')
243+
writeStdout(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
244+
writeStdout('Repository does not exist...\n')
240245
}
241246
await waitOnConfirmInput()
242247
} else if (char === 'u') {
243248
if (project.data.isCloned) {
244249
const dir = path.join(Ctx.repositoryDir, project.name)
245250

246-
process.stdout.write(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
251+
writeStdout(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
247252
const scriptFile = path.join(os.tmpdir(), `dev-${crypto.randomUUID()}.sh`)
248253
await fs.writeFile(scriptFile, project.uninstall)
249254
ignoreKeystrokes = true
@@ -254,29 +259,29 @@ async function renderMainScreen(char: string) {
254259
ignoreKeystrokes = false
255260
await updateProjectData()
256261
} else {
257-
process.stdout.write(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
258-
process.stdout.write('Repository does not exist...\n')
262+
writeStdout(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
263+
writeStdout('Repository does not exist...\n')
259264
}
260265
await waitOnConfirmInput()
261266
} else if (char === 'r') {
262-
process.stdout.write('LOADING...\n')
267+
writeStdout('LOADING...\n')
263268
await updateProjectData()
264269
} else if (char === 'v') {
265270
currentScreen = 'update-version'
266271
await render('')
267272
return
268273
}
269274

270-
const sep = '='.repeat(process.stdout.columns)
275+
const sep = '='.repeat(Deno.consoleSize().columns)
271276
const nameColLen = 13
272277
const clonedColLen = 8
273278
const installedColLen = 11
274279
const currentRef = 14
275280
const latestRef = 14
276281

277-
process.stdout.write(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
278-
process.stdout.write(`${sep}\n`)
279-
process.stdout.write(
282+
writeStdout(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
283+
writeStdout(`${sep}\n`)
284+
writeStdout(
280285
' ' +
281286
'Name'.padEnd(nameColLen) +
282287
'Cloned'.padEnd(clonedColLen) +
@@ -285,7 +290,7 @@ async function renderMainScreen(char: string) {
285290
'Latest Ref'.padEnd(latestRef) +
286291
'\n',
287292
)
288-
process.stdout.write(`${sep}\n`)
293+
writeStdout(`${sep}\n`)
289294
for (const project of Projects) {
290295
if (!project?.data) {
291296
throw new Error(`Project does not have data attached: \"${project.name}\"`)
@@ -315,10 +320,10 @@ async function renderMainScreen(char: string) {
315320
str += '\n'
316321
str = str.replaceAll('YES', styleText('green', 'yes'))
317322
str = str.replaceAll('NO', styleText('red', 'no'))
318-
process.stdout.write(str)
323+
writeStdout(str)
319324
}
320-
process.stdout.write(`${sep}\n`)
321-
process.stdout.write(dedent`
325+
writeStdout(`${sep}\n`)
326+
writeStdout(dedent`
322327
CONTROLS
323328
- j/k: Move up/down
324329
- c: Clone repository
@@ -328,7 +333,7 @@ async function renderMainScreen(char: string) {
328333
- r: Refresh refs
329334
- v: Switch version/ref of repository
330335
- q/esc: Exit program\n`)
331-
process.stdout.write(`${sep}\n`)
336+
writeStdout(`${sep}\n`)
332337
}
333338

334339
let currentVersion = 0
@@ -346,7 +351,7 @@ async function renderUpdateVersionScreen(char: string) {
346351
currentVersion = Math.max(0, currentVersion - 1)
347352
} else if (char === '\x0D') {
348353
ignoreKeystrokes = true
349-
process.stdout.write(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
354+
writeStdout(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
350355
const ref = project.data.versions[currentVersion]
351356
const dir = path.join(Ctx.repositoryDir, project.name)
352357
await execa`git -C ${dir} reset --hard HEAD`
@@ -368,21 +373,21 @@ async function renderUpdateVersionScreen(char: string) {
368373
return
369374
}
370375

371-
const sep = '='.repeat(process.stdout.columns)
372-
process.stdout.write(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
373-
process.stdout.write(`REPOSITORY: ${project.name}\n`)
376+
const sep = '='.repeat(Deno.consoleSize().columns)
377+
writeStdout(ansiEscapes.eraseScreen + ansiEscapes.cursorTo(0, 0))
378+
writeStdout(`REPOSITORY: ${project.name}\n`)
374379
for (let i = 0; i < project.data.versions.length; ++i) {
375380
const version = project.data.versions[i]
376-
process.stdout.write(`[${i === currentVersion ? 'x' : ' '}] ${version}\n`)
381+
writeStdout(`[${i === currentVersion ? 'x' : ' '}] ${version}\n`)
377382
}
378-
process.stdout.write(`${sep}\n`)
379-
process.stdout.write(dedent`
383+
writeStdout(`${sep}\n`)
384+
writeStdout(dedent`
380385
CONTROLS
381386
- j/k: Move up/down
382387
- Enter: Select version
383388
- v/backspace: Go back
384389
- q/esc: Exit program\n`)
385-
process.stdout.write(`${sep}\n`)
390+
writeStdout(`${sep}\n`)
386391
}
387392

388393
async function updateProjectData() {
@@ -449,7 +454,7 @@ async function updateProjectData() {
449454
}
450455

451456
async function waitOnConfirmInput() {
452-
process.stdout.write('PRESS ENTER TO CONTINUE...\n')
457+
writeStdout('PRESS ENTER TO CONTINUE...\n')
453458
await new Promise((resolve, reject) => {
454459
process.stdin
455460
.once('data', (data) => {

commands/lint.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import * as path from 'node:path'
44
import * as fs from 'node:fs/promises'
55
import * as readline from 'node:readline/promises'
6-
import util, { styleText } from 'node:util'
6+
import { styleText } from 'node:util'
77
import { fileExists, pkgRoot } from '#common'
88
import yn from 'yn'
99
import toml from 'smol-toml'
@@ -15,8 +15,8 @@ import { xdgConfig } from 'xdg-basedir'
1515
import { getEcosystems } from '../devutils/index.ts'
1616

1717
import type { CommandFixOptions, Config, Issue, Project } from '#types'
18-
import type { PackageJson } from 'type-fest'
1918
import _ from 'lodash'
19+
import process from 'node:process'
2020

2121
export async function run(options: CommandFixOptions, positionals: string[]) {
2222
if (positionals.length > 0) {
@@ -196,7 +196,7 @@ export async function run(options: CommandFixOptions, positionals: string[]) {
196196
}\n`
197197
}
198198

199-
process.stdout.write(str)
199+
Deno.stdout.write(new TextEncoder().encode(str))
200200
}
201201

202202
for (const fixFile of ruleFiles) {
@@ -340,7 +340,7 @@ async function getProject(): Promise<Project> {
340340
'clone.defaultRemoteName',
341341
])
342342
}
343-
} catch (err) {
343+
} catch {
344344
// If there is a git branch, but no configured remotes, then control flow reaches here.
345345
return {
346346
stdout: null,

commands/new.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { existsSync } from 'node:fs'
1111

1212
const _dirname = import.meta.dirname
1313

14-
export async function run(values: CommandNewOptions, positionals: string[]) {
14+
export async function run(options: CommandNewOptions, positionals: string[]) {
1515
if (!positionals[0]) {
1616
const input = await inquirer.input({
1717
message: 'Choose a directory',
@@ -29,7 +29,7 @@ export async function run(values: CommandNewOptions, positionals: string[]) {
2929
}
3030
}
3131

32-
if (!values.ecosystem) {
32+
if (!options.ecosystem) {
3333
const input = await inquirer.select({
3434
message: 'Choose an ecosystem',
3535
choices: [
@@ -40,14 +40,14 @@ export async function run(values: CommandNewOptions, positionals: string[]) {
4040
{ name: 'C++', value: 'cpp' },
4141
],
4242
})
43-
values.ecosystem = input
43+
options.ecosystem = input
4444
}
4545

46-
if (!values.templateName) {
46+
if (!options.templateName) {
4747
const templateData = getTemplateData()
48-
const parameters = templateData[values.ecosystem]?.templates
48+
const parameters = templateData[options.ecosystem]?.templates
4949
if (!parameters) {
50-
throw new Error(`Ecosystem "${values.ecosystem}" not supported`)
50+
throw new Error(`Ecosystem "${options.ecosystem}" not supported`)
5151
}
5252

5353
const value = await inquirer.select({
@@ -58,24 +58,24 @@ export async function run(values: CommandNewOptions, positionals: string[]) {
5858
})),
5959
})
6060

61-
values.templateName = value
61+
options.templateName = value
6262
}
6363

64-
if (!values.projectName) {
64+
if (!options.projectName) {
6565
const value = await inquirer.input({
6666
message: 'What is the project name?',
6767
})
6868

69-
values.projectName = value
69+
options.projectName = value
7070
}
7171

7272
await createProject({
7373
dir: positionals[0] ?? '.',
74-
ecosystem: values.ecosystem,
75-
templateName: values.templateName,
76-
projectName: values.projectName,
77-
forceTemplate: values.force ?? false,
78-
options: (values.options ?? '').split(','),
74+
ecosystem: options.ecosystem,
75+
templateName: options.templateName,
76+
projectName: options.projectName,
77+
forceTemplate: options.force ?? false,
78+
options: (options.options ?? '').split(','),
7979
})
8080
}
8181

0 commit comments

Comments
 (0)