| ofs | hex dump | ascii |
|---|
| 0000 | 23 21 2f 75 73 72 2f 62 69 6e 2f 65 6e 76 20 6e 6f 64 65 0a 2f 2a 0a 20 20 4d 65 72 67 65 20 61 | #!/usr/bin/env.node./*...Merge.a |
| 0020 | 6c 6c 20 4a 53 4f 4e 20 70 61 63 6b 73 20 66 72 6f 6d 20 64 61 74 61 2f 70 61 63 6b 73 2f 2a 2e | ll.JSON.packs.from.data/packs/*. |
| 0040 | 6a 73 6f 6e 20 69 6e 74 6f 20 74 65 78 74 73 2e 6a 73 6f 6e 20 61 74 20 72 65 70 6f 20 72 6f 6f | json.into.texts.json.at.repo.roo |
| 0060 | 74 2e 0a 20 20 45 61 63 68 20 70 61 63 6b 20 69 74 65 6d 3a 20 7b 20 63 61 74 65 67 6f 72 79 3a | t....Each.pack.item:.{.category: |
| 0080 | 20 73 74 72 69 6e 67 2c 20 63 6f 6e 74 65 6e 74 3a 20 73 74 72 69 6e 67 2c 20 61 74 74 72 69 62 | .string,.content:.string,.attrib |
| 00a0 | 75 74 69 6f 6e 3a 20 73 74 72 69 6e 67 20 7d 0a 2a 2f 0a 63 6f 6e 73 74 20 66 73 20 3d 20 72 65 | ution:.string.}.*/.const.fs.=.re |
| 00c0 | 71 75 69 72 65 28 27 66 73 27 29 3b 0a 63 6f 6e 73 74 20 70 61 74 68 20 3d 20 72 65 71 75 69 72 | quire('fs');.const.path.=.requir |
| 00e0 | 65 28 27 70 61 74 68 27 29 3b 0a 0a 63 6f 6e 73 74 20 52 4f 4f 54 20 3d 20 70 61 74 68 2e 72 65 | e('path');..const.ROOT.=.path.re |
| 0100 | 73 6f 6c 76 65 28 5f 5f 64 69 72 6e 61 6d 65 2c 20 27 2e 2e 27 29 3b 0a 63 6f 6e 73 74 20 50 41 | solve(__dirname,.'..');.const.PA |
| 0120 | 43 4b 53 5f 44 49 52 20 3d 20 70 61 74 68 2e 6a 6f 69 6e 28 52 4f 4f 54 2c 20 27 64 61 74 61 27 | CKS_DIR.=.path.join(ROOT,.'data' |
| 0140 | 2c 20 27 70 61 63 6b 73 27 29 3b 0a 63 6f 6e 73 74 20 4f 55 54 50 55 54 20 3d 20 70 61 74 68 2e | ,.'packs');.const.OUTPUT.=.path. |
| 0160 | 6a 6f 69 6e 28 52 4f 4f 54 2c 20 27 74 65 78 74 73 2e 6a 73 6f 6e 27 29 3b 0a 2f 2f 20 54 68 65 | join(ROOT,.'texts.json');.//.The |
| 0180 | 20 77 65 62 20 61 70 70 20 64 6f 65 73 6e 27 74 20 66 65 74 63 68 20 74 68 65 20 72 65 70 6f 2d | .web.app.doesn't.fetch.the.repo- |
| 01a0 | 72 6f 6f 74 20 66 69 6c 65 20 61 74 20 72 75 6e 74 69 6d 65 20 2d 2d 20 6d 61 69 6e 2e 6a 73 20 | root.file.at.runtime.--.main.js. |
| 01c0 | 62 75 6e 64 6c 65 73 0a 2f 2f 20 69 74 73 20 6f 77 6e 20 63 6f 70 79 20 61 74 20 77 65 62 2f 73 | bundles.//.its.own.copy.at.web/s |
| 01e0 | 72 63 2f 64 61 74 61 2f 74 65 78 74 73 2e 6a 73 6f 6e 20 2d 2d 20 73 6f 20 62 6f 74 68 20 6e 65 | rc/data/texts.json.--.so.both.ne |
| 0200 | 65 64 20 77 72 69 74 69 6e 67 20 6f 72 20 74 68 65 0a 2f 2f 20 73 69 74 65 20 6b 65 65 70 73 20 | ed.writing.or.the.//.site.keeps. |
| 0220 | 73 65 72 76 69 6e 67 20 77 68 61 74 65 76 65 72 20 77 61 73 20 74 68 65 72 65 20 62 65 66 6f 72 | serving.whatever.was.there.befor |
| 0240 | 65 20 74 68 69 73 20 6d 65 72 67 65 2e 0a 63 6f 6e 73 74 20 57 45 42 5f 4f 55 54 50 55 54 20 3d | e.this.merge..const.WEB_OUTPUT.= |
| 0260 | 20 70 61 74 68 2e 6a 6f 69 6e 28 52 4f 4f 54 2c 20 27 77 65 62 27 2c 20 27 73 72 63 27 2c 20 27 | .path.join(ROOT,.'web',.'src',.' |
| 0280 | 64 61 74 61 27 2c 20 27 74 65 78 74 73 2e 6a 73 6f 6e 27 29 3b 0a 0a 74 72 79 20 7b 0a 20 20 20 | data',.'texts.json');..try.{.... |
| 02a0 | 20 63 6f 6e 73 74 20 66 69 6c 65 73 20 3d 20 66 73 2e 65 78 69 73 74 73 53 79 6e 63 28 50 41 43 | .const.files.=.fs.existsSync(PAC |
| 02c0 | 4b 53 5f 44 49 52 29 0a 20 20 20 20 20 20 20 20 3f 20 66 73 2e 72 65 61 64 64 69 72 53 79 6e 63 | KS_DIR).........?.fs.readdirSync |
| 02e0 | 28 50 41 43 4b 53 5f 44 49 52 29 2e 66 69 6c 74 65 72 28 66 20 3d 3e 20 66 2e 65 6e 64 73 57 69 | (PACKS_DIR).filter(f.=>.f.endsWi |
| 0300 | 74 68 28 27 2e 6a 73 6f 6e 27 29 29 2e 6d 61 70 28 66 20 3d 3e 20 70 61 74 68 2e 6a 6f 69 6e 28 | th('.json')).map(f.=>.path.join( |
| 0320 | 50 41 43 4b 53 5f 44 49 52 2c 20 66 29 29 0a 20 20 20 20 20 20 20 20 3a 20 5b 5d 3b 0a 20 20 20 | PACKS_DIR,.f)).........:.[];.... |
| 0340 | 20 63 6f 6e 73 74 20 69 74 65 6d 73 20 3d 20 5b 5d 3b 0a 20 20 20 20 63 6f 6e 73 74 20 73 65 65 | .const.items.=.[];.....const.see |
| 0360 | 6e 20 3d 20 6e 65 77 20 53 65 74 28 29 3b 0a 0a 20 20 20 20 66 6f 72 20 28 63 6f 6e 73 74 20 66 | n.=.new.Set();......for.(const.f |
| 0380 | 69 6c 65 20 6f 66 20 66 69 6c 65 73 29 20 7b 0a 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 70 61 | ile.of.files).{.........const.pa |
| 03a0 | 63 6b 20 3d 20 4a 53 4f 4e 2e 70 61 72 73 65 28 66 73 2e 72 65 61 64 46 69 6c 65 53 79 6e 63 28 | ck.=.JSON.parse(fs.readFileSync( |
| 03c0 | 66 69 6c 65 2c 20 27 75 74 66 38 27 29 29 3b 0a 20 20 20 20 20 20 20 20 66 6f 72 20 28 63 6f 6e | file,.'utf8'));.........for.(con |
| 03e0 | 73 74 20 69 74 65 6d 20 6f 66 20 70 61 63 6b 29 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 69 | st.item.of.pack).{.............i |
| 0400 | 66 20 28 21 69 74 65 6d 20 7c 7c 20 21 69 74 65 6d 2e 63 6f 6e 74 65 6e 74 29 20 63 6f 6e 74 69 | f.(!item.||.!item.content).conti |
| 0420 | 6e 75 65 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 6b 65 79 20 3d 20 60 24 7b | nue;.............const.key.=.`${ |
| 0440 | 69 74 65 6d 2e 63 61 74 65 67 6f 72 79 20 7c 7c 20 27 27 7d 00 24 7b 69 74 65 6d 2e 63 6f 6e 74 | item.category.||.''}.${item.cont |
| 0460 | 65 6e 74 2e 74 72 69 6d 28 29 2e 74 6f 4c 6f 77 65 72 43 61 73 65 28 29 7d 60 3b 0a 20 20 20 20 | ent.trim().toLowerCase()}`;..... |
| 0480 | 20 20 20 20 20 20 20 20 69 66 20 28 73 65 65 6e 2e 68 61 73 28 6b 65 79 29 29 20 63 6f 6e 74 69 | ........if.(seen.has(key)).conti |
| 04a0 | 6e 75 65 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 73 65 65 6e 2e 61 64 64 28 6b 65 79 29 3b 0a | nue;.............seen.add(key);. |
| 04c0 | 20 20 20 20 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 65 6e 74 72 79 20 3d 20 7b 0a 20 20 20 20 | ............const.entry.=.{..... |
| 04e0 | 20 20 20 20 20 20 20 20 20 20 20 20 63 61 74 65 67 6f 72 79 3a 20 53 74 72 69 6e 67 28 69 74 65 | ............category:.String(ite |
| 0500 | 6d 2e 63 61 74 65 67 6f 72 79 20 7c 7c 20 27 67 65 6e 65 72 61 6c 27 29 2c 0a 20 20 20 20 20 20 | m.category.||.'general'),....... |
| 0520 | 20 20 20 20 20 20 20 20 20 20 63 6f 6e 74 65 6e 74 3a 20 53 74 72 69 6e 67 28 69 74 65 6d 2e 63 | ..........content:.String(item.c |
| 0540 | 6f 6e 74 65 6e 74 29 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 7d 3b 0a 20 20 20 20 20 20 20 20 | ontent),.............};......... |
| 0560 | 20 20 20 20 2f 2f 20 4f 6e 6c 79 20 77 68 65 6e 20 74 68 65 20 70 61 63 6b 20 61 63 74 75 61 6c | ....//.Only.when.the.pack.actual |
| 0580 | 6c 79 20 6e 61 6d 65 73 20 61 20 73 6f 75 72 63 65 2e 20 46 61 6c 6c 69 6e 67 20 62 61 63 6b 20 | ly.names.a.source..Falling.back. |
| 05a0 | 74 6f 20 74 68 65 0a 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 70 61 63 6b 27 73 20 6f 77 6e | to.the.............//.pack's.own |
| 05c0 | 20 66 69 6c 65 6e 61 6d 65 20 69 6e 76 65 6e 74 65 64 20 61 6e 20 61 74 74 72 69 62 75 74 69 6f | .filename.invented.an.attributio |
| 05e0 | 6e 20 66 6f 72 20 74 65 78 74 20 74 68 61 74 20 68 61 73 0a 20 20 20 20 20 20 20 20 20 20 20 20 | n.for.text.that.has............. |
| 0600 | 2f 2f 20 6e 6f 6e 65 20 2d 2d 20 6f 72 69 67 69 6e 61 6c 20 70 72 6f 73 65 20 69 73 20 6e 6f 74 | //.none.--.original.prose.is.not |
| 0620 | 20 61 20 71 75 6f 74 61 74 69 6f 6e 20 66 72 6f 6d 20 61 6e 79 62 6f 64 79 2e 0a 20 20 20 20 20 | .a.quotation.from.anybody....... |
| 0640 | 20 20 20 20 20 20 20 69 66 20 28 69 74 65 6d 2e 61 74 74 72 69 62 75 74 69 6f 6e 29 20 65 6e 74 | .......if.(item.attribution).ent |
| 0660 | 72 79 2e 61 74 74 72 69 62 75 74 69 6f 6e 20 3d 20 53 74 72 69 6e 67 28 69 74 65 6d 2e 61 74 74 | ry.attribution.=.String(item.att |
| 0680 | 72 69 62 75 74 69 6f 6e 29 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 50 72 6f 67 72 61 | ribution);.............//.Progra |
| 06a0 | 6d 6d 69 6e 67 20 73 6e 69 70 70 65 74 73 20 63 61 72 72 79 20 74 68 65 20 73 79 6e 74 61 78 20 | mming.snippets.carry.the.syntax. |
| 06c0 | 6c 61 6e 67 75 61 67 65 20 74 68 65 79 20 73 68 6f 75 6c 64 20 62 65 0a 20 20 20 20 20 20 20 20 | language.they.should.be......... |
| 06e0 | 20 20 20 20 2f 2f 20 68 69 67 68 6c 69 67 68 74 65 64 20 61 73 2e 20 43 61 72 72 69 65 64 20 74 | ....//.highlighted.as..Carried.t |
| 0700 | 68 72 6f 75 67 68 20 6f 6e 6c 79 20 77 68 65 6e 20 70 72 65 73 65 6e 74 2c 20 73 6f 20 65 76 65 | hrough.only.when.present,.so.eve |
| 0720 | 72 79 0a 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 6f 74 68 65 72 20 70 61 63 6b 27 73 20 69 | ry.............//.other.pack's.i |
| 0740 | 74 65 6d 73 20 6b 65 65 70 20 65 78 61 63 74 6c 79 20 74 68 65 20 73 68 61 70 65 20 74 68 65 79 | tems.keep.exactly.the.shape.they |
| 0760 | 20 68 61 64 20 62 65 66 6f 72 65 2e 0a 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 69 74 65 | .had.before..............if.(ite |
| 0780 | 6d 2e 6c 61 6e 67 75 61 67 65 29 20 65 6e 74 72 79 2e 6c 61 6e 67 75 61 67 65 20 3d 20 53 74 72 | m.language).entry.language.=.Str |
| 07a0 | 69 6e 67 28 69 74 65 6d 2e 6c 61 6e 67 75 61 67 65 29 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 | ing(item.language);............. |
| 07c0 | 2f 2f 20 57 68 61 74 20 74 68 65 20 73 6e 69 70 70 65 74 20 61 63 74 75 61 6c 6c 79 20 64 6f 65 | //.What.the.snippet.actually.doe |
| 07e0 | 73 2c 20 73 68 6f 77 6e 20 61 66 74 65 72 20 74 68 65 20 74 65 73 74 20 28 6f 72 20 64 75 72 69 | s,.shown.after.the.test.(or.duri |
| 0800 | 6e 67 0a 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 69 74 20 69 6e 20 73 69 6e 67 6c 65 20 70 | ng.............//.it.in.single.p |
| 0820 | 6c 61 79 65 72 29 2e 20 50 72 6f 67 72 61 6d 6d 69 6e 67 20 70 61 63 6b 73 20 6f 6e 6c 79 2e 0a | layer)..Programming.packs.only.. |
| 0840 | 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 69 74 65 6d 2e 65 78 70 6c 61 6e 61 74 69 6f 6e | ............if.(item.explanation |
| 0860 | 29 20 65 6e 74 72 79 2e 65 78 70 6c 61 6e 61 74 69 6f 6e 20 3d 20 53 74 72 69 6e 67 28 69 74 65 | ).entry.explanation.=.String(ite |
| 0880 | 6d 2e 65 78 70 6c 61 6e 61 74 69 6f 6e 29 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 69 74 65 6d | m.explanation);.............item |
| 08a0 | 73 2e 70 75 73 68 28 65 6e 74 72 79 29 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a 0a | s.push(entry);.........}.....}.. |
| 08c0 | 20 20 20 20 2f 2f 20 53 68 75 66 66 6c 65 0a 20 20 20 20 66 6f 72 20 28 6c 65 74 20 69 20 3d 20 | ....//.Shuffle.....for.(let.i.=. |
| 08e0 | 69 74 65 6d 73 2e 6c 65 6e 67 74 68 20 2d 20 31 3b 20 69 20 3e 20 30 3b 20 69 2d 2d 29 20 7b 0a | items.length.-.1;.i.>.0;.i--).{. |
| 0900 | 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 6a 20 3d 20 4d 61 74 68 2e 66 6c 6f 6f 72 28 4d 61 74 | ........const.j.=.Math.floor(Mat |
| 0920 | 68 2e 72 61 6e 64 6f 6d 28 29 20 2a 20 28 69 20 2b 20 31 29 29 3b 0a 20 20 20 20 20 20 20 20 5b | h.random().*.(i.+.1));.........[ |
| 0940 | 69 74 65 6d 73 5b 69 5d 2c 20 69 74 65 6d 73 5b 6a 5d 5d 20 3d 20 5b 69 74 65 6d 73 5b 6a 5d 2c | items[i],.items[j]].=.[items[j], |
| 0960 | 20 69 74 65 6d 73 5b 69 5d 5d 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 63 6f 6e 73 74 20 6a 73 6f | .items[i]];.....}......const.jso |
| 0980 | 6e 20 3d 20 4a 53 4f 4e 2e 73 74 72 69 6e 67 69 66 79 28 69 74 65 6d 73 2c 20 6e 75 6c 6c 2c 20 | n.=.JSON.stringify(items,.null,. |
| 09a0 | 32 29 3b 0a 20 20 20 20 66 73 2e 77 72 69 74 65 46 69 6c 65 53 79 6e 63 28 4f 55 54 50 55 54 2c | 2);.....fs.writeFileSync(OUTPUT, |
| 09c0 | 20 6a 73 6f 6e 29 3b 0a 20 20 20 20 66 73 2e 77 72 69 74 65 46 69 6c 65 53 79 6e 63 28 57 45 42 | .json);.....fs.writeFileSync(WEB |
| 09e0 | 5f 4f 55 54 50 55 54 2c 20 6a 73 6f 6e 29 3b 0a 20 20 20 20 63 6f 6e 73 6f 6c 65 2e 6c 6f 67 28 | _OUTPUT,.json);.....console.log( |
| 0a00 | 60 4d 65 72 67 65 64 20 24 7b 69 74 65 6d 73 2e 6c 65 6e 67 74 68 7d 20 69 74 65 6d 73 20 69 6e | `Merged.${items.length}.items.in |
| 0a20 | 74 6f 20 24 7b 4f 55 54 50 55 54 7d 20 61 6e 64 20 24 7b 57 45 42 5f 4f 55 54 50 55 54 7d 60 29 | to.${OUTPUT}.and.${WEB_OUTPUT}`) |
| 0a40 | 3b 0a 7d 20 63 61 74 63 68 20 28 65 72 72 29 20 7b 0a 20 20 20 20 63 6f 6e 73 6f 6c 65 2e 65 72 | ;.}.catch.(err).{.....console.er |
| 0a60 | 72 6f 72 28 27 6d 65 72 67 65 5f 70 61 63 6b 73 20 66 61 69 6c 65 64 3a 27 2c 20 65 72 72 29 3b | ror('merge_packs.failed:',.err); |
| 0a80 | 0a 20 20 20 20 70 72 6f 63 65 73 73 2e 65 78 69 74 28 31 29 3b 0a 7d 0a | .....process.exit(1);.}. |