-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #311 from elsoul/cli
update get dirs
- Loading branch information
Showing
10 changed files
with
70 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
import { mkdir, readdir } from 'fs/promises' | ||
import path from 'path' | ||
import { sortDirsByLastModified } from './sortDirsByLastModified' | ||
|
||
export const getFunctions = async () => { | ||
const functionsDir = path.join(process.cwd(), 'functions') | ||
if (!functionsDir) { | ||
await mkdir(functionsDir, { recursive: true }) | ||
try { | ||
const dir = path.join(process.cwd(), 'functions') | ||
if (!dir) { | ||
await mkdir(dir, { recursive: true }) | ||
} | ||
const sqlDirs = (await readdir(dir)).map((dirName) => | ||
path.join(dir, dirName), | ||
) | ||
const result = await sortDirsByLastModified(sqlDirs) | ||
return result | ||
} catch (error) { | ||
console.log('getFunctions:', error) | ||
return [''] | ||
} | ||
console.log(functionsDir) | ||
const functions = await readdir(functionsDir) | ||
return functions | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
import { mkdir, readdir } from 'fs/promises' | ||
import path from 'path' | ||
import { sortDirsByLastModified } from './sortDirsByLastModified' | ||
|
||
export const getSQLs = async () => { | ||
const dir = path.join(process.cwd(), 'sql') | ||
if (!dir) { | ||
await mkdir(dir, { recursive: true }) | ||
try { | ||
const dir = path.join(process.cwd(), 'sql') | ||
if (!dir) { | ||
await mkdir(dir, { recursive: true }) | ||
} | ||
const sqlDirs = (await readdir(dir)).map((dirName) => | ||
path.join(dir, dirName), | ||
) | ||
const result = await sortDirsByLastModified(sqlDirs) | ||
return result | ||
} catch (error) { | ||
console.log('Error getting SQL directories:', error) | ||
return [''] | ||
} | ||
console.log(dir) | ||
const apps = await readdir(dir) | ||
return apps | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { getDirectoryLastModified } from './getDirectoryLastModified' | ||
|
||
export const sortDirsByLastModified = async (dirs: string[]) => { | ||
const dirsWithStats = [] | ||
for await (const dir of dirs) { | ||
const lastModified = await getDirectoryLastModified(dir) | ||
dirsWithStats.push({ name: dir, mtime: lastModified }) | ||
} | ||
|
||
// Sort by last modified date | ||
dirsWithStats.sort((a, b) => b.mtime.getTime() - a.mtime.getTime()) | ||
const dirNames = dirsWithStats.map((dir) => dir.name.split('/').pop()) | ||
return dirNames as string[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.