lampson 0.1.0 → 0.1.2

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/bin/lampson.js CHANGED
@@ -24,11 +24,17 @@ const marker = path.join(home, '.npm-installed');
24
24
  // what gets copied into the home: the runtime, never state. Keep in sync with "files" in package.json.
25
25
  const CODE = ['lib', 'public', 'skills', 'chat.syn', 'web.syn', 'lampson.ps1', 'lampson.sh', 'lampson.cmd', '.env.example', 'README.md', 'LICENSE'];
26
26
 
27
+ // copia un archivo; en unix, los scripts de shell y los .syn salen con LF aunque el paquete se haya armado
28
+ // en Windows (un CRLF en lampson.sh rompe bash: "set: pipefail\r: invalid option")
29
+ function copyFile(s, d) {
30
+ if (process.platform !== 'win32' && /\.(sh|syn)$/.test(s)) fs.writeFileSync(d, fs.readFileSync(s, 'utf8').replace(/\r\n/g, '\n'), { mode: /\.sh$/.test(s) ? 0o755 : 0o644 });
31
+ else fs.copyFileSync(s, d);
32
+ }
27
33
  function copyDir(src, dst) {
28
34
  fs.mkdirSync(dst, { recursive: true });
29
35
  for (const e of fs.readdirSync(src, { withFileTypes: true })) {
30
36
  const s = path.join(src, e.name), d = path.join(dst, e.name);
31
- if (e.isDirectory()) copyDir(s, d); else fs.copyFileSync(s, d);
37
+ if (e.isDirectory()) copyDir(s, d); else copyFile(s, d);
32
38
  }
33
39
  }
34
40
 
@@ -44,7 +50,7 @@ function sync() {
44
50
  if (!fs.existsSync(src)) continue;
45
51
  const dst = path.join(home, item);
46
52
  if (fs.statSync(src).isDirectory()) { fs.rmSync(dst, { recursive: true, force: true }); copyDir(src, dst); }
47
- else fs.copyFileSync(src, dst);
53
+ else copyFile(src, dst);
48
54
  }
49
55
  // global lamps are user content: seed the example once, never overwrite what the user put there
50
56
  const lampsSrc = path.join(pkgDir, 'lamps'), lampsDst = path.join(home, 'lamps');