saladplate 0.1.1-a → 0.1.1

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.
@@ -1,5 +1,4 @@
1
1
  #! /usr/bin/env node
2
- "use strict";
3
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -9,18 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
10
9
  });
11
10
  };
12
- var __importDefault = (this && this.__importDefault) || function (mod) {
13
- return (mod && mod.__esModule) ? mod : { "default": mod };
14
- };
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- const fs_1 = __importDefault(require("fs"));
17
- const path_1 = __importDefault(require("path"));
18
- const process_1 = __importDefault(require("process"));
19
- const util_1 = __importDefault(require("util"));
20
- const index_1 = require("../src/index");
11
+ import fs from "fs";
12
+ import path from "path";
13
+ import process from "process";
14
+ import util from "util";
15
+ import { BIN, template } from "../src/index";
21
16
  const parseArgsConfig = {
22
17
  // Exclude the first two arguments: node and the script itself.
23
- args: process_1.default.argv.slice(2),
18
+ args: process.argv.slice(2),
24
19
  options: {
25
20
  debug: {
26
21
  type: "boolean",
@@ -58,7 +53,7 @@ const parseArgsConfig = {
58
53
  allowPositionals: true,
59
54
  };
60
55
  function help() {
61
- console.info(`Usage: ${index_1.BIN} [options] <file>...`);
56
+ console.info(`Usage: ${BIN} [options] <file>...`);
62
57
  console.info(`Options:`);
63
58
  const entries = Object.entries(parseArgsConfig.options);
64
59
  const prefixes = {};
@@ -76,11 +71,11 @@ function help() {
76
71
  console.info("");
77
72
  }
78
73
  function version() {
79
- const version = process_1.default.env.npm_package_version;
80
- console.info(`${index_1.BIN}: version ${version !== null && version !== void 0 ? version : "unknown"}`);
74
+ const version = process.env.npm_package_version;
75
+ console.info(`${BIN}: version ${version !== null && version !== void 0 ? version : "unknown"}`);
81
76
  }
82
77
  const parseArgs = () => {
83
- const { values: options, positionals: filenames } = util_1.default.parseArgs(parseArgsConfig);
78
+ const { values: options, positionals: filenames } = util.parseArgs(parseArgsConfig);
84
79
  return { options, filenames };
85
80
  };
86
81
  let output = null;
@@ -91,14 +86,14 @@ function outputForFilename(filename, options) {
91
86
  }
92
87
  if (options.output) {
93
88
  output = {
94
- file: yield fs_1.default.promises.open(options.output, "w"),
89
+ file: yield fs.promises.open(options.output, "w"),
95
90
  filename: options.output,
96
91
  };
97
92
  return output;
98
93
  }
99
94
  if (options.directory) {
100
- const basename = path_1.default.basename(filename);
101
- let outputFilename = path_1.default.join(options.directory, basename);
95
+ const basename = path.basename(filename);
96
+ let outputFilename = path.join(options.directory, basename);
102
97
  if (options.suffix) {
103
98
  outputFilename = outputFilename.replace(/\.[^.]+$/, options.suffix);
104
99
  }
@@ -108,7 +103,7 @@ function outputForFilename(filename, options) {
108
103
  };
109
104
  }
110
105
  output = {
111
- file: yield fs_1.default.promises.open("/dev/stdout", "w"),
106
+ file: yield fs.promises.open("/dev/stdout", "w"),
112
107
  filename: "/dev/stdout",
113
108
  };
114
109
  return output;
@@ -118,7 +113,7 @@ function main() {
118
113
  return __awaiter(this, void 0, void 0, function* () {
119
114
  const { options, filenames } = parseArgs();
120
115
  if (options.debug) {
121
- console.debug(`${index_1.BIN}: debug mode enabled`);
116
+ console.debug(`${BIN}: debug mode enabled`);
122
117
  }
123
118
  if (options.help) {
124
119
  help();
@@ -129,7 +124,7 @@ function main() {
129
124
  return;
130
125
  }
131
126
  if (filenames.length === 0) {
132
- console.error(`${index_1.BIN}: no input files; use -- for stdin`);
127
+ console.error(`${BIN}: no input files; use -- for stdin`);
133
128
  help();
134
129
  return -1;
135
130
  }
@@ -137,15 +132,15 @@ function main() {
137
132
  if (filename === "--") {
138
133
  filename = "/dev/stdin";
139
134
  }
140
- options.debug && console.debug(`${index_1.BIN}: reading ${filename}...`);
141
- const content = yield fs_1.default.promises.readFile(filename, {
135
+ options.debug && console.debug(`${BIN}: reading ${filename}...`);
136
+ const content = yield fs.promises.readFile(filename, {
142
137
  encoding: "utf-8",
143
138
  });
144
- options.debug && console.debug(`${index_1.BIN}: templating ${filename}...`);
145
- const output = yield (0, index_1.template)(content, filename, options);
139
+ options.debug && console.debug(`${BIN}: templating ${filename}...`);
140
+ const output = yield template(content, filename, options);
146
141
  const { file: outputFile, filename: outputFilename } = yield outputForFilename(filename, options);
147
- options.debug && console.debug(`${index_1.BIN}: writing ${outputFilename}...`);
148
- yield fs_1.default.promises.writeFile(outputFile, output, {
142
+ options.debug && console.debug(`${BIN}: writing ${outputFilename}...`);
143
+ yield fs.promises.writeFile(outputFile, output, {
149
144
  encoding: "utf-8",
150
145
  });
151
146
  })));
@@ -153,9 +148,9 @@ function main() {
153
148
  }
154
149
  main()
155
150
  .then((i) => {
156
- process_1.default.exit(i !== null && i !== void 0 ? i : 0);
151
+ process.exit(i !== null && i !== void 0 ? i : 0);
157
152
  })
158
153
  .catch((e) => {
159
- console.error(`${index_1.BIN}: unhandled error:`, e);
160
- process_1.default.exit(-1);
154
+ console.error(`${BIN}: unhandled error:`, e);
155
+ process.exit(-1);
161
156
  });
package/dist/src/index.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,22 +7,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.template = exports.BIN = void 0;
16
- const child_process_1 = require("child_process");
17
- const fs_1 = __importDefault(require("fs"));
18
- const path_1 = __importDefault(require("path"));
19
- const process_1 = __importDefault(require("process"));
20
- const util_1 = __importDefault(require("util"));
10
+ import { exec } from "child_process";
11
+ import fs from "fs";
12
+ import path from "path";
13
+ import process from "process";
14
+ import util from "util";
21
15
  /**
22
16
  * The name of the tool; prefixes most output.
23
17
  */
24
- exports.BIN = "saladplate";
18
+ export const BIN = "saladplate";
25
19
  const cwdForFilename = (filename) => {
26
- return filename === "/dev/stdin" ? process_1.default.cwd() : path_1.default.dirname(filename);
20
+ return filename === "/dev/stdin" ? process.cwd() : path.dirname(filename);
27
21
  };
28
22
  const VAR_RE = /\$\{\{([^\}]+)\}\}/g;
29
23
  const FILE_RE = /\$\<\<([^\>]+)\>\>/g;
@@ -37,24 +31,24 @@ function replaceAsync(input, regexp, fn) {
37
31
  }
38
32
  const replaceVar = (variable, filename, options) => {
39
33
  var _a;
40
- options.debug && console.debug(`${exports.BIN}: ${filename}: evaluating ${variable} for replacement...`);
41
- return (_a = process_1.default.env[variable]) !== null && _a !== void 0 ? _a : "";
34
+ options.debug && console.debug(`${BIN}: ${filename}: evaluating ${variable} for replacement...`);
35
+ return (_a = process.env[variable]) !== null && _a !== void 0 ? _a : "";
42
36
  };
43
37
  const replaceFile = (includeFilename, filename, options) => __awaiter(void 0, void 0, void 0, function* () {
44
38
  // Resolve the include filename relative to the current file; if the current file is stdin
45
39
  // then keep the current working directory.
46
40
  const cwd = cwdForFilename(filename);
47
- const include = path_1.default.join(cwd, includeFilename);
48
- options.debug && console.debug(`${exports.BIN}: ${filename}: reading ${include} for replacement...`);
49
- const content = yield fs_1.default.promises.readFile(include, { encoding: "utf-8" });
50
- return (0, exports.template)(content, include, options);
41
+ const include = path.join(cwd, includeFilename);
42
+ options.debug && console.debug(`${BIN}: ${filename}: reading ${include} for replacement...`);
43
+ const content = yield fs.promises.readFile(include, { encoding: "utf-8" });
44
+ return template(content, include, options);
51
45
  });
52
46
  const replaceExec = (command, filename, options) => __awaiter(void 0, void 0, void 0, function* () {
53
47
  // Execute the command in the working directory containing the file we are processing; if
54
48
  // the current file is stdin then keep the current working directory.
55
49
  const cwd = cwdForFilename(filename);
56
- options.debug && console.debug(`${exports.BIN}: ${filename}: executing ${command} for replacement...`);
57
- const { stdout } = yield util_1.default.promisify(child_process_1.exec)(command, {
50
+ options.debug && console.debug(`${BIN}: ${filename}: executing ${command} for replacement...`);
51
+ const { stdout } = yield util.promisify(exec)(command, {
58
52
  cwd,
59
53
  });
60
54
  return stdout;
@@ -64,7 +58,7 @@ const replaceExec = (command, filename, options) => __awaiter(void 0, void 0, vo
64
58
  * is assumed to have been read from the given `filename` (or stdin). Collapses newlines
65
59
  * at the end of the output so that there's just one.
66
60
  */
67
- const template = (content, filename, options) => __awaiter(void 0, void 0, void 0, function* () {
61
+ export const template = (content, filename, options) => __awaiter(void 0, void 0, void 0, function* () {
68
62
  filename !== null && filename !== void 0 ? filename : (filename = "/dev/stdin");
69
63
  options !== null && options !== void 0 ? options : (options = {});
70
64
  content = yield replaceAsync(content, VAR_RE, (match) => {
@@ -79,4 +73,3 @@ const template = (content, filename, options) => __awaiter(void 0, void 0, void
79
73
  content = content.replace(/\n+$/m, "\n");
80
74
  return content;
81
75
  });
82
- exports.template = template;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saladplate",
3
- "version": "0.1.1-a",
3
+ "version": "0.1.1",
4
4
  "description": "Very simple templating.",
5
5
  "keywords": [
6
6
  "template",