Skip to content

Commit 200ac8f

Browse files
committed
chore: wip
1 parent a406f4d commit 200ac8f

File tree

3 files changed

+51
-69
lines changed

3 files changed

+51
-69
lines changed

storage/framework/core/actions/src/find-projects.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import os from 'node:os'
21
import process from 'node:process'
32
import { findStacksProjects } from '@stacksjs/utils'
43
import { log } from '@stacksjs/logging'
54

6-
const startDirectory = os.homedir()
7-
85
try {
9-
// Usage example, assuming log is defined and works similarly to console
10-
const projects = await findStacksProjects(startDirectory)
6+
const projects = await findStacksProjects()
117

128
if (projects.length > 0) {
139
log.info('Found Projects:')
Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,43 @@
1-
// checks for all of the Stacks projects on the system
2-
// and generates one caddyfile for it all
3-
4-
// stacksjs.localhost {
5-
// route {
6-
// @libs {
7-
// path /libs/*
8-
// }
9-
10-
// handle @libs {
11-
// reverse_proxy localhost:3003
12-
// }
13-
14-
// @api {
15-
// path /api/*
16-
// }
17-
18-
// handle @api {
19-
// reverse_proxy localhost:3999
20-
// }
21-
22-
// handle {
23-
// reverse_proxy localhost:3000
24-
// }
25-
// }
26-
// }
27-
28-
import { readdir } from 'node:fs/promises'
29-
import { path as p } from '@stacksjs/path'
1+
import os from 'node:os'
302
import { logger } from '@stacksjs/logging'
31-
import { storage } from '@stacksjs/storage'
32-
import { findProjects } from '@stacksjs/buddy'
3+
import { findStacksProjects } from '@stacksjs/utils'
334

345
logger.log('Generating Local Reverse Proxy...')
356

36-
const projects = await findProjects()
7+
const options = { quiet: true }
8+
const projects = await findStacksProjects(os.homedir(), options)
9+
10+
// TODO: need to generate one caddyfile that can be used for all projects on the system (each projects gets its own *.localhost domain)
11+
// TODO: need to create a watcher
12+
// TODO: need to create an action that can be run to add a new project
13+
// TODO: need to an action that checks whether there are an env port clashes aross projects
3714

38-
const caddyfile = `stacksjs.localhost {
39-
route {
40-
@
15+
console.log(projects)
4116

42-
@libs {
43-
path /libs/*
44-
}
17+
// const caddyfile = `stacksjs.localhost {
18+
// route {
19+
// @
4520

46-
handle @libs {
47-
reverse_proxy localhost:3003
48-
}
21+
// @libs {
22+
// path /libs/*
23+
// }
4924

50-
@api {
51-
path /api/*
52-
}
25+
// handle @libs {
26+
// reverse_proxy localhost:3003
27+
// }
5328

54-
handle @api {
55-
reverse_proxy localhost:3999
56-
}
29+
// @api {
30+
// path /api/*
31+
// }
5732

33+
// handle @api {
34+
// reverse_proxy localhost:3999
35+
// }
5836

59-
handle {
60-
reverse_proxy localhost:3000
61-
}
62-
}
63-
}`
37+
// handle {
38+
// reverse_proxy localhost:3000
39+
// }
40+
// }
41+
// }`
6442

65-
await storage.writeFile(p.frameworkPath('types/actions.d.ts'), caddyfile)
43+
// await storage.writeFile(p.frameworkPath('types/actions.d.ts'), caddyfile)

storage/framework/core/utils/src/find.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,25 @@ const excludePatterns = [
1818
`${os.homedir()}/.Trash`,
1919
]
2020

21-
export async function findStacksProjects(dir: string): Promise<string[]> {
22-
log.info(`This may take a few moments, searching for Stacks projects in: ${italic(dir)}`)
23-
// eslint-disable-next-line no-console
24-
console.log('')
25-
// eslint-disable-next-line no-console
26-
console.log(italic(' Please note, while Stacks is searching for projects on your machine,'))
27-
// eslint-disable-next-line no-console
28-
console.log(italic(' you may be asked for permissions to scan certain directories.'))
29-
// eslint-disable-next-line no-console
30-
console.log('')
31-
log.debug(`Excluding directories: ${excludePatterns.join(', ')}`)
21+
interface FindStacksProjectsOptions {
22+
quiet?: boolean
23+
}
24+
25+
export async function findStacksProjects(dir?: string, options?: FindStacksProjectsOptions): Promise<string[]> {
26+
dir = dir || os.homedir()
27+
28+
if (!options?.quiet) {
29+
log.info(`This may take a few moments, searching for Stacks projects in: ${italic(dir)}`)
30+
// eslint-disable-next-line no-console
31+
console.log('')
32+
// eslint-disable-next-line no-console
33+
console.log(italic(' Please note, while Stacks is searching for projects on your machine,'))
34+
// eslint-disable-next-line no-console
35+
console.log(italic(' you may be asked for permissions to scan certain directories.'))
36+
// eslint-disable-next-line no-console
37+
console.log('')
38+
log.debug(`Excluding directories: ${excludePatterns.join(', ')}`)
39+
}
3240

3341
const foundProjects: string[] = []
3442

0 commit comments

Comments
 (0)