@catladder/pipeline 3.18.0 → 3.19.0

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.
@@ -118,34 +118,9 @@ var __generator = this && this.__generator || function (thisArg, body) {
118
118
  Object.defineProperty(exports, "__esModule", {
119
119
  value: true
120
120
  });
121
- exports.writeYamlfile = exports.yamlStringifyOptions = exports.writeGeneratedFile = exports.getAutoGeneratedHeader = void 0;
121
+ exports.FileWriter = exports.yamlStringifyOptions = void 0;
122
122
  var promises_1 = require("fs/promises");
123
123
  var yaml_1 = require("yaml");
124
- var getAutoGeneratedHeader = function (commentChar) {
125
- return ["-------------------------------------------------", "\uD83D\uDC31 \uD83D\uDD28 This file is generated by catladder", "\uD83D\uDEA8 Do not edit this file manually \uD83D\uDEA8", "-------------------------------------------------"].map(function (line) {
126
- return "".concat(commentChar, " ").concat(line);
127
- }).join("\n").concat("\n");
128
- };
129
- exports.getAutoGeneratedHeader = getAutoGeneratedHeader;
130
- var writeGeneratedFile = function (path_1, content_1, _a) {
131
- return __awaiter(void 0, [path_1, content_1, _a], void 0, function (path, content, _b) {
132
- var commentChar = _b.commentChar;
133
- return __generator(this, function (_c) {
134
- switch (_c.label) {
135
- case 0:
136
- return [4 /*yield*/, (0, promises_1.writeFile)(path,
137
- // need to spread out the jobs, forgot why
138
- [(0, exports.getAutoGeneratedHeader)(commentChar), content].join("\n"), {
139
- encoding: "utf-8"
140
- })];
141
- case 1:
142
- _c.sent();
143
- return [2 /*return*/];
144
- }
145
- });
146
- });
147
- };
148
- exports.writeGeneratedFile = writeGeneratedFile;
149
124
  exports.yamlStringifyOptions = {
150
125
  // prevents colapsing long command statements into multiple lines
151
126
  lineWidth: 0,
@@ -154,19 +129,62 @@ exports.yamlStringifyOptions = {
154
129
  // Better readability when bash commands most often use double quotes
155
130
  singleQuote: true
156
131
  };
157
- var writeYamlfile = function (path, data) {
158
- return __awaiter(void 0, void 0, void 0, function () {
159
- return __generator(this, function (_a) {
160
- switch (_a.label) {
161
- case 0:
162
- return [4 /*yield*/, (0, exports.writeGeneratedFile)(path, (0, yaml_1.stringify)(data, exports.yamlStringifyOptions), {
163
- commentChar: "#"
164
- })];
165
- case 1:
166
- _a.sent();
167
- return [2 /*return*/];
168
- }
132
+ var FileWriter = /** @class */function () {
133
+ function FileWriter(config) {
134
+ this.config = config;
135
+ this.config = config;
136
+ }
137
+ FileWriter.create = function (config) {
138
+ return new FileWriter(config);
139
+ };
140
+ FileWriter.prototype.writeTheFile = function (path, content) {
141
+ return __awaiter(this, void 0, void 0, function () {
142
+ var transformedContent;
143
+ var _a, _b;
144
+ return __generator(this, function (_c) {
145
+ switch (_c.label) {
146
+ case 0:
147
+ return [4 /*yield*/, (_a = this.config.hooks) === null || _a === void 0 ? void 0 : _a.transformFileBeforeWrite({
148
+ filename: path,
149
+ content: content,
150
+ extension: (_b = path.split(".").pop()) !== null && _b !== void 0 ? _b : "",
151
+ path: path
152
+ })];
153
+ case 1:
154
+ transformedContent = _c.sent();
155
+ return [4 /*yield*/, (0, promises_1.writeFile)(path, transformedContent !== null && transformedContent !== void 0 ? transformedContent : content, {
156
+ encoding: "utf-8"
157
+ })];
158
+ case 2:
159
+ _c.sent();
160
+ return [2 /*return*/];
161
+ }
162
+ });
169
163
  });
170
- });
171
- };
172
- exports.writeYamlfile = writeYamlfile;
164
+ };
165
+ FileWriter.prototype.writeGeneratedFile = function (path, content, options) {
166
+ return __awaiter(this, void 0, void 0, function () {
167
+ return __generator(this, function (_a) {
168
+ switch (_a.label) {
169
+ case 0:
170
+ return [4 /*yield*/, this.writeTheFile(path, [this.getAutoGeneratedHeader(options.commentChar), content].join("\n"))];
171
+ case 1:
172
+ _a.sent();
173
+ return [2 /*return*/];
174
+ }
175
+ });
176
+ });
177
+ };
178
+ FileWriter.prototype.writeYamlfile = function (path, data) {
179
+ return this.writeGeneratedFile(path, (0, yaml_1.stringify)(data, exports.yamlStringifyOptions), {
180
+ commentChar: "#"
181
+ });
182
+ };
183
+ FileWriter.prototype.getAutoGeneratedHeader = function (commentChar) {
184
+ return ["-------------------------------------------------", "\uD83D\uDC31 \uD83D\uDD28 This file is generated by catladder", "\uD83D\uDEA8 Do not edit this file manually \uD83D\uDEA8", "-------------------------------------------------"].map(function (line) {
185
+ return "".concat(commentChar, " ").concat(line);
186
+ }).join("\n").concat("\n");
187
+ };
188
+ return FileWriter;
189
+ }();
190
+ exports.FileWriter = FileWriter;