@putout/processor-filesystem 5.0.1 → 6.0.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/lib/filesystem.js +2 -1
- package/lib/from-simple.js +71 -0
- package/package.json +9 -8
package/lib/filesystem.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
__filesystem,
|
|
7
7
|
} from '@putout/operator-json';
|
|
8
8
|
import {isFilesystem} from './is-filesystem.cjs';
|
|
9
|
+
import {maybeFromSimple} from './from-simple.js';
|
|
9
10
|
|
|
10
11
|
export const files = [
|
|
11
12
|
'.filesystem.json',
|
|
@@ -14,7 +15,7 @@ export const files = [
|
|
|
14
15
|
export const branch = (rawSource) => {
|
|
15
16
|
filesystem.init(filesystemCLI);
|
|
16
17
|
|
|
17
|
-
const source = toJS(rawSource, __filesystem);
|
|
18
|
+
const source = toJS(maybeFromSimple(rawSource), __filesystem);
|
|
18
19
|
|
|
19
20
|
return [{
|
|
20
21
|
source,
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {dirname} from 'node:path';
|
|
2
|
+
|
|
3
|
+
const {keys} = Object;
|
|
4
|
+
const {isArray} = Array;
|
|
5
|
+
const isString = (a) => typeof a === 'string';
|
|
6
|
+
const maybeArray = (a) => isArray(a) ? a : [a];
|
|
7
|
+
|
|
8
|
+
const {stringify, parse} = JSON;
|
|
9
|
+
|
|
10
|
+
const isDir = (a) => a.endsWith('/');
|
|
11
|
+
const cutSlash = (a) => a === '/' ? a : !a.endsWith('/') ? a : a.slice(0, -1);
|
|
12
|
+
|
|
13
|
+
export const maybeFromSimple = (simple) => {
|
|
14
|
+
if (!simple.startsWith('['))
|
|
15
|
+
return simple;
|
|
16
|
+
|
|
17
|
+
const array = parse(simple);
|
|
18
|
+
|
|
19
|
+
return stringify(fromSimple(array), null, 4);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const fromSimple = (simple) => {
|
|
23
|
+
const [root, ...list] = simple;
|
|
24
|
+
const withoutSlash = cutSlash(root);
|
|
25
|
+
const rootDir = createDirectory(withoutSlash);
|
|
26
|
+
|
|
27
|
+
const directories = {
|
|
28
|
+
[withoutSlash]: rootDir,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
for (const current of list) {
|
|
32
|
+
let file;
|
|
33
|
+
const [filename, content] = maybeArray(current);
|
|
34
|
+
|
|
35
|
+
if (isDir(filename)) {
|
|
36
|
+
const withoutSlash = cutSlash(filename);
|
|
37
|
+
|
|
38
|
+
file = createDirectory(withoutSlash);
|
|
39
|
+
directories[withoutSlash] = file;
|
|
40
|
+
} else {
|
|
41
|
+
file = createFile(filename);
|
|
42
|
+
addContent(file, content);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const name = dirname(filename);
|
|
46
|
+
const currentDir = directories[name];
|
|
47
|
+
|
|
48
|
+
if (!currentDir)
|
|
49
|
+
throw Error(`☝️ Looks like directory '${name}' not found. Only: '${keys(directories)}'`);
|
|
50
|
+
|
|
51
|
+
currentDir.files.push(file);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return rootDir;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const createDirectory = (filename) => ({
|
|
58
|
+
filename: cutSlash(filename),
|
|
59
|
+
type: 'directory',
|
|
60
|
+
files: [],
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const createFile = (filename) => ({
|
|
64
|
+
filename,
|
|
65
|
+
type: 'file',
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const addContent = (file, content) => {
|
|
69
|
+
if (isString(content))
|
|
70
|
+
file.content = content;
|
|
71
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/processor-filesystem",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout processor adds ability to lint filesystem",
|
|
@@ -33,28 +33,29 @@
|
|
|
33
33
|
],
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@putout/engine-processor": "*",
|
|
36
|
-
"@putout/
|
|
36
|
+
"@putout/eslint-flat": "^3.0.0",
|
|
37
|
+
"@putout/test": "^12.0.0",
|
|
37
38
|
"c8": "^10.0.0",
|
|
38
39
|
"eslint": "^9.0.0",
|
|
39
40
|
"eslint-plugin-n": "^17.0.0",
|
|
40
|
-
"eslint-plugin-putout": "^
|
|
41
|
-
"
|
|
42
|
-
"madrun": "^10.0.0",
|
|
41
|
+
"eslint-plugin-putout": "^26.0.0",
|
|
42
|
+
"madrun": "^11.0.0",
|
|
43
43
|
"montag": "^1.2.1",
|
|
44
44
|
"nodemon": "^3.0.1",
|
|
45
45
|
"putout": "*",
|
|
46
|
-
"supertape": "^10.0.0"
|
|
46
|
+
"supertape": "^10.0.0",
|
|
47
|
+
"try-catch": "^3.0.1"
|
|
47
48
|
},
|
|
48
49
|
"license": "MIT",
|
|
49
50
|
"engines": {
|
|
50
|
-
"node": ">=
|
|
51
|
+
"node": ">=20"
|
|
51
52
|
},
|
|
52
53
|
"publishConfig": {
|
|
53
54
|
"access": "public"
|
|
54
55
|
},
|
|
55
56
|
"dependencies": {
|
|
56
57
|
"@putout/cli-filesystem": "^2.0.1",
|
|
57
|
-
"@putout/operator-filesystem": "^
|
|
58
|
+
"@putout/operator-filesystem": "^7.0.0",
|
|
58
59
|
"@putout/operator-json": "^2.0.0"
|
|
59
60
|
}
|
|
60
61
|
}
|