@w5s/dev 2.1.7 → 2.2.0
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/directory.d.ts +39 -0
- package/dist/directory.d.ts.map +1 -0
- package/dist/directory.js +67 -0
- package/dist/directory.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/directory.ts +72 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface DirectoryOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Directory path
|
|
4
|
+
*/
|
|
5
|
+
readonly path: string;
|
|
6
|
+
/**
|
|
7
|
+
* Directory target state
|
|
8
|
+
*/
|
|
9
|
+
readonly state: 'present' | 'absent';
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Ensure directory is present/absent
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* await directory({
|
|
17
|
+
* path: 'foo/bar',
|
|
18
|
+
* state: 'present',
|
|
19
|
+
* })
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @param options
|
|
23
|
+
*/
|
|
24
|
+
export declare function directory(options: DirectoryOptions): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Ensure directory is present/absent
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* await directorySync({
|
|
31
|
+
* path: 'foo/bar',
|
|
32
|
+
* state: 'present',
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @param options
|
|
37
|
+
*/
|
|
38
|
+
export declare function directorySync(options: DirectoryOptions): void;
|
|
39
|
+
//# sourceMappingURL=directory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory.d.ts","sourceRoot":"","sources":["../src/directory.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,QAAQ,CAAC;CACtC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAUxE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAU7D"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.directorySync = exports.directory = void 0;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const promises_1 = require("node:fs/promises");
|
|
6
|
+
async function exists(path) {
|
|
7
|
+
try {
|
|
8
|
+
await (0, promises_1.access)(path, promises_1.constants.F_OK);
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Ensure directory is present/absent
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* await directory({
|
|
21
|
+
* path: 'foo/bar',
|
|
22
|
+
* state: 'present',
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @param options
|
|
27
|
+
*/
|
|
28
|
+
async function directory(options) {
|
|
29
|
+
const { path, state } = options;
|
|
30
|
+
const isPresent = await exists(path);
|
|
31
|
+
if (state === 'present') {
|
|
32
|
+
if (!isPresent) {
|
|
33
|
+
await (0, promises_1.mkdir)(path, { recursive: true });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (isPresent) {
|
|
37
|
+
await (0, promises_1.rmdir)(path, { recursive: true });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.directory = directory;
|
|
41
|
+
/**
|
|
42
|
+
* Ensure directory is present/absent
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* await directorySync({
|
|
47
|
+
* path: 'foo/bar',
|
|
48
|
+
* state: 'present',
|
|
49
|
+
* })
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @param options
|
|
53
|
+
*/
|
|
54
|
+
function directorySync(options) {
|
|
55
|
+
const { path, state } = options;
|
|
56
|
+
const isPresent = (0, node_fs_1.existsSync)(path);
|
|
57
|
+
if (state === 'present') {
|
|
58
|
+
if (!isPresent) {
|
|
59
|
+
(0, node_fs_1.mkdirSync)(path, { recursive: true });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else if (isPresent) {
|
|
63
|
+
(0, node_fs_1.rmdirSync)(path, { recursive: true });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.directorySync = directorySync;
|
|
67
|
+
//# sourceMappingURL=directory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory.js","sourceRoot":"","sources":["../src/directory.ts"],"names":[],"mappings":";;;AAAA,qCAA2D;AAC3D,+CAAmE;AAEnE,KAAK,UAAU,MAAM,CAAC,IAAY;IAChC,IAAI,CAAC;QACH,MAAM,IAAA,iBAAM,EAAC,IAAI,EAAE,oBAAS,CAAC,IAAI,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAaD;;;;;;;;;;;;GAYG;AACI,KAAK,UAAU,SAAS,CAAC,OAAyB;IACvD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAA,gBAAK,EAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;SAAM,IAAI,SAAS,EAAE,CAAC;QACrB,MAAM,IAAA,gBAAK,EAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACzC,CAAC;AACH,CAAC;AAVD,8BAUC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAAC,OAAyB;IACrD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,SAAS,GAAG,IAAA,oBAAU,EAAC,IAAI,CAAC,CAAC;IACnC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,IAAA,mBAAS,EAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;SAAM,IAAI,SAAS,EAAE,CAAC;QACrB,IAAA,mBAAS,EAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC;AACH,CAAC;AAVD,sCAUC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./directory.js"), exports);
|
|
17
18
|
__exportStar(require("./eslint.js"), exports);
|
|
18
19
|
__exportStar(require("./block.js"), exports);
|
|
19
20
|
__exportStar(require("./file.js"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,6CAA2B;AAC3B,4CAA0B;AAC1B,4CAA0B;AAC1B,+CAA6B;AAC7B,qDAAmC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,8CAA4B;AAC5B,6CAA2B;AAC3B,4CAA0B;AAC1B,4CAA0B;AAC1B,+CAA6B;AAC7B,qDAAmC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@w5s/dev",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Shared development constants and functions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"config",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "83fd8a5230a660921d5c785190b58f38a1d3cdb0"
|
|
48
48
|
}
|
package/src/directory.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, rmdirSync } from 'node:fs';
|
|
2
|
+
import { access, constants, mkdir, rmdir } from 'node:fs/promises';
|
|
3
|
+
|
|
4
|
+
async function exists(path: string) {
|
|
5
|
+
try {
|
|
6
|
+
await access(path, constants.F_OK);
|
|
7
|
+
return true;
|
|
8
|
+
} catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface DirectoryOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Directory path
|
|
16
|
+
*/
|
|
17
|
+
readonly path: string;
|
|
18
|
+
/**
|
|
19
|
+
* Directory target state
|
|
20
|
+
*/
|
|
21
|
+
readonly state: 'present' | 'absent';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Ensure directory is present/absent
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* await directory({
|
|
30
|
+
* path: 'foo/bar',
|
|
31
|
+
* state: 'present',
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @param options
|
|
36
|
+
*/
|
|
37
|
+
export async function directory(options: DirectoryOptions): Promise<void> {
|
|
38
|
+
const { path, state } = options;
|
|
39
|
+
const isPresent = await exists(path);
|
|
40
|
+
if (state === 'present') {
|
|
41
|
+
if (!isPresent) {
|
|
42
|
+
await mkdir(path, { recursive: true });
|
|
43
|
+
}
|
|
44
|
+
} else if (isPresent) {
|
|
45
|
+
await rmdir(path, { recursive: true });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Ensure directory is present/absent
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* await directorySync({
|
|
55
|
+
* path: 'foo/bar',
|
|
56
|
+
* state: 'present',
|
|
57
|
+
* })
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @param options
|
|
61
|
+
*/
|
|
62
|
+
export function directorySync(options: DirectoryOptions): void {
|
|
63
|
+
const { path, state } = options;
|
|
64
|
+
const isPresent = existsSync(path);
|
|
65
|
+
if (state === 'present') {
|
|
66
|
+
if (!isPresent) {
|
|
67
|
+
mkdirSync(path, { recursive: true });
|
|
68
|
+
}
|
|
69
|
+
} else if (isPresent) {
|
|
70
|
+
rmdirSync(path, { recursive: true });
|
|
71
|
+
}
|
|
72
|
+
}
|
package/src/index.ts
CHANGED