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