Skip to content

Commit 19c477d

Browse files
committed
chore: wip
1 parent 2e915f7 commit 19c477d

File tree

9 files changed

+56
-36
lines changed

9 files changed

+56
-36
lines changed

storage/framework/core/actions/src/helpers/component-meta.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { path, frameworkPath, join, projectPath } from '@stacksjs/path'
2-
import { existsSync, glob, mkdirSync, writeFileSync } from '@stacksjs/storage'
2+
import { existsSync, globSync, mkdirSync, writeFileSync } from '@stacksjs/storage'
33
import MarkdownIt from 'markdown-it'
44
import { type ComponentMeta, type MetaCheckerOptions, createComponentMetaChecker } from 'vue-component-meta'
55

@@ -51,7 +51,7 @@ export function generateComponentMeta() {
5151
}
5252
}
5353

54-
const components = glob.sync(['components/*.stx', 'components/**/*.stx', 'components/*.vue', 'components/**/*.vue'], {
54+
const components = globSync(['components/*.stx', 'components/**/*.stx', 'components/*.vue', 'components/**/*.vue'], {
5555
cwd: projectPath(),
5656
absolute: true,
5757
})

storage/framework/core/actions/src/helpers/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { buddyOptions, runCommand, runCommands } from '@stacksjs/cli'
33
import { err } from '@stacksjs/error-handling'
44
import { log } from '@stacksjs/logging'
55
import * as p from '@stacksjs/path'
6-
import { glob } from '@stacksjs/storage'
6+
import { globSync } from '@stacksjs/storage'
77
import type { ActionOptions } from '@stacksjs/types'
88

99
type ActionPath = string // TODO: narrow this by automating its generation
@@ -105,10 +105,10 @@ export function hasAction(action: Action) {
105105
const actionPatterns = [`src/${action}.ts`, `src/${action}`, `${action}.ts`, `${action}`]
106106

107107
// Check user actions path with its specific patterns
108-
const userActionFiles = glob.sync(userActionPatterns.map((pattern) => p.userActionsPath(pattern)))
108+
const userActionFiles = globSync(userActionPatterns.map((pattern) => p.userActionsPath(pattern)))
109109

110110
// Check actions path with its specific patterns
111-
const actionFiles = glob.sync(actionPatterns.map((pattern) => p.actionsPath(pattern)))
111+
const actionFiles = globSync(actionPatterns.map((pattern) => p.actionsPath(pattern)))
112112

113113
return userActionFiles.length > 0 || actionFiles.length > 0
114114

storage/framework/core/database/src/drivers/mysql.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ok } from '@stacksjs/error-handling'
44
import { getModelName, getTableName } from '@stacksjs/orm'
55
import { fetchOtherModelRelations, getPivotTables } from '@stacksjs/orm'
66
import { path } from '@stacksjs/path'
7-
import { fs, glob } from '@stacksjs/storage'
7+
import { fs, glob, globSync } from '@stacksjs/storage'
88
import { snakeCase } from '@stacksjs/strings'
99
import type { Attribute, Attributes, Model } from '@stacksjs/types'
1010
import {
@@ -28,7 +28,7 @@ export async function resetMysqlDatabase() {
2828

2929
const files = await fs.readdir(path.userMigrationsPath())
3030
const modelFiles = await fs.readdir(path.frameworkPath('database/models'))
31-
const userModelFiles = glob.sync(path.userModelsPath('*.ts'))
31+
const userModelFiles = globSync([path.userModelsPath('*.ts')])
3232

3333
for (const userModel of userModelFiles) {
3434
const model = (await import(userModel)).default as Model
@@ -330,7 +330,7 @@ function reArrangeColumns(attributes: Attributes | undefined, tableName: string)
330330
}
331331

332332
export async function fetchMysqlTables(): Promise<string[]> {
333-
const modelFiles = glob.sync(path.userModelsPath('*.ts'))
333+
const modelFiles = globSync([path.userModelsPath('*.ts')])
334334
const tables: string[] = []
335335

336336
for (const modelPath of modelFiles) {

storage/framework/core/database/src/drivers/postgres.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ok } from '@stacksjs/error-handling'
44
import { getTableName } from '@stacksjs/orm'
55
import { fetchOtherModelRelations, getPivotTables } from '@stacksjs/orm'
66
import { path } from '@stacksjs/path'
7-
import { fs, glob } from '@stacksjs/storage'
7+
import { fs, glob, globSync } from '@stacksjs/storage'
88
import { snakeCase } from '@stacksjs/strings'
99
import type { Attribute, Attributes, Model } from '@stacksjs/types'
1010
import {
@@ -27,7 +27,7 @@ export async function resetPostgresDatabase() {
2727
const files = await fs.readdir(path.userMigrationsPath())
2828
const modelFiles = await fs.readdir(path.frameworkPath('database/models'))
2929

30-
const userModelFiles = glob.sync(path.userModelsPath('*.ts'))
30+
const userModelFiles = globSync([path.userModelsPath('*.ts')])
3131

3232
for (const userModel of userModelFiles) {
3333
const userModelPath = (await import(userModel)).default
@@ -266,7 +266,7 @@ export async function createAlterTableMigration(modelPath: string) {
266266
}
267267

268268
export async function fetchMysqlTables(): Promise<string[]> {
269-
const modelFiles = glob.sync(path.userModelsPath('*.ts'))
269+
const modelFiles = globSync([path.userModelsPath('*.ts')])
270270
const tables: string[] = []
271271

272272
for (const modelPath of modelFiles) {

storage/framework/core/database/src/drivers/sqlite.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ok } from '@stacksjs/error-handling'
44
import { getModelName, getTableName } from '@stacksjs/orm'
55
import { fetchOtherModelRelations, getPivotTables } from '@stacksjs/orm'
66
import { path } from '@stacksjs/path'
7-
import { fs, glob } from '@stacksjs/storage'
7+
import { fs, glob, globSync } from '@stacksjs/storage'
88
import { snakeCase } from '@stacksjs/strings'
99
import type { Attribute, Attributes, Model } from '@stacksjs/types'
1010
import {
@@ -26,8 +26,7 @@ export async function resetSqliteDatabase() {
2626
const files = await fs.readdir(path.userMigrationsPath())
2727
const modelFiles = await fs.readdir(path.frameworkPath('database/models'))
2828

29-
const userModelFiles = glob.sync(path.userModelsPath('*.ts'))
30-
29+
const userModelFiles = globSync([path.userModelsPath('*.ts')])
3130
for (const userModel of userModelFiles) {
3231
const userModelPath = (await import(userModel)).default
3332
const pivotTables = await getPivotTables(userModelPath, userModel)

storage/framework/core/database/src/migrations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { database } from '@stacksjs/config'
33
import { err, ok } from '@stacksjs/error-handling'
44
import { extractAttributesFromModel } from '@stacksjs/orm'
55
import { path } from '@stacksjs/path'
6-
import { fs, glob } from '@stacksjs/storage'
6+
import { fs, globSync } from '@stacksjs/storage'
77
import type { Attribute, Attributes } from '@stacksjs/types'
88
import { $ } from 'bun'
99
import { FileMigrationProvider, Migrator } from 'kysely'
@@ -84,7 +84,7 @@ export async function generateMigrations() {
8484
try {
8585
log.info('Generating migrations...')
8686

87-
const modelFiles = glob.sync(path.userModelsPath('*.ts'))
87+
const modelFiles = globSync([path.userModelsPath('*.ts')])
8888

8989
for (const file of modelFiles) {
9090
log.debug('Generating migration for:', file)

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { generator, parser, traverse } from '@stacksjs/build'
22
import { italic, log } from '@stacksjs/cli'
33
import { path } from '@stacksjs/path'
4-
import { fs, glob } from '@stacksjs/storage'
4+
import { fs, glob, globSync } from '@stacksjs/storage'
55
import { pascalCase, plural, singular, snakeCase } from '@stacksjs/strings'
66
import type {
77
Attributes,
@@ -193,7 +193,7 @@ export async function getPivotTables(
193193
}
194194

195195
export async function fetchOtherModelRelations(model: Model, modelName?: string): Promise<RelationConfig[]> {
196-
const modelFiles = glob.sync(path.userModelsPath('*.ts'))
196+
const modelFiles = globSync([path.userModelsPath('*.ts')])
197197
const modelRelations = []
198198

199199
for (let i = 0; i < modelFiles.length; i++) {
@@ -238,7 +238,7 @@ export function getFillableAttributes(attributes: Attributes | undefined): strin
238238
}
239239

240240
export async function writeModelNames() {
241-
const modelFiles = glob.sync(path.userModelsPath('*.ts'))
241+
const modelFiles = globSync([path.userModelsPath('*.ts')])
242242
let fileString = `export type ModelNames = `
243243

244244
for (let i = 0; i < modelFiles.length; i++) {
@@ -260,7 +260,7 @@ export async function writeModelNames() {
260260
}
261261

262262
export async function writeModelRequest() {
263-
const modelFiles = glob.sync(path.userModelsPath('*.ts'))
263+
const modelFiles = globSync([path.userModelsPath('*.ts')])
264264
const requestD = Bun.file(path.frameworkPath('types/requests.d.ts'))
265265

266266
let importTypes = ``
@@ -689,7 +689,7 @@ export async function deleteExistingModels(modelStringFile?: string) {
689689
return
690690
}
691691

692-
const modelPaths = glob.sync(path.frameworkPath(`orm/src/models/*.ts`)).sort() // handle them alphabetically
692+
const modelPaths = globSync([path.frameworkPath(`orm/src/models/*.ts`)].sort()) // handle them alphabetically
693693
await Promise.all(
694694
modelPaths.map(async (modelPath) => {
695695
if (fs.existsSync(modelPath)) {
@@ -711,7 +711,7 @@ export async function deleteExistingOrmActions(modelStringFile?: string) {
711711
return
712712
}
713713

714-
const ormPaths = glob.sync(path.builtUserActionsPath(`**/*.ts`))
714+
const ormPaths = globSync([path.builtUserActionsPath(`**/*.ts`)])
715715

716716
for (const ormPath of ormPaths) {
717717
if (fs.existsSync(ormPath)) await fs.promises.unlink(ormPath)
@@ -734,7 +734,7 @@ export async function deleteExistingModelRequest(modelStringFile?: string) {
734734
return
735735
}
736736

737-
const requestFiles = glob.sync(path.frameworkPath(`requests/*.ts`))
737+
const requestFiles = globSync([path.frameworkPath(`requests/*.ts`)])
738738
for (const requestFile of requestFiles) {
739739
if (fs.existsSync(requestFile)) await fs.promises.unlink(requestFile)
740740
}
@@ -746,7 +746,7 @@ export async function deleteExistingOrmRoute() {
746746
}
747747

748748
export async function generateKyselyTypes() {
749-
const modelFiles = glob.sync(path.userModelsPath('*.ts'))
749+
const modelFiles = globSync([path.userModelsPath('*.ts')])
750750
let text = ``
751751

752752
for (const modelFile of modelFiles) {
@@ -1380,7 +1380,7 @@ export async function generateModelString(
13801380
.execute();
13811381
}
13821382
1383-
1383+
13841384
${mittDeleteStatement}
13851385
}
13861386
@@ -1520,7 +1520,7 @@ export async function generateModelString(
15201520
15211521
const model = await this.find(Number(this.id))
15221522
1523-
1523+
15241524
${mittUpdateStatement}
15251525
15261526
return model
@@ -1537,7 +1537,7 @@ export async function generateModelString(
15371537
15381538
const model = await this.find(Number(this.id))
15391539
1540-
1540+
15411541
${mittUpdateStatement}
15421542
15431543
return model
@@ -1578,7 +1578,7 @@ export async function generateModelString(
15781578
.execute();
15791579
}
15801580
1581-
1581+
15821582
${mittDeleteStatement}
15831583
}
15841584
@@ -1712,7 +1712,7 @@ export async function generateModelFiles(modelStringFile?: string, options?: Gen
17121712
log.success('Wrote Model Requests')
17131713

17141714
log.info('Generating API Routes...')
1715-
const modelFiles = glob.sync(path.userModelsPath('**/*.ts'))
1715+
const modelFiles = globSync([path.userModelsPath('**/*.ts')])
17161716
await generateApiRoutes(modelFiles)
17171717
log.success('Generated API Routes')
17181718

storage/framework/core/router/src/server.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import process from 'node:process'
22
import { log } from '@stacksjs/logging'
33
import { getModelName } from '@stacksjs/orm'
44
import { path, extname } from '@stacksjs/path'
5-
import { glob } from '@stacksjs/storage'
5+
import { globSync } from '@stacksjs/storage'
66
import type { Model, Route, RouteParam, StatusCode } from '@stacksjs/types'
77
import { route } from '.'
88
import { middlewares } from './middleware'
@@ -299,8 +299,8 @@ function noCache(response: Response) {
299299
}
300300

301301
async function addRouteQuery(url: URL) {
302-
const modelFiles = glob.sync(path.userModelsPath('*.ts'))
303-
302+
// const modelFiles = globSync([path.userModelsPath('*.ts')])
303+
const modelFiles = globSync([path.userModelsPath('*.ts')])
304304
for (const modelFile of modelFiles) {
305305
const model = (await import(modelFile)).default
306306
const modelName = getModelName(model, modelFile)
@@ -317,7 +317,7 @@ async function addRouteQuery(url: URL) {
317317
}
318318

319319
async function addBody(params: any) {
320-
const modelFiles = glob.sync(path.userModelsPath('*.ts'))
320+
const modelFiles = globSync([path.userModelsPath('*.ts')])
321321

322322
for (const modelFile of modelFiles) {
323323
const model = (await import(modelFile)).default
@@ -335,7 +335,7 @@ async function addBody(params: any) {
335335
}
336336

337337
async function addRouteParam(param: RouteParam): Promise<void> {
338-
const modelFiles = glob.sync(path.userModelsPath('*.ts'))
338+
const modelFiles = globSync([path.userModelsPath('*.ts')])
339339

340340
for (const modelFile of modelFiles) {
341341
const model = (await import(modelFile)).default as Model
@@ -353,7 +353,7 @@ async function addRouteParam(param: RouteParam): Promise<void> {
353353
}
354354

355355
async function addHeaders(headers: Headers): Promise<void> {
356-
const modelFiles = glob.sync(path.userModelsPath('*.ts'))
356+
const modelFiles = globSync([path.userModelsPath('*.ts')])
357357

358358
for (const modelFile of modelFiles) {
359359
const model = (await import(modelFile)).default as Model
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,22 @@
1-
export { glob, globSync } from 'tinyglobby'
1+
import { globSync as gs } from 'tinyglobby'
2+
export { glob } from 'tinyglobby'
3+
4+
interface GlobOptions {
5+
absolute?: boolean
6+
cwd?: string
7+
patterns?: string[]
8+
ignore?: string[]
9+
dot?: boolean
10+
deep?: number
11+
expandDirectories?: boolean
12+
onlyDirectories?: boolean
13+
onlyFiles?: boolean
14+
}
15+
16+
export const globSync = (patterns: string | string[], options?: Omit<GlobOptions, 'patterns'>) => {
17+
if (typeof patterns === 'string') {
18+
return gs([patterns], options)
19+
}
20+
21+
return gs(patterns, options)
22+
}

0 commit comments

Comments
 (0)