@naanlang/naan 1.0.5 → 1.0.7

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.
@@ -716,6 +716,10 @@ closure Builder(rules, operation, fs, srcpath, destpath, local build, group, new
716
716
  entry.unzip = true
717
717
  entry.writepath = outdirpath
718
718
  }
719
+ if group.tasks.indexOf("catenate") >= 0
720
+ entry.catenate = true
721
+ if group.tasks.indexOf("zip") >= 0
722
+ entry.zip = true
719
723
  if group.tasks.indexOf("naanpack") >= 0 || group.tasks.indexOf("jspack") >= 0 || group.tasks.indexOf("syntax") >= 0 {
720
724
  let (inpar, outpar, extension) { // change extension for package output
721
725
  inpar = JSpath.parse(infile)
@@ -740,12 +744,12 @@ closure Builder(rules, operation, fs, srcpath, destpath, local build, group, new
740
744
  inpar.base = inpar.name.concat(extension)
741
745
  entry.insource = JSpath.format(inpar)
742
746
  }
743
- } else
747
+ } else if !entry.zip && !entry.catenate
744
748
  entry.copy = true // fall back to copy
745
749
  } ()
746
750
  }
747
751
  if group.tasks.indexOf("minimize") >= 0 {
748
- if infile.endsWith(".js") {
752
+ if infile.endsWith(".js") || outfile.endsWith(".js") {
749
753
  entry.minimize = true
750
754
  if group.minprefix
751
755
  entry.minprefix = group.minprefix // use group minify prefix
@@ -753,10 +757,7 @@ closure Builder(rules, operation, fs, srcpath, destpath, local build, group, new
753
757
  entry.minprefix = build.minprefix // use generic minify prefix
754
758
  }
755
759
  }
756
- if group.tasks.indexOf("catenate") >= 0
757
- entry.catenate = true
758
- if group.tasks.indexOf("zip") >= 0 {
759
- entry.zip = true
760
+ if entry.zip {
760
761
  if !entry.writepath.toLowerCase().endsWith(".zip")
761
762
  entry.writepath = entry.writepath.concat(".zip") // always ends with .zip
762
763
  outfile = entry.writepath
@@ -844,7 +845,8 @@ closure Builder(rules, operation, fs, srcpath, destpath, local build, group, new
844
845
  // checked and any that have all the parts are written out. Catenates that don't have all their
845
846
  // parts are reported as an error in addition to the error that caused them to be incomplete.
846
847
  //
847
- closure execute(local error, entries, pending, licFileDefs, buildno, verFileDefs, baddestpaths, catenates) {
848
+ closure execute(local error, licFileDefs, buildno, verFileDefs, version, entries, pending,
849
+ baddestpaths, catenates) {
848
850
  if build.tasks.license > 0
849
851
  `(error, licFileDefs) = readSubstitutionFile(build.licfilepath)
850
852
  if build.tasks.version > 0 {
@@ -858,6 +860,8 @@ closure Builder(rules, operation, fs, srcpath, destpath, local build, group, new
858
860
  `(error, verFileDefs) = readSubstitutionFile(build.verfilepath, {
859
861
  BuildNumber: buildno
860
862
  })
863
+ build.version = verFileDefs["Version"]
864
+ verFileDefs["CacheBuster"] = HashMD5(build.version.concat(Math.random()))
861
865
  }
862
866
  if build.tasks.catenate > 0 || build.tasks.zip > 0 {
863
867
  build.templates = { }
@@ -962,7 +966,7 @@ closure Builder(rules, operation, fs, srcpath, destpath, local build, group, new
962
966
 
963
967
  let (writepath, template, entry, content, catsub, dozip, docat, fsoptions, zipmap, error, result) {
964
968
  for :out1 writepath in catenates {
965
- template = build.templates[writepath] // optional
969
+ template = build.templates[writepath] // optional in some cases ### should warn in others
966
970
  catsub = { }
967
971
  for entry in catenates[writepath] { // error check and substitution build
968
972
  if !entry.content {
@@ -1024,13 +1028,14 @@ closure Builder(rules, operation, fs, srcpath, destpath, local build, group, new
1024
1028
  // } ... ]
1025
1029
  // }
1026
1030
  //
1027
- build.make = closure make(debugMake, local sink, xchan, entry, outext, error) {
1031
+ build.make = closure make(options, local sink, xchan, entry, outext, error) {
1028
1032
  sink = new(textstream, "", `string) // log all output
1029
1033
  xchan = textstreams(list(sink, sink))
1030
1034
  try {
1031
1035
  resetlist()
1032
- analyze(debugMake)
1033
- if debugMake {
1036
+ analyze(options.debugMake)
1037
+ if options.debugMake {
1038
+ printline("Debugging make for ", options.buildnum, "-", options.stage)
1034
1039
  if build.errorlist.length == 0 {
1035
1040
  printline("build operations (", build.filelist.length, ") for ", operation)
1036
1041
  for entry in build.filelist
@@ -1052,6 +1057,8 @@ closure Builder(rules, operation, fs, srcpath, destpath, local build, group, new
1052
1057
  "\ndate: ", Date(),
1053
1058
  "\nfrom: ", JSpath.join(fs.rootpath, build.srcpath),
1054
1059
  "\n to: ", build.destpath,
1060
+ "\ntype: ", options.stage,
1061
+ "\nvers: ", build.version,
1055
1062
  "\n", sink.taketext())
1056
1063
  `(error) = fs.writeFile(JSpath.join(build.destpath, "build_log.txt"), outext)
1057
1064
  if error
@@ -1153,14 +1160,17 @@ closure Builder(rules, operation, fs, srcpath, destpath, local build, group, new
1153
1160
  //
1154
1161
  // build.refresh
1155
1162
  //
1156
- // Refresh after updating the v-site. This should probably update all types of executions. ###
1163
+ // Refresh after updating the v-site, returning true iff an existing vsite was found.
1157
1164
  //
1158
- build.refresh = function refresh(track local main, url_origin) {
1165
+ build.refresh = function refresh(track local main, url_origin, found) {
1159
1166
  if build.runway."v-site" {
1160
1167
  url_origin = js.w.location.origin.concat("/run", build.runway."v-site")
1161
- for target in track.enumlist()
1162
- target.vsiteRefresh(url_origin)
1168
+ for target in track.enumlist() {
1169
+ if target.vsiteRefresh(url_origin)
1170
+ found = true
1171
+ }
1163
1172
  }
1173
+ found
1164
1174
  }
1165
1175
 
1166
1176
  //
@@ -296,7 +296,7 @@ closure projConnector(projman, projtype, local connector, watch) {
296
296
  *
297
297
  * Nide.proj/
298
298
  * nide_cliser.cfg - JSON definition of the project (see below)
299
- * NaanIDE_version.txt - [default] substitution file defining 1.0.5-1 etc.
299
+ * NaanIDE_version.txt - [default] substitution file defining 1.0.7+1 etc.
300
300
  * NaanIDE_version_builds.txt - [default] contains current build number as decimal string
301
301
  * build/ - [optional] default build output location
302
302
  * NaanIDE.lic - [optional] defines Zulch Laboratories, Inc. and other license info
@@ -326,6 +326,7 @@ proj_cliserConfigFile = "nide_cliser.cfg";
326
326
  closure projConfig(projman, where, projID, local procon, fs, configpath) {
327
327
  procon = new(object, this)
328
328
  procon.name = where.name
329
+ procon.dirName = proj_configDataFolder.slice(0,-1) // remove terminal "/"
329
330
  if projID
330
331
  procon.localID = projID.concat("-data")
331
332
 
@@ -407,7 +408,11 @@ closure projConfig(projman, where, projID, local procon, fs, configpath) {
407
408
  if error
408
409
  debuglog("projConfig.writeConfig cannot write local storage:", ErrorString(error))
409
410
  }
410
- `(error, data) = fs.writeFile(configpath, JSONstringify(procon.configDict))
411
+ if procon.configMD5 { // don't overwrite existing file
412
+ data = HashMD5(JSONstringify(procon.configDict)) // ### it messes up the formatting and
413
+ error = false // is manually maintained anyway
414
+ } else
415
+ `(error, data) = fs.writeFile(configpath, JSONstringify(procon.configDict))
411
416
  if !error {
412
417
  procon.configMD5 = data
413
418
  `(error, info) = fs.info(configpath)
@@ -547,39 +552,57 @@ closure projConfig(projman, where, projID, local procon, fs, configpath) {
547
552
  stage
548
553
  }
549
554
 
555
+ // setCurrentStage
556
+ //
557
+ // Set the current stage.
558
+ //
559
+ procon.setCurrentStage = function setCurrentStage(stage) {
560
+ if member(stage, stages()) {
561
+ procon.localDict.currentStage = stage
562
+ update() // ### errors here are never reported
563
+ }
564
+ }
565
+
550
566
  // buildrules
551
567
  //
552
- // Get the build rules for the named stage.
568
+ // Get the build rules for the named stage, reloading the project configuration if changed.
553
569
  //
554
- function buildrules(stage, local rules, common, rule, key) {
570
+ function buildrules(stage, local error, data, rules, common, rule, key) {
571
+ if !procon.loaded
572
+ return (list(Error("project not loaded")))
573
+ `(error, data) = procon.changed()
574
+ if error
575
+ return (list(error))
555
576
  rules = procon.configDict."build-rules"[stage]
556
577
  if !rules
557
578
  rules = procon.configDict.build // fallback to old config structure
558
579
  rules = new(rules)
559
- common = procon.configDict."build-common"
580
+ if !rules["no-common"]
581
+ common = procon.configDict."build-common"
560
582
  if common {
561
583
  for rule in common
562
584
  if !rules[rule]
563
585
  rules[rule] = common[rule] // common rule was not overridden
564
- else if array(common[rule], rules[rule])
586
+ else if array(common[rule], rules[rule]) // ### array only tests first argument 20220909 Rcz
565
587
  rules[rule] = common[rule].concat(rules[rule]) // merge common array with rule
566
- else if dictionary(common[rule], rules[rule]) {
588
+ else if dictionary(common[rule], rules[rule]) { // ### dictionary only tests first argument 20220909 Rcz
567
589
  for key in common[rule] // merge common dictionary with rule
568
590
  if !rules[rule][key]
569
591
  rules[rule][key] = common[rule][key]
570
592
  }
571
593
  }
572
- rules
594
+ list(false, rules)
573
595
  }
574
596
 
575
597
  // run
576
598
  //
577
599
  // Run the project by building and then launching.
578
600
  //
579
- procon.run = closure run(stage, buildonly, local rules, builder, buildpath, error, buildnum) {
580
- if !procon.loaded
581
- return (list(Error("project not loaded")))
582
- rules = buildrules(stage)
601
+ procon.run = closure run(stage, buildonly,
602
+ local error, rules, builder, buildpath, error, buildnum) {
603
+ `(error, rules) = buildrules(stage)
604
+ if error
605
+ return (list(error))
583
606
  if !rules || !rules.products
584
607
  return (list(Error("build rules missing or incomplete")))
585
608
  buildpath = fs.path.join(proj_configDataFolder, rules.products)
@@ -595,11 +618,14 @@ closure projConfig(projman, where, projID, local procon, fs, configpath) {
595
618
  ErrorDebuglog("build number increment failed", error)
596
619
  return (list(error))
597
620
  }
598
- `(error) = builder.make()
621
+ `(error) = builder.make({
622
+ stage: stage
623
+ buildnum: buildnum
624
+ })
599
625
  if !error {
600
- if buildonly
601
- builder.refresh(projman.track)
602
- else
626
+ if builder.refresh(projman.track)
627
+ buildonly = !buildonly // reverse if refresh
628
+ if !buildonly
603
629
  `(error) = builder.run(projman.track)
604
630
  }
605
631
  builder.destroy()
@@ -613,13 +639,27 @@ closure projConfig(projman, where, projID, local procon, fs, configpath) {
613
639
  //
614
640
  // Publish the project to its configured location.
615
641
  //
616
- procon.publish = closure publish(stage, local rules, where, publish, error, outfs, inpath) {
617
- rules = buildrules(stage)
642
+ // {
643
+ // input: "tutorApp/www/"
644
+ // sources: [""]
645
+ // output: ""
646
+ // cacheControl: "max-age=2592000"
647
+ // }
648
+ //
649
+ procon.publish = closure publish(stage,
650
+ local error, rules, where, publish, error, outOptions, outfs, inpath) {
651
+ `(error, rules) = buildrules(stage)
652
+ if error
653
+ return (list(error))
618
654
  publish = rules.publish
619
655
  where = procon.localDict.publish[stage].where
620
656
  if !rules || !where
621
657
  return (list(Error("no project publish location configured")))
622
- `(error, outfs) = projman.locate.connect(where.locationID, "NideFS", where.path)
658
+ if publish.cacheControl
659
+ outOptions = {
660
+ cacheControl: publish.cacheControl
661
+ }
662
+ `(error, outfs) = projman.locate.connect(where.locationID, "NideFS", where.path, outOptions)
623
663
  if error
624
664
  return (list(Error("can't access publishing filesystem", error)))
625
665
  inpath = fs.path.join(proj_configDataFolder, rules.products, publish.input)
@@ -656,8 +696,8 @@ closure projConfig(projman, where, projID, local procon, fs, configpath) {
656
696
  */
657
697
 
658
698
  function projInit(local manifest) {
659
-
660
- manifest = `(ProjectManager, projTracker, projConnector, projConfig, projInit)
699
+ manifest = `(ProjectManager, projTracker, projConnector, proj_configDataFolder,
700
+ proj_cliserConfigFile, projConfig, projInit)
661
701
 
662
702
  Naan.module.build(module.id, "projects", function(modobj, compobj) {
663
703
  require("./project.nlg")
@@ -438,7 +438,6 @@ closure ExecutorTracker(local xtrak) {
438
438
  // Notify watchers of an update on an execution instance.
439
439
 
440
440
  xtrak.update = closure update(executor) {
441
- debuglog("xtrack.update", executor.title)
442
441
  notify({ updated: [executor] })
443
442
  }
444
443
 
@@ -144,7 +144,7 @@ function procstring(procdef, options, local name, output, parm) {
144
144
  function runnInit(local manifest) {
145
145
  manifest = `(rootproc, baseproc, pathmatch, procpath, procname, procstring, runnInit)
146
146
 
147
- build(module.id, "running", closure(modobj, compobj) {
147
+ Naan.module.build(module.id, "running", closure(modobj, compobj) {
148
148
  require("../common").LiveImport()
149
149
  compobj.manifest = manifest
150
150
  })
@@ -119,7 +119,7 @@ closure taskDispatcher(replier, local contexts, gohome, util) {
119
119
  }
120
120
  }
121
121
  else
122
- call(onMessageHook, data)
122
+ onMessageHook(data)
123
123
  } catch {
124
124
  if true {
125
125
  if tuple(exception)
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * column positioning: // // !
8
8
  *
9
- * Copyright (c) 2020-2021 by Richard C. Zulch
9
+ * Copyright (c) 2020-2022 by Richard C. Zulch
10
10
  *
11
11
  */
12
12
 
@@ -287,6 +287,7 @@ closure FileManager(fs, options, local files, watch, opqueue, willgit, hadgit) {
287
287
  fixed: true
288
288
  ignoreCase: true
289
289
  returnText: true
290
+ excludeDirs: []
290
291
  }
291
292
  }
292
293
 
@@ -465,14 +465,24 @@ closure FSview(table, rootpath, local view, error) {
465
465
  if !callback
466
466
  return (syncAdapter(info, path))
467
467
  dbReadRecord(path, true, function(error, data, local finfo) {
468
- if data {
468
+ if data { // try to glean the node info
469
469
  finfo = new(data.finfo)
470
470
  if !finfo
471
471
  finfo = { }
472
472
  if data._md5
473
473
  finfo.md5 = data._md5
474
- if data._length
475
- finfo.length = data._length }
474
+ if xobject(data.modified) {
475
+ finfo.mtimeMs = data.modified.getTime()
476
+ finfo.mtime = data.modified.toISOString()
477
+ }
478
+ if data.contentType
479
+ finfo.contentType = data.contentType
480
+ if data.length
481
+ finfo.length = data.length
482
+ else if data._length
483
+ finfo.length = data._length
484
+ if finfo.length
485
+ finfo.type = "file" }
476
486
  else if path == "" {
477
487
  error = false // we were asked for info on superoot
478
488
  finfo = {
@@ -309,8 +309,11 @@ exports.NaanControllerWeb = function() {
309
309
  //
310
310
 
311
311
  this.VsiteRefresh = function VsiteRefresh(url_origin) {
312
- if (window.location.href.startsWith(url_origin))
312
+ if (vsiteName && window.location.href.startsWith(url_origin)) {
313
313
  window.location.reload(); // we have changed underneath
314
+ return (true);
315
+ }
316
+ return (false);
314
317
  };
315
318
 
316
319
 
@@ -455,7 +458,7 @@ exports.NaanControllerWeb = function() {
455
458
  statedoc.curversion = kStateCurrentVersion;
456
459
  statedoc.firstver = kStateFirstVersion;
457
460
  statedoc.licensee = "MIT-License";
458
- statedoc.verstring = "1.0.5-1";
461
+ statedoc.verstring = "1.0.7+1";
459
462
  statedoc.date = new Date().toISOString();
460
463
  statedoc.prefs = prefs;
461
464
  statedoc.naan = naanlib.saveState(false); // true to optimize, which is a bit slower
@@ -473,7 +476,7 @@ exports.NaanControllerWeb = function() {
473
476
  || statedoc.firstver > kStateCurrentVersion
474
477
  || statedoc.curversion < kStateFirstVersion
475
478
  || statedoc.licensee != "MIT-License"
476
- || statedoc.verstring != "1.0.5-1")
479
+ || statedoc.verstring != "1.0.7+1")
477
480
  {
478
481
  localStorage.removeItem("NaanState_Hosted");
479
482
  return (false);
@@ -531,7 +534,7 @@ exports.NaanControllerWeb = function() {
531
534
  op: "VsiteOpen",
532
535
  name: vsiteName,
533
536
  naancont: contSelf,
534
- title: vsiteName + " 1.0.5-1"
537
+ title: vsiteName + " 1.0.7+1"
535
538
  });
536
539
  }
537
540
 
@@ -541,8 +544,9 @@ exports.NaanControllerWeb = function() {
541
544
  op: "VsiteClose",
542
545
  name: vsiteName,
543
546
  naancont: contSelf,
544
- title: vsiteName + " 1.0.5-1"
547
+ title: vsiteName + " 1.0.7+1"
545
548
  });
549
+ vsiteName = false; // window is going away
546
550
  termTextOut("\x1b[90m\x1b[3m".concat("\nwindow closed", "\x1b[0m\n"));
547
551
  }
548
552
  }
@@ -553,7 +557,10 @@ exports.NaanControllerWeb = function() {
553
557
  naanlib.banner();
554
558
  var hostpath = naanlib.js.r("path").dirname(window.location.href);
555
559
  naanlib.start({
556
- cmd: 'Naan.module.webparse("naan_init.nlg", "' + hostpath + '"' + ');;\r\n'
560
+ cmd: 'App.version = "1.0.7+1";;\r\n'
561
+ + 'App.cache = "cb-1.0.7+1";;\r\n'
562
+ + 'Naan.module.requireQuery({ naanver: App.cache });;\r\n'
563
+ + 'Naan.module.webparse("naan_init.nlg", "' + hostpath + '", { naanver: App.cache });;\r\n'
557
564
  });
558
565
  } else {
559
566
  if (!replstate) { // saved state but never opened a terminal
@@ -104,6 +104,16 @@ exports.NaanControllerWebWorker = function NaanControllerWebWorker() {
104
104
  return (proc);
105
105
  };
106
106
 
107
+ targSelf.Download = function Download(bits, name, options) {
108
+ postMessage({ // tell browser host to download a file
109
+ id: "download",
110
+ bits: bits,
111
+ name: name,
112
+ options: options,
113
+ });
114
+ return (name);
115
+ };
116
+
107
117
  onmessage = function(e) {
108
118
  var msg = e.data;
109
119
  if (msg.id == "interrupt")