@tmlmobilidade/go-utils-fs 20260914.1727.46

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.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Returns a list of all the files inside a directory and its subdirectories recursively.
3
+ * @param dirPath The path to the directory to get the files from.
4
+ * @returns A list of all the files inside the directory and its subdirectories recursively.
5
+ */
6
+ export declare function getDirectoryFiles(dirPath: string): string[];
@@ -0,0 +1,37 @@
1
+ /* * */
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ /**
5
+ * Returns a list of all the files inside a directory and its subdirectories recursively.
6
+ * @param dirPath The path to the directory to get the files from.
7
+ * @returns A list of all the files inside the directory and its subdirectories recursively.
8
+ */
9
+ export function getDirectoryFiles(dirPath) {
10
+ //
11
+ //
12
+ // Read the directory contents.
13
+ const dirEntries = fs.readdirSync(dirPath, { withFileTypes: true });
14
+ //
15
+ // Initialize the list of files.
16
+ const dirFiles = [];
17
+ for (const entry of dirEntries) {
18
+ // Get the path to the entry.
19
+ const entryPath = path.join(dirPath, entry.name);
20
+ // If the entry is a directory, recursively get
21
+ // the files in the subdirectory.
22
+ if (entry.isDirectory()) {
23
+ const subdirFiles = getDirectoryFiles(entryPath);
24
+ dirFiles.push(...subdirFiles);
25
+ continue;
26
+ }
27
+ // Add the path to the list of files.
28
+ if (entry.isFile()) {
29
+ dirFiles.push(entryPath);
30
+ }
31
+ }
32
+ //
33
+ // Sort and return the list of files in the directory
34
+ // and its subdirectories.
35
+ const sortedDirFiles = dirFiles.sort((a, b) => a.localeCompare(b));
36
+ return sortedDirFiles;
37
+ }
@@ -0,0 +1,2 @@
1
+ export * from './get-directory-files.js';
2
+ export * from './set-directory-permissions.js';
@@ -0,0 +1,2 @@
1
+ export * from './get-directory-files.js';
2
+ export * from './set-directory-permissions.js';
@@ -0,0 +1,7 @@
1
+ import fs from 'node:fs';
2
+ /**
3
+ * Sets the permissions of a directory and all its files using `chmod` recursively.
4
+ * @param dirPath The path to the directory to set the permissions of.
5
+ * @param mode The mode to set the permissions of the directory and all its files to.
6
+ */
7
+ export declare function setDirectoryPermissions(dirPath: string, mode: fs.Mode): void;
@@ -0,0 +1,19 @@
1
+ /* * */
2
+ import fs from 'node:fs';
3
+ /**
4
+ * Sets the permissions of a directory and all its files using `chmod` recursively.
5
+ * @param dirPath The path to the directory to set the permissions of.
6
+ * @param mode The mode to set the permissions of the directory and all its files to.
7
+ */
8
+ export function setDirectoryPermissions(dirPath, mode) {
9
+ const files = fs.readdirSync(dirPath, { withFileTypes: true });
10
+ for (const file of files) {
11
+ const filePath = `${dirPath}/${file.name}`;
12
+ if (file.isDirectory()) {
13
+ setDirectoryPermissions(filePath, mode);
14
+ }
15
+ else {
16
+ fs.chmodSync(filePath, mode);
17
+ }
18
+ }
19
+ }
@@ -0,0 +1 @@
1
+ export * from './directories/index.js';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './directories/index.js';
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@tmlmobilidade/go-utils-fs",
3
+ "version": "20260914.1727.46",
4
+ "author": {
5
+ "email": "iso@tmlmobilidade.pt",
6
+ "name": "TML-ISO"
7
+ },
8
+ "license": "AGPL-3.0-or-later",
9
+ "homepage": "https://go.tmlmobilidade.pt",
10
+ "bugs": {
11
+ "url": "https://github.com/tmlmobilidade/go/issues"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/tmlmobilidade/go.git"
16
+ },
17
+ "keywords": [
18
+ "public transit",
19
+ "tml",
20
+ "transportes metropolitanos de lisboa",
21
+ "go"
22
+ ],
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "type": "module",
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "main": "./dist/index.js",
31
+ "types": "./dist/index.d.ts",
32
+ "scripts": {
33
+ "build": "tsc && resolve-tspaths",
34
+ "lint": "eslint ./src/ && tsc --noEmit",
35
+ "lint:fix": "eslint ./src/ --fix",
36
+ "watch": "tsc-watch --onSuccess 'resolve-tspaths'"
37
+ },
38
+ "devDependencies": {
39
+ "@tmlmobilidade/go-utils-tsconfig": "*",
40
+ "@types/node": "26.4.0",
41
+ "resolve-tspaths": "0.8.23",
42
+ "tsc-watch": "7.2.1",
43
+ "typescript": "6.0.3"
44
+ }
45
+ }