Skip to content

Commit e69e64a

Browse files
committed
Awesome improvements
1 parent 7a5c287 commit e69e64a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+6873
-625
lines changed

.zed/settings.json

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,53 @@
11
{
2-
"file_scan_exclusions": ["**/.git", "**/.data"]
2+
"file_scan_exclusions": ["**/.git", "**/.data"],
3+
"lsp": {
4+
"deno": {
5+
"settings": {
6+
"deno": {
7+
"enable": true
8+
}
9+
}
10+
},
11+
"languages": {
12+
"JavaScript": {
13+
"language_servers": [
14+
"deno",
15+
"!typescript-language-server",
16+
"!vtsls",
17+
"!eslint"
18+
]
19+
},
20+
"JSX": {
21+
"language_servers": [
22+
"deno",
23+
"!typescript-language-server",
24+
"!vtsls",
25+
"!eslint"
26+
]
27+
},
28+
"TypeScript": {
29+
"language_servers": [
30+
"deno",
31+
"!typescript-language-server",
32+
"!vtsls",
33+
"!eslint"
34+
],
35+
"prettier": { "allowed": true }
36+
// "formatter": {
37+
// "external": {
38+
// "command": "prettier",
39+
// "arguments": ["--stdin-filepath", "{buffer_path}"]
40+
// }
41+
// }
42+
},
43+
"TSX": {
44+
"language_servers": [
45+
"deno",
46+
"!typescript-language-server",
47+
"!vtsls",
48+
"!eslint"
49+
]
50+
}
51+
}
52+
}
353
}

bin/dev.js renamed to bin/dev.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ import { run as runInstall, cleanupTerminal } from '../commands/install.ts'
1010
import { run as runRepos } from '../commands/repos.ts'
1111
import { run as runTask } from '../commands/task.ts'
1212
import { startServer } from '../devserver/webframework.ts'
13+
import type { PackageJson } from 'type-fest'
1314

