@stacksjs/storage 0.56.34 → 0.57.2
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.d.ts +21 -23
- package/dist/index.mjs +24 -27
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,47 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
import { JsonFile,
|
|
3
|
-
|
|
4
|
-
declare const _dirname: string;
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import type { JsonFile, TextFile } from '@stacksjs/types';
|
|
3
|
+
export declare const _dirname: any;
|
|
5
4
|
/**
|
|
6
5
|
* Reads a JSON file and returns the parsed data.
|
|
7
6
|
*/
|
|
8
|
-
declare function readJsonFile(name: string, cwd?: string): Promise<JsonFile>;
|
|
7
|
+
export declare function readJsonFile(name: string, cwd?: string): Promise<JsonFile>;
|
|
9
8
|
/**
|
|
10
9
|
* Reads a package.json file and returns the parsed data.
|
|
11
10
|
*/
|
|
12
|
-
declare function readPackageJson(name: string, cwd?: string): Promise<PackageJson>;
|
|
11
|
+
export declare function readPackageJson(name: string, cwd?: string): Promise<PackageJson>;
|
|
13
12
|
/**
|
|
14
13
|
* Writes the given data to the specified JSON file.
|
|
15
14
|
*/
|
|
16
|
-
declare function writeJsonFile(file: JsonFile): Promise<void>;
|
|
15
|
+
export declare function writeJsonFile(file: JsonFile): Promise<void>;
|
|
17
16
|
/**
|
|
18
17
|
* Reads a text file and returns its contents.
|
|
19
18
|
*/
|
|
20
|
-
declare function readTextFile(name: string, cwd?: string): Promise<TextFile>;
|
|
19
|
+
export declare function readTextFile(name: string, cwd?: string): Promise<TextFile>;
|
|
21
20
|
/**
|
|
22
21
|
* Writes the given text to the specified file.
|
|
23
22
|
*/
|
|
24
|
-
declare function writeTextFile(file: TextFile): Promise<void>;
|
|
23
|
+
export declare function writeTextFile(file: TextFile): Promise<void>;
|
|
25
24
|
/**
|
|
26
25
|
* Determine whether a path is a folder.
|
|
27
26
|
*/
|
|
28
|
-
declare function isFolder(path: string): boolean;
|
|
27
|
+
export declare function isFolder(path: string): boolean;
|
|
29
28
|
/**
|
|
30
29
|
* Determine whether a path is a file.
|
|
31
30
|
*/
|
|
32
|
-
declare function isFile(path: string): boolean;
|
|
31
|
+
export declare function isFile(path: string): boolean;
|
|
33
32
|
/**
|
|
34
33
|
* Determine whether a folder has any files in it.
|
|
35
34
|
*/
|
|
36
|
-
declare function hasFiles(folder: string): boolean;
|
|
37
|
-
declare function hasComponents(): boolean;
|
|
38
|
-
declare function hasFunctions(): boolean;
|
|
39
|
-
declare function copyFolder(src: string, dest: string, exclude?: string[]): void;
|
|
40
|
-
declare function deleteFolder(path: string): Promise<void>;
|
|
41
|
-
declare function deleteFiles(dir: string, exclude?: string[]): void;
|
|
42
|
-
declare function deleteEmptyFolders(dir: string): void;
|
|
43
|
-
declare function doesFolderExist(path: string):
|
|
44
|
-
declare function createFolder(dir: string): Promise<void>;
|
|
45
|
-
declare function updateConfigFile(filePath: string, newConfig: Record<string, unknown>): Promise<void>;
|
|
46
|
-
|
|
47
|
-
export { _dirname, copyFolder, createFolder, deleteEmptyFolders, deleteFiles, deleteFolder, doesFolderExist, hasComponents, hasFiles, hasFunctions, isFile, isFolder, readJsonFile, readPackageJson, readTextFile, updateConfigFile, writeJsonFile, writeTextFile };
|
|
35
|
+
export declare function hasFiles(folder: string): boolean;
|
|
36
|
+
export declare function hasComponents(): boolean;
|
|
37
|
+
export declare function hasFunctions(): boolean;
|
|
38
|
+
export declare function copyFolder(src: string, dest: string, exclude?: string[]): void;
|
|
39
|
+
export declare function deleteFolder(path: string): Promise<void>;
|
|
40
|
+
export declare function deleteFiles(dir: string, exclude?: string[]): void;
|
|
41
|
+
export declare function deleteEmptyFolders(dir: string): void;
|
|
42
|
+
export declare function doesFolderExist(path: string): any;
|
|
43
|
+
export declare function createFolder(dir: string): Promise<void>;
|
|
44
|
+
export declare function updateConfigFile(filePath: string, newConfig: Record<string, unknown>): Promise<void>;
|
|
45
|
+
export { fs };
|
package/dist/index.mjs
CHANGED
|
@@ -1,30 +1,28 @@
|
|
|
1
|
-
import { fileURLToPath } from
|
|
2
|
-
import fs from
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const _dirname = typeof __dirname !== "undefined" ? __dirname : dirname(fileURLToPath(import.meta.url));
|
|
9
|
-
async function readJsonFile(name, cwd) {
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import { detectIndent, detectNewline } from "@stacksjs/strings";
|
|
4
|
+
import { componentsPath, dirname, functionsPath, join, projectPath } from "@stacksjs/path";
|
|
5
|
+
import { contains } from "@stacksjs/arrays";
|
|
6
|
+
export const _dirname = typeof __dirname !== "undefined" ? __dirname : dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
export async function readJsonFile(name, cwd) {
|
|
10
8
|
const file = await readTextFile(name, cwd);
|
|
11
9
|
const data = JSON.parse(file.data);
|
|
12
10
|
const indent = detectIndent(file.data).indent;
|
|
13
11
|
const newline = detectNewline(file.data);
|
|
14
12
|
return { ...file, data, indent, newline };
|
|
15
13
|
}
|
|
16
|
-
async function readPackageJson(name, cwd) {
|
|
14
|
+
export async function readPackageJson(name, cwd) {
|
|
17
15
|
const file = await readJsonFile(name, cwd);
|
|
18
16
|
const data = file.data;
|
|
19
17
|
return data;
|
|
20
18
|
}
|
|
21
|
-
async function writeJsonFile(file) {
|
|
19
|
+
export async function writeJsonFile(file) {
|
|
22
20
|
let json = JSON.stringify(file.data, void 0, file.indent);
|
|
23
21
|
if (file.newline)
|
|
24
22
|
json += file.newline;
|
|
25
23
|
return writeTextFile({ ...file, data: json });
|
|
26
24
|
}
|
|
27
|
-
function readTextFile(name, cwd) {
|
|
25
|
+
export function readTextFile(name, cwd) {
|
|
28
26
|
return new Promise((resolve, reject) => {
|
|
29
27
|
let filePath;
|
|
30
28
|
if (cwd)
|
|
@@ -43,7 +41,7 @@ function readTextFile(name, cwd) {
|
|
|
43
41
|
});
|
|
44
42
|
});
|
|
45
43
|
}
|
|
46
|
-
function writeTextFile(file) {
|
|
44
|
+
export function writeTextFile(file) {
|
|
47
45
|
return new Promise((resolve, reject) => {
|
|
48
46
|
fs.writeFile(file.path, file.data, (err) => {
|
|
49
47
|
if (err)
|
|
@@ -53,26 +51,26 @@ function writeTextFile(file) {
|
|
|
53
51
|
});
|
|
54
52
|
});
|
|
55
53
|
}
|
|
56
|
-
function isFolder(path) {
|
|
54
|
+
export function isFolder(path) {
|
|
57
55
|
try {
|
|
58
56
|
return fs.statSync(path).isDirectory();
|
|
59
57
|
} catch {
|
|
60
58
|
return false;
|
|
61
59
|
}
|
|
62
60
|
}
|
|
63
|
-
function isFile(path) {
|
|
61
|
+
export function isFile(path) {
|
|
64
62
|
return fs.existsSync(projectPath(path));
|
|
65
63
|
}
|
|
66
|
-
function hasFiles(folder) {
|
|
64
|
+
export function hasFiles(folder) {
|
|
67
65
|
return fs.readdirSync(folder).length > 0;
|
|
68
66
|
}
|
|
69
|
-
function hasComponents() {
|
|
67
|
+
export function hasComponents() {
|
|
70
68
|
return hasFiles(componentsPath());
|
|
71
69
|
}
|
|
72
|
-
function hasFunctions() {
|
|
70
|
+
export function hasFunctions() {
|
|
73
71
|
return hasFiles(functionsPath());
|
|
74
72
|
}
|
|
75
|
-
function copyFolder(src, dest, exclude = []) {
|
|
73
|
+
export function copyFolder(src, dest, exclude = []) {
|
|
76
74
|
if (!fs.existsSync(dest))
|
|
77
75
|
fs.mkdirSync(dest, { recursive: true });
|
|
78
76
|
if (fs.existsSync(src)) {
|
|
@@ -88,11 +86,11 @@ function copyFolder(src, dest, exclude = []) {
|
|
|
88
86
|
});
|
|
89
87
|
}
|
|
90
88
|
}
|
|
91
|
-
async function deleteFolder(path) {
|
|
89
|
+
export async function deleteFolder(path) {
|
|
92
90
|
if (fs.statSync(path).isDirectory())
|
|
93
91
|
await fs.rmSync(path, { recursive: true, force: true });
|
|
94
92
|
}
|
|
95
|
-
function deleteFiles(dir, exclude = []) {
|
|
93
|
+
export function deleteFiles(dir, exclude = []) {
|
|
96
94
|
if (fs.existsSync(dir)) {
|
|
97
95
|
fs.readdirSync(dir).forEach((file) => {
|
|
98
96
|
const p = join(dir, file);
|
|
@@ -107,7 +105,7 @@ function deleteFiles(dir, exclude = []) {
|
|
|
107
105
|
});
|
|
108
106
|
}
|
|
109
107
|
}
|
|
110
|
-
function deleteEmptyFolders(dir) {
|
|
108
|
+
export function deleteEmptyFolders(dir) {
|
|
111
109
|
if (fs.existsSync(dir)) {
|
|
112
110
|
fs.readdirSync(dir).forEach((file) => {
|
|
113
111
|
const p = join(dir, file);
|
|
@@ -120,10 +118,10 @@ function deleteEmptyFolders(dir) {
|
|
|
120
118
|
});
|
|
121
119
|
}
|
|
122
120
|
}
|
|
123
|
-
function doesFolderExist(path) {
|
|
121
|
+
export function doesFolderExist(path) {
|
|
124
122
|
return fs.existsSync(path);
|
|
125
123
|
}
|
|
126
|
-
function createFolder(dir) {
|
|
124
|
+
export function createFolder(dir) {
|
|
127
125
|
return new Promise((resolve, reject) => {
|
|
128
126
|
fs.mkdirs(dir, (err) => {
|
|
129
127
|
if (err)
|
|
@@ -133,7 +131,7 @@ function createFolder(dir) {
|
|
|
133
131
|
});
|
|
134
132
|
});
|
|
135
133
|
}
|
|
136
|
-
function updateConfigFile(filePath, newConfig) {
|
|
134
|
+
export function updateConfigFile(filePath, newConfig) {
|
|
137
135
|
return new Promise((resolve, reject) => {
|
|
138
136
|
const config = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
139
137
|
for (const key in newConfig) {
|
|
@@ -143,5 +141,4 @@ function updateConfigFile(filePath, newConfig) {
|
|
|
143
141
|
resolve();
|
|
144
142
|
});
|
|
145
143
|
}
|
|
146
|
-
|
|
147
|
-
export { _dirname, copyFolder, createFolder, deleteEmptyFolders, deleteFiles, deleteFolder, doesFolderExist, hasComponents, hasFiles, hasFunctions, isFile, isFolder, readJsonFile, readPackageJson, readTextFile, updateConfigFile, writeJsonFile, writeTextFile };
|
|
144
|
+
export { fs };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/storage",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.57.2",
|
|
5
5
|
"packageManager": "pnpm@8.6.5",
|
|
6
6
|
"description": "The Stacks file system.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
@@ -44,13 +44,13 @@
|
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"fs-extra": "^11.1.1",
|
|
46
46
|
"unstorage": "^1.7.0",
|
|
47
|
-
"@stacksjs/arrays": "0.
|
|
48
|
-
"@stacksjs/path": "0.
|
|
49
|
-
"@stacksjs/types": "0.
|
|
50
|
-
"@stacksjs/strings": "0.
|
|
47
|
+
"@stacksjs/arrays": "0.57.2",
|
|
48
|
+
"@stacksjs/path": "0.57.2",
|
|
49
|
+
"@stacksjs/types": "0.57.2",
|
|
50
|
+
"@stacksjs/strings": "0.57.2"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@stacksjs/development": "0.
|
|
53
|
+
"@stacksjs/development": "0.57.2"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"build": "unbuild",
|