-
Notifications
You must be signed in to change notification settings - Fork 4
/
emk.js
1050 lines (885 loc) · 24 KB
/
emk.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const fs = require('fs');
const path = require('path');
const url = require('url').URL;
const jmacs = require('jmacs');
const detective = require('detective');
const h_package_tree = require('./emk/aux/package-tree.js');
const {
packages: h_content_packages,
modes: h_content_modes,
} = require('./emk/aux/content.js');
const s_super = process.env.GRAPHY_CHANNEL || 'graphy';
const g_package_json_super = require('./package.json');
const P_PACKAGE_JSON_BASE = `./emk/aux/base-package-${s_super}.json`;
const g_package_json_base = require(P_PACKAGE_JSON_BASE);
const s_base_version = g_package_json_base.version;
// const s_base_version = g_package_json_super.version;
const s_semver = `^${s_base_version}`;
const P_PACKAGE_PREFIX = process.env.GRAPHY_PACKAGE_PREFIX || '.npm-packages';
let a_link_selected = [];
const dir_struct = (a_files) => {
let a_paths = [];
for(let z_file of a_files) {
if('string' === typeof z_file) {
a_paths.push(z_file);
}
else {
for(let s_dir in z_file) {
a_paths.push(...dir_struct(z_file[s_dir]).map(s => `${s_dir}/${s}`));
}
}
}
return a_paths;
};
const files = (g_config={}, pd_rel=null) => {
// accumulate results
let a_outputs = [];
// recurse on this directory
if(g_config.under) {
let p_pwd = g_config.under;
pd_rel = pd_rel || p_pwd;
// filter
let f_filter = g_config.filter || (() => true);
// map
let f_map = g_config.map || (s => s);
// each file under directory
for(let s_file of fs.readdirSync(p_pwd)) {
let p_file = `${p_pwd}/${s_file}`;
// stat file
let d_stat = fs.statSync(p_file);
// subdirectory
if(d_stat.isDirectory()) {
a_outputs.push(...files({
...g_config,
under: p_file,
}, pd_rel));
}
// file; filter, then map
else if(f_filter(path.relative(pd_rel, p_file))) {
a_outputs.push(f_map(path.relative(pd_rel, p_file)));
}
}
}
// bad input
else {
throw new TypeError(`expected 'under' key in files args struct`);
}
return a_outputs;
};
// for run commands to lint js files
const eslint = (sx_more='') => /* syntax: bash */ `
npx eslint --fix --color --rule 'no-debugger: off' $@
eslint_exit=$?
# do not fail on warnings
if [ $eslint_exit -eq 2 ]; then
${sx_more}
exit 0
fi
${sx_more}
exit $eslint_exit
`;
// root library
const h_lib_root_package_json = {
dependencies: {},
};
// package map
const h_packages = {};
// each package in the tree
(function map_tree(h_tree, s_path='') {
// each branch in subtree
for(let [s_key, z_value] of Object.entries(h_tree)) {
// leaf node; call value producer and save normalized version to map
if('function' === typeof z_value) {
h_packages[s_path+s_key] = Object.assign({
links: [],
}, z_value());
}
// another subtree; recurse
else {
map_tree(z_value, s_path+s_key+'.');
}
}
})(h_package_tree);
// list of content subs
let a_content_subs = [];
// each content package
for(let [s_content, g_content] of Object.entries(h_content_packages)) {
// ref base description
let s_description_base = g_content.description;
// each content mode of this package
for(let [s_mode, g_mode_extend] of Object.entries(g_content.modes)) {
let g_mode = {
...h_content_modes[s_mode],
...g_mode_extend,
};
// mode description
let s_description_mode = g_mode.description(s_description_base);
// build package name
let si_name = `content.${s_content}.${s_mode}`;
// add definition to package hash
h_packages[si_name] = {
...g_content,
...g_mode,
description: s_description_mode,
};
// content sub; add to sub map
if(g_content.super) {
h_packages[si_name].super = g_content.super;
a_content_subs.push(si_name);
// h_content_heirs[s_content] = si_name;
}
}
}
// normalize packages
let h_super_deps = Object.assign(g_package_json_super.dependencies);
for(let [si_package, g_package] of Object.entries(h_packages)) {
// auto-default ref package.json struct
let g_json = g_package.json = g_package.json || {};
// no name, use default
if(!g_json.name) {
g_json.name = `@${s_super}/${si_package}`;
}
// copy-by-value fields
Object.assign(g_json, {
description: g_package.description,
});
// auto-default ref dependencies
let h_dependencies = g_json.dependencies = (g_package.dependencies || [])
.reduce((h_deps, si_dep) => {
if(!(si_dep in h_super_deps)) throw new Error(`super repository missing sub-package (${si_package}) dependency: ${si_dep}`);
return {
[si_dep]: h_super_deps[si_dep],
};
}, {});
// convert links to dependencies
for(let si_link of g_package.links) {
h_dependencies[`@${s_super}/${si_link}`] = s_semver;
}
// add package dependency to root library
h_lib_root_package_json.dependencies[`@${s_super}/${si_package}`] = s_semver;
}
// recipe to make package.json file
const package_json = si_package => () => ({
deps: [
P_PACKAGE_JSON_BASE,
'package.json',
],
run: /* syntax: bash */ `
# load base package.json and enter
cat $1 | npx lambduh "g_base_package_json => {\
${/* syntax: js */`
// load package info
let g_package_json = ${JSON.stringify(h_packages[si_package].json)};
// update package.json
return Object.assign(g_base_package_json, g_package_json, {
version: '${s_base_version}',
});
`.trim().replace(/(["`])/g, '\\$1')} }" > $@
# sort its package.json
npx sort-package-json $@
`,
});
// recipe to make .npmrc file
const npmrc = () => ({
deps: [],
run: /* syntax: bash */ `
# write .npmrc file
echo "prefix=$PWD/.npm-packages" > $@
`,
});
// recipe to build jmacs file
const jmacs_lint = (a_deps=[], a_deps_strict=[]) => ({
deps: [
...a_deps,
...a_deps_strict,
...(a_deps.reduce((a_requires, p_dep) => {
// skip directories
if(fs.statSync(p_dep).isDirectory()) return a_requires;
// load script into jmacs
let g_compiled = jmacs.load(p_dep);
return [
...detective(g_compiled.meta.code),
...g_compiled.meta.deps,
].filter(s => s.startsWith('/'))
.map(p => path.relative(process.cwd(), p));
}, [])),
],
run: /* syntax: bash */ `
npx jmacs $1 > $@ \
&& ${eslint(/* syntax: bash */ `
node emk/pretty-print.js $@
`)}
`,
});
// create intra-library links for development & testing
const package_node_modules = si_package => ({
[`@${s_super}`]: {
...h_packages[si_package].links.reduce((h, si_link) => Object.assign(h, {
[si_link]: () => ({
deps: [
// `link_ready.${si_link}`,
`link.selected.${si_link}`,
// 'link.packages',
// ...h_packages[si_link].links.map(s => `build/${s}/**`),
],
run: /* syntax: bash */ `
pushd build/package/${si_package}
# link to dep
npm link @${s_super}/${si_link}
# echo "link @${s_super}/${si_link}"
# touch $@
`,
}),
}), {}),
// run: /* syntax: bash */ `
// mkdir -p $@
// pushd $@
// ${h_packages[si_package].links.map(si_link => /* syntax: bash */ `
// # link to dep
// npm link @${s_super}/${si_link}
// `).join('\n')}
// popd
// `,
},
// external dependencies
...(h_packages[si_package].dependencies || [])
.reduce((h_deps, si_dep) => Object.assign(h_deps, {
[si_dep]: () => ({
deps: [
`node_modules/${si_dep}`,
'package.json',
],
run: /* syntax: bash */ `
cd "build/package/${si_package}/node_modules"
ln -sf "../../../../$1" ${si_dep}
`,
}),
}), {}),
});
const scoped_package = si_package => ({
...(process.env.GRAPHY_USE_NVM
? {}
: {
'.npmrc': npmrc,
}),
'package.json': package_json(si_package),
node_modules: package_node_modules(si_package),
});
// carry files from a main source file's subdirectory
const carry_sub = (pd_src, h_recipe={}, pdr_package=null) => {
// scan directory
let a_files = fs.readdirSync(pd_src);
// deps
let a_deps = [];
let a_direct = [];
// each file
for(let s_file of a_files) {
let p_src = `${pd_src}/${s_file}`;
let pd_dst = `build/package/${pdr_package}`;
// *.js files
if(s_file.endsWith('.js')) {
h_recipe[s_file] = () => ({copy:p_src});
a_deps.push(`${pd_dst}/${s_file}`);
}
// *.jmacs files
else if(s_file.endsWith('.js.jmacs')) {
let s_dst = s_file.slice(0, -'.jmacs'.length);
h_recipe[s_dst] = () => jmacs_lint([p_src]);
a_deps.push(`${pd_dst}/${s_dst}`);
}
// subdirectory
else if(fs.statSync(p_src).isDirectory()) {
// make subrecipe; put in this recipe
let h_subrecipe = h_recipe[s_file] = {};
// recurse
a_deps.push(...carry_sub(p_src, h_subrecipe, `${pdr_package}/${s_file}`));
// simple deps
a_direct.push(`${pd_dst}/${s_file}/**`);
}
}
return a_direct.length? a_direct: a_deps;
// return a_deps;
};
let a_messages = fs.readdirSync('messages').sort().reverse().map(s => `messages/${s}`);
// emk struct
module.exports = async() => {
// make manifest dependencies
let h_manifest_deps = {};
{
const A_DEPEDENCY_PREDICATES = [
'http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#action',
'http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#result',
];
for(let si_package of a_content_subs.filter(s => s.endsWith('.read'))) {
let h_deps = h_manifest_deps[`manifest_deps_${si_package.replace(/\./g, '_')}`] = {};
try {
fs.accessSync(`build/package/content.ttl.read/main.js`, fs.constants.F_OK);
fs.accessSync(`build/cache/specs/${si_package}/manifest.ttl`, fs.constants.F_OK);
}
catch(e_access) {
continue;
}
if(process.env.GRAPHY_SKIP_MANIFEST) continue;
let ttl_read;
try {
ttl_read = require(`@${s_super}/content.ttl.read`); // eslint-disable-line global-require
}
catch(e_require) {
continue;
}
if('function' !== typeof ttl_read) continue;
let ds_manifest = fs.createReadStream(path.join(`build/cache/specs`, si_package, 'manifest.ttl'));
try {
await new Promise((fk_deps, fe_deps) => {
ds_manifest.pipe(ttl_read({
base_uri: h_packages[si_package].manifest,
data(g_quad) {
if(A_DEPEDENCY_PREDICATES.includes(g_quad.predicate.value)) {
let p_dep = g_quad.object.value;
h_deps[path.basename((new url(p_dep)).pathname)] = p_dep;
}
},
error(e_read) {
fe_deps(e_read);
},
end() {
fk_deps(h_deps);
},
}));
});
}
catch(e_read) {
continue;
}
}
}
return {
defs: {
// contet sub enum
content_sub: a_content_subs,
...(Object.entries(h_manifest_deps).reduce((h_out, [si_key, h_deps]) => ({
...h_out,
[si_key]: Object.keys(h_deps),
}), {})),
testable: [
'core.data.factory',
'content.nt.read',
'content.nt.scan',
'content.nt.scribe',
'content.nt.write',
'content.nq.read',
'content.nq.scan',
'content.nq.scribe',
'content.nq.write',
'content.ttl.read',
'content.ttl.scribe',
'content.ttl.write',
'content.trig.read',
'content.trig.scribe',
'content.trig.write',
'content.xml.scribe',
'memory.dataset.fast',
],
// package enumeration
package: Object.keys(h_packages),
// non-content-sub packages
package_ncs: Object.keys(h_packages)
.filter(s => !a_content_subs.includes(s)
&& !s.startsWith('content.n')
&& !s.startsWith('content.t')
&& !s.startsWith('store.memory.query')
),
// docs snippet
snippet: fs.readdirSync('src/docs/snippets')
.filter(s => s.endsWith('.js.jmacs')).map(s => s.replace(/\.jmacs$/, '')),
// docs markdown
markdown: fs.readdirSync('src/docs/')
.filter(s => s.endsWith('.md.jmacs')).map(s => s.replace(/\.jmacs$/, '')),
},
tasks: {
// all tasks
all: [
'prepublish.*',
],
// clean
clean: () => ({
run: /* syntax: bash */ `
rm -rf \
'${P_PACKAGE_PREFIX}/lib/node_modules/${s_super}' \
'${P_PACKAGE_PREFIX}/lib/node_modules/@${s_super}' \
'${P_PACKAGE_PREFIX}/bin/${s_super}' \
'build/package' \
'build/test' \
'node_modules/${s_super}' \
'node_modules/@${s_super}'
`,
}),
// link alias
link_ready: {
':package': h => ([
`${P_PACKAGE_PREFIX}/lib/node_modules/@${s_super}/${h.package}.ready`,
]),
},
link: {
// selected: () => ({
// run() {
// return a_link_selected.map(si_link => /* syntax: bash */ `
// # package directory relative to project root
// PACKAGE_DIR='build/package/${si_link}'
// # enter package directory
// pushd "$PACKAGE_DIR"
// # link self
// npm link
// # pop dir from stack
// popd
// `).map('\n');
// },
// }),
selected: {
':package': ({package:si_package}) => ({
deps: [
...h_packages[si_package].links.reduce((a_out, si_link) => [
...a_out,
`link.selected.${si_link}`,
], []),
`link_ready.${si_package}`,
],
run: /* syntax: bash */ `
# package directory relative to project root
PACKAGE_DIR='build/package/${si_package}'
# enter package directory
pushd "$PACKAGE_DIR"
# link self
npm link
# pop dir from stack
popd
`,
}),
},
packages: () => ({
deps: [
...Object.keys(h_packages).reduce((a_out, si_package) => [
...a_out,
`link_ready.${si_package}`,
], []),
],
run: Object.keys(h_packages).map(si_package => /* syntax: bash */ `
# package directory relative to project root
PACKAGE_DIR='build/package/${si_package}'
# enter package directory
pushd "$PACKAGE_DIR"
# link self
npm link
# pop dir from stack
popd
`).join('\n'),
}),
[s_super]: () => ([
`${P_PACKAGE_PREFIX}/lib/node_modules/${s_super}`,
]),
},
// link-to alias
local: {
':package': h => ({
deps: [`node_modules/@${s_super}/${h.package}`],
}),
[s_super]: () => ({
deps: [`node_modules/${s_super}`],
}),
},
// prepublish
prepublish: {
':package': h => ({
deps: [`local.${h.package}`],
run: /* syntax: bash */ `
cd build/package/${h.package}
# defer README to GitHub
rm -rf README.md
cat <(echo "#@${s_super}/${h.package}") ../../../emk/aux/README-defer.md > README.md
`,
}),
[s_super]: () => ({
deps: [`local.${s_super}`],
run: /* syntax: bash */ `
cd build/package/${s_super}
# defer README to GitHub
rm -rf README.md
cat <(echo "#${s_super}") ../../../emk/aux/README-defer.md > README.md
`,
}),
docs: ['docs/**'],
},
// publish
publish: {
':package': h => ({
deps: [`prepublish.${h.package}`],
run: /* syntax: bash */ `
cd build/package/${h.package}
# publish to npm
npm publish --access=public
`,
}),
[s_super]: () => ({
deps: [`prepublish.${s_super}`],
run: /* syntax: bash */ `
cd build/package/${s_super}
# publish to npm
npm publish --access=public
`,
}),
},
// tests
test: {
':testable': ({testable:si_package}) => ({
deps: [
`prepublish.${si_package}`,
'local.memory.dataset.fast',
`test/package/${si_package}.js`,
...a_content_subs.filter(s => s.endsWith('.read')).includes(si_package)
? [
`build/cache/specs/${si_package}/**`,
// `build/cache/specs/${si_package}/dependencies/*:{optional:true}`,
]
: [],
],
run: /* syntax: bash */ `
npx mocha --timeout 5000 --colors $3
`,
}),
[s_super]: () => ({
deps: [
`test/package/${s_super}.js`,
`prepublish.${s_super}`,
// 'build/cache/data/dbr/**',
],
run: /* syntax: bash */ `
npx mocha --timeout 5000 --colors $1
`,
}),
// web test
web: {
browserify: {
chrome: () => ({
deps: [
'test/web/runner.html',
`build/test/browserify/**`,
],
run: /* syntax: bash */ `
npx mocha-webdriver-runner --reporter=spec --headless-chrome $1
`,
}),
firefox: () => ({
deps: [
'test/web/runner.html',
`build/test/browserify/**`,
],
run: /* syntax: bash */ `
npx mocha-webdriver-runner --reporter=spec --headless-firefox $1
`,
}),
},
webpack: {
chrome: () => ({
deps: [
'test/web/runner.html',
`build/test/webpack/**`,
],
run: /* syntax: bash */ `
npx mocha-webdriver-runner --reporter=spec --headless-chrome $1
`,
}),
firefox: () => ({
deps: [
'test/web/runner.html',
`build/test/webpack/**`,
],
run: /* syntax: bash */ `
npx mocha-webdriver-runner --reporter=spec --headless-firefox $1
`,
}),
},
},
},
// performance
perf: ['build/perf/**'],
},
outputs: {
// eslint config
'.eslintrc.yaml': () => ({copy:'~/dev/.eslintrc.yaml'}),
// CHANGELOG.md
'CHANGELOG.md': () => ({
deps: [
...a_messages,
],
run: /* syntax: bash */ `
echo -e "# Changelog\\\\n\\\\n${a_messages.map(s => `$(cat '${s}')`).join('\\\\n'.repeat(3))}" > $@
`,
}),
// docs
docs: {
// snippets
snippets: {
':snippet': h => jmacs_lint([
`src/docs/snippets/${h.snippet}.jmacs`,
], [
'local.*',
]),
},
// markdown
':markdown': h => ({
deps: [
`src/docs/${h.markdown}.jmacs`,
`src/docs/docs.jmacs`,
'docs/snippets/**',
],
run: /* syntax: bash */ `
npx jmacs $1 > $@
`,
}),
},
// package builds
build: {
cache: {
specs: {
':content_sub': [si_package => ({
...(si_package.endsWith('.read')
? {
[si_package]: (g_package => ({
// manifest file
[path.basename(g_package.manifest)]: () => ({
deps: [
g_package.manifest,
],
run: /* syntax: bash */ `
curl "$1" > $@
`,
}),
// manifest dependencies
...(si_manifest_dep => ({
[`:${si_manifest_dep}`]: [s_dep => ({
[s_dep]: () => ({
deps: [
h_manifest_deps[si_manifest_dep][s_dep],
`build/cache/specs/${si_package}/${path.basename(g_package.manifest)}`,
],
run: /* syntax: bash */ `
curl "$1" > $@
`,
}),
})],
}))(`manifest_deps_${si_package.replace(/\./g, '_')}`),
}))(h_packages[si_package]),
}
: {}),
})],
},
},
package: {
// content subs
':content_sub': [si_package => ({
[si_package]: (g_package => ({
...scoped_package(si_package),
...Object.entries(g_package.files).reduce((h_def, [s_file, a_deps]) => ({
...h_def,
[s_file]: () => ({
deps: [
`src/content/${g_package.super}/${si_package.split(/\./g)[2]}/${s_file}.jmacs`,
...a_deps.map(s_dep => path.join(`src/content/${g_package.super}/`, s_dep)),
],
run: /* syntax: bash */ `
npx jmacs -g "{FORMAT:'${si_package.split(/\./g)[1]}'}" $1 > $@ \
&& ${eslint(/* syntax: bash */ `
node emk/pretty-print.js $@
`)}
`,
}),
}), {}),
}))(h_packages[si_package]),
})],
// all non-content-sub packages
':package_ncs': [si_package => ({
[si_package]: {
...scoped_package(si_package),
'main.js': () => jmacs_lint([
`src/${si_package.replace(/\./g, '/')}.js.jmacs`,
], [
`build/package/${si_package}/package.json`,
]),
...((h_packages[si_package].includes || []).reduce((h_out, s_include) => ({
...h_out,
[s_include]: () => ({
copy: `src/${si_package.replace(/\./g, '/').replace(/\/[^/]+$/, '')}/${s_include}`,
}),
}), {})),
},
})],
// the super module
[s_super]: {
...(process.env.GRAPHY_USE_NVM
? {}
: {
'.npmrc': npmrc,
}),
'package.json': () => ({
deps: [
P_PACKAGE_JSON_BASE,
'package.json',
],
run: /* syntax: bash */ `
cat $1 | npx lambduh "g_base_package_json => { \
${/* eslint-disable indent */
/* syntax: js */`
// load package info
let g_package_json = ${JSON.stringify({
name: s_super,
dependencies: {
...g_package_json_super.dependencies,
...Object.keys(h_packages).reduce((h, si_link) => Object.assign(h, {
[`@${s_super}/${si_link}`]: s_base_version,
}), {}),
},
description: 'A comprehensive RDF toolkit including triplestores, intuitive writers, and the fastest JavaScript parsers on the Web',
main: 'api.js',
bin: {
[s_super]: 'cli.js',
},
})};
// update package.json
return Object.assign(g_base_package_json, g_package_json);
`.trim().replace(/(["`])/g, '\\$1')
/* eslint-enable */} }" > $@
# sort its package.json
npx sort-package-json $@
`,
}),
node_modules: {
[`@${s_super}`]: {
':package': ({package:si_package}) => ({
deps: [
...(process.env.GRAPHY_USE_NVM
? []
: [`build/package/${s_super}/.npmrc`]),
`local.${si_package}`,
],
run: /* syntax: bash */ `
cd build/package/${s_super}
npm link @${s_super}/${si_package}
`,
}),
},
},
'api.js': () => jmacs_lint([`src/main/graphy.js.jmacs`], ['package.json']),
'cli.js': () => jmacs_lint([`src/cli/cli.js.jmacs`]),
// quad-expression parser
'quad-expression.js': () => ({
deps: [
'src/cli/quad-expression.pegjs',
],
run: /* syntax: bash */ `
npx pegjs < $1 > $@
`,
}),
// quad-expression parser
'expression-handler.js': () => ({
copy: 'src/cli/expression-handler.js',
}),
'constants.js': () => ({
copy: 'src/cli/constants.js',
}),
},
},
test: {
browserify: {
':testable.js': ({testable:si_package}) => ({
deps: [
`test/package/${si_package}.js`,
],
run: /* syntax: bash */ `
npx browserify $1 -d -o $@
`,
}),
},
webpack: {
':testable.js': ({testable:si_package}) => ({
deps: [
`test/package/${si_package}.js`,
],
run: /* syntax: bash */ `
npx webpack --config=./emk/webpack.config.js $1 -o $@
`,
}),
},
},
},
// package linking
[P_PACKAGE_PREFIX]: {
lib: {
node_modules: {
[`@${s_super}`]: {
':package.ready': ({package:si_package}) => ({
deps: [
`build/package/${si_package}/**`,
],
run: /* syntax: bash */ `
# package directory relative to project root
PACKAGE_DIR='build/package/${si_package}'
# enter package directory
pushd "$PACKAGE_DIR"
# remove package lock
rm -f package-lock.json
# pop dir off stack
popd
# touch file ready
mkdir -p $(dirname $@)
touch $@
# # then link self
# npm link
`,
}),
},
[s_super]: () => ({
deps: [
`build/package/${s_super}/**`,
...Object.keys(h_packages).map(s_dep => `link_ready.${s_dep}`),