14-
/**
15-
* @import { PackageJson } from "type-fest";
16-
*/
17-
18-
/** @type {PackageJson} */
19-
const packageJson = JSON.parse(
15+
const packageJson: PackageJson = JSON.parse(
2016
await fs.readFile(path.join(import.meta.dirname, '../package.json'), 'utf-8'),
2117
)
2218

commands/install.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const Projects: InstalledProject[] = [
1616
url: 'https://github.com/fox-incubating/sauerkraut',
1717
install: dedent`
1818
pnpm install
19-
ln -sf "$PWD/bin/sauerkraut.js" ~/.local/bin/sauerkraut
19+
ln -sf "$PWD/bin/sauerkraut.js" ~/.dotfiles/.data/bin/sauerkraut
2020
cat <<"EOF" > ~/.local/share/systemd/user/brain.service
2121
[Unit]
2222
Description=Brain
@@ -45,6 +45,20 @@ const Projects: InstalledProject[] = [
4545
return await fileExists(path.join(os.homedir(), '.local/bin/sauerkraut'))
4646
},
4747
},
48+
{
49+
name: 'd',
50+
url: 'https://github.com/fox-incubating/d',
51+
install: dedent`
52+
./bake build
53+
ln -s "$PWD/d" ~/.dotfiles/.data/bin/d
54+
`,
55+
uninstall: dedent`
56+
57+
`,
58+
async installed() {
59+
return await fileExists(path.join(os.homedir(), '.dotfiles/.data/bin/d'))
60+
},
61+
},
4862
{
4963
name: 'pick-sticker',
5064
url: 'https://github.com/fox-projects/pick-sticker',

commands/lint.ts

Lines changed: 105 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import { execa } from 'execa'
1111
import { globby } from 'globby'
1212
import ansiEscapes from 'ansi-escapes'
1313

14-
import type { CommandFixOptions, Project } from '#types'
14+
import type { CommandFixOptions, Config, Issue, Project } from '#types'
15+
import type { PackageJson } from 'type-fest'
16+
import _ from 'lodash'
1517

1618
export async function run(options: CommandFixOptions, positionals: string[]) {
1719
if (positionals.length > 0) {
@@ -20,34 +22,37 @@ export async function run(options: CommandFixOptions, positionals: string[]) {
2022

2123
const project = await getProject()
2224

23-
let config = {}
25+
const globalConfig = {
26+
skippedOrganizations: ['bash-bastion'],
27+
skippedRepositories: ['SchemaStore/schemastore'],
28+
}
29+
30+
let config: Config = {
31+
rules: {
32+
...(project.type === 'with-remote-url' &&
33+
`${project.owner}/${project.name}` === 'awesome-lists/awesome-bash'
34+
? {
35+
'remote-url/remote-metadata/disable-projects-tab': 'off',
36+
'remote-url/remote-metadata/default-branch-main': 'off',
37+
}
38+
: {}),
39+
},
40+
}
2441
try {
25-
config = toml.parse(
26-
await fs.readFile(path.join(project.rootDir, 'project.toml'), 'utf-8'),
27-
)
42+
config = _.merge(
43+
config,
44+
toml.parse(await fs.readFile(path.join(project.rootDir, 'dev.toml'), 'utf-8')),
45+
) as Config
2846
} catch (err) {
2947
if ((err as NodeJS.ErrnoException)?.code !== 'ENOENT') {
3048
throw err
3149
}
3250
}
3351

34-
// Print metadata.
35-
{
36-
let str = ''
37-
str += `${styleText(['blue', 'bold'], 'Directory:')} ${project.rootDir}\n`
38-
if (project.type === 'with-remote-url') {
39-
str += `${styleText(['blue', 'bold'], 'Project:')} ${ansiEscapes.link(`${project.owner}/${project.name}`, `https://github.com/${project.owner}/${project.name}`)}\n`
40-
}
41-
42-
process.stdout.write(str)
43-
}
44-
45-
// TODO
46-
const skippedOrganizations = ['bash-bastion']
47-
const skippedRepositories = ['SchemaStore/schemastore']
4852
if (
49-
skippedRepositories.includes(`${project.owner}/${project.name}`) ||
50-
skippedOrganizations.includes(project.owner)
53+
project.type === 'with-remote-url' &&
54+
(globalConfig.skippedRepositories.includes(`${project.owner}/${project.name}`) ||
55+
globalConfig.skippedOrganizations.includes(project.owner))
5156
) {
5257
console.info(`[${styleText('yellow', 'SKIP')}] ${project.owner}/${project.name}`)
5358
return
@@ -80,13 +85,53 @@ export async function run(options: CommandFixOptions, positionals: string[]) {
8085
}
8186

8287
// Collect rule files that match the ecosystem.
88+
const ecosystems: string[] = []
8389
{
8490
if (await fileExists('package.json')) {
8591
await collect(`400-ecosystem/nodejs/*`)
92+
ecosystems.push('nodejs')
93+
94+
const content: PackageJson = JSON.parse(await fs.readFile('package.json', 'utf-8'))
95+
if (content.displayName) {
96+
await collect(`400-ecosystem/vscode-extension/*`)
97+
ecosystems.push('vscode-extension')
98+
}
8699
}
87100

88101
if ((await fileExists('deno.jsonc')) || (await fileExists('deno.json'))) {
89102
await collect(`400-ecosystem/deno/*`)
103+
ecosystems.push('deno')
104+
}
105+
106+
if ((await globby('*.c')).length > 0) {
107+
await collect(`400-ecosystem/c/*`)
108+
ecosystems.push('c')
109+
}
110+
111+
// https://cmake.org/cmake/help/latest/command/project.html
112+
if (await fileExists('CMakeLists.txt')) {
113+
const content = await fs.readFile('CMakeLists.txt', 'utf-8')
114+
const language: { groups?: { lang?: string } } = content.match(
115+
/project\((?:.*? (?<lang>[a-zA-Z]+)\)|.*?LANGUAGES[ \t]+(?<lang>[a-zA-Z]+))/,
116+
) as any
117+
if (language.groups?.lang === 'C') {
118+
await collect(`400-ecosystem/c/*`)
119+
ecosystems.push('c')
120+
} else if (language.groups?.lang === 'CXX') {
121+
await collect(`400-ecosystem/cpp/*`)
122+
ecosystems.push('cpp')
123+
}
124+
}
125+
126+
if (await fileExists('basalt.toml')) {
127+
await collect(`400-ecosystem/bash/*`)
128+
ecosystems.push('bash')
129+
}
130+
131+
// https://zed.dev/docs/extensions/developing-extensions
132+
if (await fileExists('extension.toml')) {
133+
await collect(`400-ecosystem/zed-extension/*`)
134+
ecosystems.push('zed-extension')
90135
}
91136

92137
await collect(`400-ecosystem/_/*`)
@@ -116,35 +161,44 @@ export async function run(options: CommandFixOptions, positionals: string[]) {
116161
}
117162
}
118163

119-
for (const fixFile of ruleFiles) {
120-
const fixId = path.basename(path.dirname(fixFile)) + '/' + path.parse(fixFile).name
121-
if (`${project.owner}/${project.name}` === 'awesome-lists/awesome-bash') {
122-
if (
123-
fixFile.includes('300-remote-url/repo-metadata') ||
124-
fixFile.includes('_/editorconfig')
125-
) {
126-
console.info(`[${styleText('yellow', 'SKIP')}] ${fixId}`)
127-
continue
128-
}
164+
// Print metadata.
165+
{
166+
let str = ''
167+
str += `${styleText(['blue', 'bold'], 'Directory:')} ${project.rootDir}\n`
168+
str += `${styleText(['blue', 'bold'], 'Ecosystems:')} ${new Intl.ListFormat().format(ecosystems)}\n`
169+
if (project.type === 'with-remote-url') {
170+
str += `${styleText(['blue', 'bold'], 'Project:')} ${ansiEscapes.link(
171+
`${project.owner}/${project.name}`,
172+
`https://github.com/${project.owner}/${project.name}`,
173+
)}\n`
129174
}
130175

176+
process.stdout.write(str)
177+
}
178+
179+
for (const fixFile of ruleFiles) {
131180
await fixFromFile(
132181
path.join(pkgRoot(), 'config/lint-rules', fixFile),
133182
project,
134183
options,
184+
config,
135185
)
136186
}
137187

138188
console.info('Done.')
139189
}
140190

141-
/**
142-
* @param {string} fixFile
143-
] * @param {Project} project
144-
* @param {CommandFixOptions} options
145-
*/
146-
async function fixFromFile(fixFile, project, options) {
147-
const fixId = path.basename(path.dirname(fixFile)) + '/' + path.parse(fixFile).name
191+
async function fixFromFile(
192+
fixFile: string,
193+
project: Project,
194+
options: CommandFixOptions,
195+
config: Config,
196+
) {
197+
const fixId = (
198+
path.basename(path.dirname(fixFile)) +
199+
'/' +
200+
path.parse(fixFile).name
201+
).replaceAll(/[0-9]+-/gu, '')
148202

149203
const module = await import(fixFile)
150204
if (!module.issues) {
@@ -160,8 +214,18 @@ async function fixFromFile(fixFile, project, options) {
160214

161215
try {
162216
let failed = false
163-
const issues = module.issues({ project })
217+
const issues: AsyncGenerator<Issue> = module.issues({ project })
164218
for await (const issue of issues) {
219+
if (issue.id) {
220+
if (`${fixId}/${issue.id}` in (config.rules ?? {})) {
221+
const rule = (config.rules ?? {})[`${fixId}/${issue.id}`]
222+
if (rule === 'off') {
223+
console.info(`[${styleText('yellow', 'SKIP')}] ${fixId}/${issue.id}`)
224+
continue
225+
}
226+
}
227+
}
228+
165229
console.info(`[EVAL] ${fixId}: Found issue`)
166230
if (Array.isArray(issue.message)) {
167231
for (const message of issue.message) {
@@ -196,7 +260,7 @@ async function fixFromFile(fixFile, project, options) {
196260
await issue.fix()
197261
} else {
198262
printWithTips(`[${styleText('red', 'FAIL')}] ${fixId}`, [
199-
'Failed because running fix function was declined',
263+
'Failed because the fix function was not executed',
200264
])
201265
failed = true
202266
break
@@ -217,10 +281,7 @@ async function fixFromFile(fixFile, project, options) {
217281
}
218282
}
219283

220-
/**
221-
* @returns {Promise<Project>}
222-
*/
223-
async function getProject() {
284+
async function getProject(): Promise<Project> {
224285
if (!(await fileExists('.git'))) {
225286
return {
226287
type: 'only-directory',

commands/new.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export async function run(values: CommandNewOptions, positionals: string[]) {
2020
name: 'value',
2121
message: 'Choose an ecosystem',
2222
choices: [
23+
{ message: 'Deno', name: 'deno' },
2324
{ message: 'NodeJS', name: 'nodejs' },
2425
{ message: 'Rust', name: 'rust' },
2526
{ message: 'Go', name: 'go' },
@@ -31,7 +32,7 @@ export async function run(values: CommandNewOptions, positionals: string[]) {
3132

3233
if (!values.templateName) {
3334
const templateData = getTemplateData()
34-
const parameters = templateData[values.ecosystem].templates
35+
const parameters = templateData[values.ecosystem]?.templates
3536
if (!parameters) {
3637
throw new Error(`Ecosystem "${values.ecosystem}" not supported`)
3738
}
@@ -121,6 +122,7 @@ export async function createProject(ctx: Context) {
121122
key: 'value',
122123
})
123124
}
125+
await fs.mkdir(path.dirname(outputFile), { recursive: true })
124126
await fs.writeFile(outputFile, outputContent)
125127
}
126128
}
@@ -129,7 +131,10 @@ export async function createProject(ctx: Context) {
129131
console.info(`Bootstrapped "${ctx.templateName}"`)
130132
}
131133

132-
function getTemplateData() {
134+
function getTemplateData(): Record<
135+
string,
136+
{ templates: Record<string, { name: string }>; onRun?: (ctx: unknown) => Promise<void> }
137+
> {
133138
return {
134139
nodejs: {
135140
templates: {
@@ -149,6 +154,13 @@ function getTemplateData() {
149154
})
150155
},
151156
},
157+
deno: {
158+
templates: {
159+
webframework: {
160+
name: 'Web Framework',
161+
},
162+
},
163+
},
152164
rust: {
153165
templates: {
154166
'hello-world': {

config/.commitlintrc.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
{
2-
"extends": [
3-
"@hyperupcall/commitlint-config"
4-
]
2+
"extends": ["@hyperupcall/commitlint-config"]
53
}

config/.ls-lint.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

config/.markdownlint.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)