json-to-fs-structure 1.2.13 → 2.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.
@@ -0,0 +1,424 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const assert = __importStar(require("assert"));
37
+ const fs = __importStar(require("fs"));
38
+ const index_1 = require("../index");
39
+ describe("json-to-fs-structure", () => {
40
+ describe("jsonToFsStructure", () => {
41
+ it("should produce a simple directory with a first layer object", (done) => {
42
+ const options = {
43
+ jsonObject: {
44
+ testDirectoryField: {},
45
+ },
46
+ filePath: ".",
47
+ callback: () => {
48
+ assert.strictEqual(fs.statSync("testDirectoryField").size, 4096);
49
+ fs.rmdirSync("testDirectoryField");
50
+ done();
51
+ },
52
+ };
53
+ (0, index_1.jsonToFsStructure)(options);
54
+ });
55
+ it("should produce a simple directory with a first layer object with siblings", (done) => {
56
+ const options = {
57
+ jsonObject: {
58
+ testDirectoryField0: {},
59
+ testDirectoryField1: {},
60
+ testDirectoryField2: {},
61
+ },
62
+ filePath: ".",
63
+ callback: () => {
64
+ assert.strictEqual(fs.statSync("testDirectoryField0").size, 4096);
65
+ assert.strictEqual(fs.statSync("testDirectoryField1").size, 4096);
66
+ assert.strictEqual(fs.statSync("testDirectoryField2").size, 4096);
67
+ fs.rmdirSync("testDirectoryField0");
68
+ fs.rmdirSync("testDirectoryField1");
69
+ fs.rmdirSync("testDirectoryField2");
70
+ done();
71
+ },
72
+ };
73
+ (0, index_1.jsonToFsStructure)(options);
74
+ });
75
+ it("should produce a nested directory structure", (done) => {
76
+ const options = {
77
+ jsonObject: {
78
+ testDirectoryField3: { innerTestField: {} },
79
+ },
80
+ filePath: ".",
81
+ callback: () => {
82
+ assert.strictEqual(fs.statSync("testDirectoryField3/innerTestField").size, 4096);
83
+ fs.rmdirSync("testDirectoryField3/innerTestField");
84
+ fs.rmdirSync("testDirectoryField3");
85
+ done();
86
+ },
87
+ };
88
+ (0, index_1.jsonToFsStructure)(options);
89
+ });
90
+ it("should produce a nested directory structure when there is an array of strings", (done) => {
91
+ const options = {
92
+ jsonObject: {
93
+ testArrayField5: [
94
+ { somedir: {} },
95
+ { anotherdir: {} },
96
+ { andanotherdir: {} },
97
+ ],
98
+ },
99
+ filePath: ".",
100
+ callback: () => {
101
+ assert.strictEqual(fs.statSync("testArrayField5/somedir").size, 4096);
102
+ assert.strictEqual(fs.statSync("testArrayField5/anotherdir").size, 4096);
103
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir").size, 4096);
104
+ fs.rmdirSync("testArrayField5/somedir");
105
+ fs.rmdirSync("testArrayField5/anotherdir");
106
+ fs.rmdirSync("testArrayField5/andanotherdir");
107
+ fs.rmdirSync("testArrayField5");
108
+ done();
109
+ },
110
+ };
111
+ (0, index_1.jsonToFsStructure)(options);
112
+ });
113
+ it("should produce a nested deep complex directory structure", (done) => {
114
+ const options = {
115
+ jsonObject: {
116
+ testArrayField5: [
117
+ { somedir: {} },
118
+ { anotherdir: {} },
119
+ {
120
+ andanotherdir: {
121
+ interiorone: {
122
+ interiortwo: {
123
+ interiorthree: [{ interiorfour: {} }, { interiorfive: {} }],
124
+ },
125
+ },
126
+ },
127
+ },
128
+ ],
129
+ },
130
+ filePath: ".",
131
+ callback: () => {
132
+ assert.strictEqual(fs.statSync("testArrayField5/somedir").size, 4096);
133
+ assert.strictEqual(fs.statSync("testArrayField5/anotherdir").size, 4096);
134
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir").size, 4096);
135
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone").size, 4096);
136
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo")
137
+ .size, 4096);
138
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree").size, 4096);
139
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfour").size, 4096);
140
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfive").size, 4096);
141
+ fs.rmdirSync("testArrayField5/somedir");
142
+ fs.rmdirSync("testArrayField5/anotherdir");
143
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfive");
144
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfour");
145
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree");
146
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo");
147
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone");
148
+ fs.rmdirSync("testArrayField5/andanotherdir");
149
+ fs.rmdirSync("testArrayField5");
150
+ done();
151
+ },
152
+ };
153
+ (0, index_1.jsonToFsStructure)(options);
154
+ });
155
+ });
156
+ describe("jsonToFsWithLeafFunction", () => {
157
+ it("should produce a nested deep complex directory structure and execute the procedure on leaves", (done) => {
158
+ const endpoints = [];
159
+ const options = {
160
+ jsonObject: {
161
+ testArrayField5: [
162
+ { somedir: {} },
163
+ { anotherdir: {} },
164
+ {
165
+ andanotherdir: {
166
+ interiorone: {
167
+ interiortwo: {
168
+ interiorthree: [{ interiorfour: {} }, { interiorfive: {} }],
169
+ },
170
+ },
171
+ },
172
+ },
173
+ ],
174
+ },
175
+ filePath: ".",
176
+ leafProcedure: (filePath) => {
177
+ endpoints.push(filePath);
178
+ },
179
+ callback: () => {
180
+ assert.strictEqual(fs.statSync("testArrayField5/somedir").size, 4096);
181
+ assert.strictEqual(fs.statSync("testArrayField5/anotherdir").size, 4096);
182
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir").size, 4096);
183
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone").size, 4096);
184
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo")
185
+ .size, 4096);
186
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree").size, 4096);
187
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfour").size, 4096);
188
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfive").size, 4096);
189
+ fs.rmdirSync("testArrayField5/somedir");
190
+ fs.rmdirSync("testArrayField5/anotherdir");
191
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfive");
192
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfour");
193
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree");
194
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo");
195
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone");
196
+ fs.rmdirSync("testArrayField5/andanotherdir");
197
+ fs.rmdirSync("testArrayField5");
198
+ done();
199
+ },
200
+ };
201
+ (0, index_1.jsonToFsWithLeafFunction)(options);
202
+ expect(endpoints).toMatchSnapshot();
203
+ });
204
+ it("should produce a nested directory not past a stop word with a leaf function", (done) => {
205
+ const endpoints = [];
206
+ const options = {
207
+ jsonObject: {
208
+ testArrayField5: [
209
+ { somedir: {} },
210
+ { anotherdir: {} },
211
+ {
212
+ andanotherdir: {
213
+ interiorone: {
214
+ interiortwo: {
215
+ interiorthree: [{ interiorfour: {} }, { interiorfive: {} }],
216
+ },
217
+ },
218
+ },
219
+ },
220
+ ],
221
+ },
222
+ leafProcedure: (filePath) => {
223
+ endpoints.push(filePath);
224
+ },
225
+ filePath: ".",
226
+ callback: () => {
227
+ assert.strictEqual(fs.statSync("testArrayField5/somedir").size, 4096);
228
+ assert.strictEqual(fs.statSync("testArrayField5/anotherdir").size, 4096);
229
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir").size, 4096);
230
+ fs.rmdirSync("testArrayField5/somedir");
231
+ fs.rmdirSync("testArrayField5/anotherdir");
232
+ fs.rmdirSync("testArrayField5/andanotherdir");
233
+ fs.rmdirSync("testArrayField5");
234
+ done();
235
+ },
236
+ stopWord: "interiorone",
237
+ };
238
+ (0, index_1.jsonToFsWithLeafFunction)(options);
239
+ expect(endpoints).toMatchSnapshot();
240
+ });
241
+ });
242
+ describe("jsonToFsWithNonLeafFunction", () => {
243
+ it("should produce a nested deep complex directory structure and execute the procedure on non leaves", (done) => {
244
+ const endpoints = [];
245
+ const options = {
246
+ jsonObject: {
247
+ testArrayField5: [
248
+ { somedir: {} },
249
+ { anotherdir: {} },
250
+ {
251
+ andanotherdir: {
252
+ interiorone: {
253
+ interiortwo: {
254
+ interiorthree: [{ interiorfour: {} }, { interiorfive: {} }],
255
+ },
256
+ },
257
+ },
258
+ },
259
+ ],
260
+ },
261
+ nonLeafProcedure: (filePath) => {
262
+ endpoints.push(filePath);
263
+ },
264
+ filePath: ".",
265
+ context: {},
266
+ callback: () => {
267
+ assert.strictEqual(fs.statSync("testArrayField5/somedir").size, 4096);
268
+ assert.strictEqual(fs.statSync("testArrayField5/anotherdir").size, 4096);
269
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir").size, 4096);
270
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone").size, 4096);
271
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo")
272
+ .size, 4096);
273
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree").size, 4096);
274
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfour").size, 4096);
275
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfive").size, 4096);
276
+ fs.rmdirSync("testArrayField5/somedir");
277
+ fs.rmdirSync("testArrayField5/anotherdir");
278
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfive");
279
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfour");
280
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree");
281
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo");
282
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone");
283
+ fs.rmdirSync("testArrayField5/andanotherdir");
284
+ fs.rmdirSync("testArrayField5");
285
+ done();
286
+ },
287
+ };
288
+ (0, index_1.jsonToFsWithNonLeafFunction)(options);
289
+ expect(endpoints).toMatchSnapshot();
290
+ });
291
+ });
292
+ describe("jsonToFsWithFunction", () => {
293
+ it("should produce a nested deep complex directory structure and execute the procedure on everything", (done) => {
294
+ const endpoints = [];
295
+ const options = {
296
+ jsonObject: {
297
+ testArrayField5: [
298
+ { somedir: {} },
299
+ { anotherdir: {} },
300
+ {
301
+ andanotherdir: {
302
+ interiorone: {
303
+ interiortwo: {
304
+ interiorthree: [{ interiorfour: {} }, { interiorfive: {} }],
305
+ },
306
+ },
307
+ },
308
+ },
309
+ ],
310
+ },
311
+ procedure: (filePath) => {
312
+ endpoints.push(filePath);
313
+ },
314
+ filePath: ".",
315
+ context: {},
316
+ callback: () => {
317
+ assert.strictEqual(fs.statSync("testArrayField5/somedir").size, 4096);
318
+ assert.strictEqual(fs.statSync("testArrayField5/anotherdir").size, 4096);
319
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir").size, 4096);
320
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone").size, 4096);
321
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo")
322
+ .size, 4096);
323
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree").size, 4096);
324
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfour").size, 4096);
325
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfive").size, 4096);
326
+ fs.rmdirSync("testArrayField5/somedir");
327
+ fs.rmdirSync("testArrayField5/anotherdir");
328
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfive");
329
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfour");
330
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree");
331
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo");
332
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone");
333
+ fs.rmdirSync("testArrayField5/andanotherdir");
334
+ fs.rmdirSync("testArrayField5");
335
+ done();
336
+ },
337
+ };
338
+ (0, index_1.jsonToFsWithFunction)(options);
339
+ expect(endpoints).toMatchSnapshot();
340
+ });
341
+ it("should not go below the stop word andanotherdir provided", (done) => {
342
+ const endpoints = [];
343
+ const options = {
344
+ jsonObject: {
345
+ testArrayField5: [
346
+ { somedir: {} },
347
+ { anotherdir: {} },
348
+ {
349
+ andanotherdir: {
350
+ interiorone: {
351
+ interiortwo: {
352
+ interiorthree: [{ interiorfour: {} }, { interiorfive: {} }],
353
+ },
354
+ },
355
+ },
356
+ },
357
+ ],
358
+ },
359
+ procedure: (filePath) => {
360
+ endpoints.push(filePath);
361
+ },
362
+ filePath: ".",
363
+ context: {},
364
+ callback: () => {
365
+ assert.strictEqual(fs.statSync("testArrayField5/somedir").size, 4096);
366
+ assert.strictEqual(fs.statSync("testArrayField5/anotherdir").size, 4096);
367
+ fs.rmdirSync("testArrayField5/somedir");
368
+ fs.rmdirSync("testArrayField5/anotherdir");
369
+ fs.rmdirSync("testArrayField5");
370
+ done();
371
+ },
372
+ stopWord: "andanotherdir",
373
+ };
374
+ (0, index_1.jsonToFsWithFunction)(options);
375
+ expect(endpoints).toMatchSnapshot();
376
+ });
377
+ it("should not do anything with ignored words like meta", (done) => {
378
+ const endpoints = [];
379
+ const options = {
380
+ jsonObject: {
381
+ testArrayField5: [
382
+ { somedir: { meta: {}, apple: {} } },
383
+ { anotherdir: {} },
384
+ {
385
+ meta: { somethingweird: {} },
386
+ andanotherdir: {
387
+ interiorone: {
388
+ interiortwo: {
389
+ apple: { dontdonothing: {} },
390
+ interiorthree: [{ interiorfour: {} }, { interiorfive: {} }],
391
+ },
392
+ },
393
+ },
394
+ },
395
+ ],
396
+ },
397
+ procedure: (filePath) => {
398
+ endpoints.push(filePath);
399
+ },
400
+ filePath: ".",
401
+ context: {},
402
+ callback: () => {
403
+ assert.strictEqual(fs.statSync("testArrayField5/somedir").size, 4096);
404
+ assert.strictEqual(fs.statSync("testArrayField5/anotherdir").size, 4096);
405
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir").size, 4096);
406
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone").size, 4096);
407
+ assert.strictEqual(fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo")
408
+ .size, 4096);
409
+ fs.rmdirSync("testArrayField5/somedir");
410
+ fs.rmdirSync("testArrayField5/anotherdir");
411
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo");
412
+ fs.rmdirSync("testArrayField5/andanotherdir/interiorone");
413
+ fs.rmdirSync("testArrayField5/andanotherdir");
414
+ fs.rmdirSync("testArrayField5");
415
+ done();
416
+ },
417
+ ignoredWords: ["meta", "apple"],
418
+ stopWord: "interiorthree",
419
+ };
420
+ (0, index_1.jsonToFsWithFunction)(options);
421
+ expect(endpoints).toMatchSnapshot();
422
+ });
423
+ });
424
+ });
package/package.json CHANGED
@@ -1,10 +1,17 @@
1
1
  {
2
2
  "name": "json-to-fs-structure",
3
- "version": "1.2.13",
3
+ "version": "2.0.0",
4
4
  "description": "A simple module that takes a simple JSON file and produces the properties as a file structure in the same directory or given directory.",
5
- "main": "index.js",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
6
10
  "scripts": {
7
- "test": "jest",
11
+ "build": "tsc",
12
+ "pretest": "yarn build",
13
+ "prepublishOnly": "yarn build",
14
+ "test": "jest dist/test/index.test.js",
8
15
  "format": "yarn eslint . --fix"
9
16
  },
10
17
  "keywords": [
@@ -15,12 +22,15 @@
15
22
  "author": "eldavojohn",
16
23
  "license": "MIT",
17
24
  "devDependencies": {
18
- "eslint": "^5.11.1",
19
- "eslint-config-prettier": "^3.3.0",
20
- "eslint-plugin-prettier": "^3.0.0",
21
- "jest": "^24.8.0",
22
- "mocha": "^5.2.0",
23
- "prettier": "^1.9.2"
25
+ "@types/jest": "^30.0.0",
26
+ "@types/node": "^26.0.0",
27
+ "eslint": "^9.39.2",
28
+ "eslint-config-prettier": "^10.1.8",
29
+ "eslint-plugin-prettier": "^5.5.5",
30
+ "jest": "^30.2.0",
31
+ "mocha": "^11.7.5",
32
+ "prettier": "^3.8.1",
33
+ "typescript": "^6.0.3"
24
34
  },
25
35
  "resolutions": {
26
36
  "**/**/cryptiles": "^4.1.2",
@@ -33,5 +43,14 @@
33
43
  "repository": {
34
44
  "type": "git",
35
45
  "url": "https://github.com/eldavojohn/json-to-fs-structure.git"
46
+ },
47
+ "dependencies": {
48
+ "hoek": "^6.1.3",
49
+ "mem": "^10.0.0",
50
+ "minimist": "^1.2.3",
51
+ "npm": "^11.8.0"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
36
55
  }
37
56
  }
package/.eslintrc.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "plugins": ["prettier"],
3
- "rules": {
4
- "prettier/prettier": "error"
5
- },
6
- "extends": [
7
- "plugin:prettier/recommended"
8
- ],
9
- "env": {
10
- "es6": true,
11
- "node": true
12
- }
13
- }
@@ -1,33 +0,0 @@
1
- # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
- # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
-
4
- name: Node.js Package
5
-
6
- on:
7
- release:
8
- types: [created]
9
-
10
- jobs:
11
- build:
12
- runs-on: ubuntu-latest
13
- steps:
14
- - uses: actions/checkout@v3
15
- - uses: actions/setup-node@v3
16
- with:
17
- node-version: 16
18
- - run: npm ci
19
- - run: npm test
20
-
21
- publish-npm:
22
- needs: build
23
- runs-on: ubuntu-latest
24
- steps:
25
- - uses: actions/checkout@v3
26
- - uses: actions/setup-node@v3
27
- with:
28
- node-version: 16
29
- registry-url: https://registry.npmjs.org/
30
- - run: npm ci
31
- - run: npm publish
32
- env:
33
- NODE_AUTH_TOKEN: ${{secrets.npm_token}}
Binary file