saladplate 0.1.0 → 0.1.1-a

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