@stacksjs/utils 0.58.72 → 0.58.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2001 -72
- package/package.json +7 -7
- package/src/find.ts +91 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.58.
|
|
4
|
+
"version": "0.58.73",
|
|
5
5
|
"description": "The Stacks helper functions.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"license": "MIT",
|
|
@@ -63,10 +63,10 @@
|
|
|
63
63
|
"@stacksjs/strings": "latest",
|
|
64
64
|
"@stacksjs/types": "latest",
|
|
65
65
|
"@types/js-yaml": "^4.0.9",
|
|
66
|
-
"@vueuse/core": "^10.
|
|
66
|
+
"@vueuse/core": "^10.8.0",
|
|
67
67
|
"@vueuse/head": "^2.0.0",
|
|
68
|
-
"@vueuse/math": "^10.
|
|
69
|
-
"@vueuse/shared": "^10.
|
|
68
|
+
"@vueuse/math": "^10.8.0",
|
|
69
|
+
"@vueuse/shared": "^10.8.0",
|
|
70
70
|
"export-size": "^0.7.0",
|
|
71
71
|
"js-yaml": "^4.1.0",
|
|
72
72
|
"rimraf": "^5.0.5",
|
|
@@ -83,10 +83,10 @@
|
|
|
83
83
|
"@stacksjs/storage": "latest",
|
|
84
84
|
"@stacksjs/strings": "latest",
|
|
85
85
|
"@stacksjs/types": "latest",
|
|
86
|
-
"@vueuse/core": "^10.
|
|
86
|
+
"@vueuse/core": "^10.8.0",
|
|
87
87
|
"@vueuse/head": "^2.0.0",
|
|
88
|
-
"@vueuse/math": "^10.
|
|
89
|
-
"@vueuse/shared": "^10.
|
|
88
|
+
"@vueuse/math": "^10.8.0",
|
|
89
|
+
"@vueuse/shared": "^10.8.0",
|
|
90
90
|
"defu": "^6.1.4",
|
|
91
91
|
"detect-indent": "^7.0.1",
|
|
92
92
|
"detect-newline": "^4.0.1",
|
package/src/find.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import os from 'node:os'
|
|
2
|
+
import fs from 'node:fs/promises'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import type { Dirent } from 'node:fs'
|
|
5
|
+
import { italic } from '@stacksjs/cli'
|
|
6
|
+
import { log } from '@stacksjs/logging'
|
|
7
|
+
|
|
8
|
+
const targetFileName = 'buddy' // The exact name of the target file
|
|
9
|
+
|
|
10
|
+
// Assuming excludePatterns is defined somewhere in your script
|
|
11
|
+
const excludePatterns = [
|
|
12
|
+
'node_modules',
|
|
13
|
+
'dist',
|
|
14
|
+
/.*out.*/,
|
|
15
|
+
`${os.homedir()}/Documents`,
|
|
16
|
+
`${os.homedir()}/Pictures`,
|
|
17
|
+
`${os.homedir()}/Library`,
|
|
18
|
+
`${os.homedir()}/.Trash`,
|
|
19
|
+
]
|
|
20
|
+
|
|
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
|
+
}
|
|
40
|
+
|
|
41
|
+
const foundProjects: string[] = []
|
|
42
|
+
|
|
43
|
+
async function searchDirectory(directory: string) {
|
|
44
|
+
if (path.basename(directory).startsWith('.'))
|
|
45
|
+
return
|
|
46
|
+
|
|
47
|
+
const isExcluded = excludePatterns.some(pattern => typeof pattern === 'string' ? directory.includes(pattern) : pattern.test(directory))
|
|
48
|
+
if (isExcluded)
|
|
49
|
+
return
|
|
50
|
+
|
|
51
|
+
let items: Dirent[]
|
|
52
|
+
try {
|
|
53
|
+
items = await fs.readdir(directory, { withFileTypes: true })
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.error(`Error reading directory ${directory}:`, error)
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let buddyFileFound = false
|
|
61
|
+
let storageDirFound = false
|
|
62
|
+
|
|
63
|
+
for (const item of items) {
|
|
64
|
+
if (item.isFile() && item.name === targetFileName) {
|
|
65
|
+
buddyFileFound = true
|
|
66
|
+
}
|
|
67
|
+
else if (item.isDirectory()) {
|
|
68
|
+
// Recursively search in directories
|
|
69
|
+
const fullPath = path.join(directory, item.name)
|
|
70
|
+
if (item.name === 'storage') {
|
|
71
|
+
// Check if the 'storage/framework/core/buddy/' structure exists within this directory
|
|
72
|
+
try {
|
|
73
|
+
const storagePath = path.join(fullPath, 'framework/core/buddy')
|
|
74
|
+
await fs.access(storagePath)
|
|
75
|
+
storageDirFound = true
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
// The specific directory structure does not exist
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
await searchDirectory(fullPath)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (buddyFileFound && storageDirFound)
|
|
86
|
+
foundProjects.push(directory) // Both conditions are met
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
await searchDirectory(dir)
|
|
90
|
+
return foundProjects
|
|
91
|
+
}
|