@tenonhq/sincronia-core 0.0.8 → 0.0.9
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/dist/FileUtils.js +232 -0
- package/dist/Logger.js +87 -0
- package/dist/PluginManager.js +125 -0
- package/dist/Watcher.js +54 -0
- package/dist/appUtils.js +445 -0
- package/dist/bootstrap.js +56 -0
- package/dist/commander.js +81 -0
- package/dist/commands.js +277 -0
- package/dist/config.js +287 -0
- package/dist/constants.js +20 -0
- package/dist/defaultOptions.js +52 -0
- package/dist/genericUtils.js +145 -0
- package/dist/gitUtils.js +108 -0
- package/dist/logMessages.js +105 -0
- package/dist/snClient.js +236 -0
- package/dist/tests/cred.test.js +69 -0
- package/dist/tests/example.test.js +6 -0
- package/dist/wizard.js +173 -0
- package/package.json +6 -2
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
|
+
if (k2 === undefined) k2 = k;
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
8
|
+
}) : (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
o[k2] = m[k];
|
|
11
|
+
}));
|
|
12
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
13
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
14
|
+
}) : function(o, v) {
|
|
15
|
+
o["default"] = v;
|
|
16
|
+
});
|
|
17
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
18
|
+
if (mod && mod.__esModule) return mod;
|
|
19
|
+
var result = {};
|
|
20
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
+
__setModuleDefault(result, mod);
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
+
};
|
|
27
|
+
(function (factory) {
|
|
28
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
29
|
+
var v = factory(require, exports);
|
|
30
|
+
if (v !== undefined) module.exports = v;
|
|
31
|
+
}
|
|
32
|
+
else if (typeof define === "function" && define.amd) {
|
|
33
|
+
define(["require", "exports", "./constants", "fs", "path", "./config"], factory);
|
|
34
|
+
}
|
|
35
|
+
})(function (require, exports) {
|
|
36
|
+
"use strict";
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.writeFileForce = exports.writeSNFileForce = exports.writeSNFileIfNotExists = exports.writeBuildFile = exports.summarizeFile = exports.encodedPathsToFilePaths = exports.isValidPath = exports.splitEncodedPaths = exports.getPathsInPath = exports.isDirectory = exports.toAbsolutePath = exports.getFileContextFromPath = exports.getBuildExt = exports.isUnderPath = exports.appendToPath = exports.pathExists = exports.createDirRecursively = exports.writeSNFileCurry = exports.writeManifestFile = exports.SNFileExists = void 0;
|
|
39
|
+
const constants_1 = require("./constants");
|
|
40
|
+
const fs_1 = __importStar(require("fs"));
|
|
41
|
+
const path_1 = __importDefault(require("path"));
|
|
42
|
+
const ConfigManager = __importStar(require("./config"));
|
|
43
|
+
const SNFileExists = (parentDirPath) => async (file) => {
|
|
44
|
+
try {
|
|
45
|
+
const files = await fs_1.promises.readdir(parentDirPath);
|
|
46
|
+
const reg = new RegExp(`${file.name}\..*$`);
|
|
47
|
+
return !!files.find((f) => reg.test(f));
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.SNFileExists = SNFileExists;
|
|
54
|
+
const writeManifestFile = async (man) => {
|
|
55
|
+
return fs_1.promises.writeFile(ConfigManager.getManifestPath(), JSON.stringify(man, null, 2));
|
|
56
|
+
};
|
|
57
|
+
exports.writeManifestFile = writeManifestFile;
|
|
58
|
+
const writeSNFileCurry = (checkExists) => async (file, parentPath) => {
|
|
59
|
+
let { name, type, content = "" } = file;
|
|
60
|
+
// content can sometimes be null
|
|
61
|
+
if (!content) {
|
|
62
|
+
content = "";
|
|
63
|
+
}
|
|
64
|
+
const write = async () => {
|
|
65
|
+
const fullPath = path_1.default.join(parentPath, `${name}.${type}`);
|
|
66
|
+
return await fs_1.promises.writeFile(fullPath, content);
|
|
67
|
+
};
|
|
68
|
+
if (checkExists) {
|
|
69
|
+
const exists = await (0, exports.SNFileExists)(parentPath)(file);
|
|
70
|
+
if (!exists) {
|
|
71
|
+
await write();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
write();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
exports.writeSNFileCurry = writeSNFileCurry;
|
|
79
|
+
const createDirRecursively = async (path) => {
|
|
80
|
+
await fs_1.promises.mkdir(path, { recursive: true });
|
|
81
|
+
};
|
|
82
|
+
exports.createDirRecursively = createDirRecursively;
|
|
83
|
+
const pathExists = async (path) => {
|
|
84
|
+
try {
|
|
85
|
+
await fs_1.promises.access(path, fs_1.default.constants.F_OK);
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
exports.pathExists = pathExists;
|
|
93
|
+
const appendToPath = (prefix) => (suffix) => path_1.default.join(prefix, suffix);
|
|
94
|
+
exports.appendToPath = appendToPath;
|
|
95
|
+
/**
|
|
96
|
+
* Detects if a path is under a parent directory
|
|
97
|
+
* @param parentPath full path to parent directory
|
|
98
|
+
* @param potentialChildPath full path to child directory
|
|
99
|
+
*/
|
|
100
|
+
const isUnderPath = (parentPath, potentialChildPath) => {
|
|
101
|
+
const parentTokens = parentPath.split(path_1.default.sep);
|
|
102
|
+
const childTokens = potentialChildPath.split(path_1.default.sep);
|
|
103
|
+
return parentTokens.every((token, index) => token === childTokens[index]);
|
|
104
|
+
};
|
|
105
|
+
exports.isUnderPath = isUnderPath;
|
|
106
|
+
const getFileExtension = (filePath) => {
|
|
107
|
+
try {
|
|
108
|
+
return "." + path_1.default.basename(filePath).split(".").slice(1).join(".");
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
return "";
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const getBuildExt = (table, recordName, field) => {
|
|
115
|
+
const manifest = ConfigManager.getManifest();
|
|
116
|
+
if (!manifest) {
|
|
117
|
+
throw new Error("Failed to retrieve manifest");
|
|
118
|
+
}
|
|
119
|
+
const files = manifest.tables[table].records[recordName].files;
|
|
120
|
+
const file = files.find((f) => f.name === field);
|
|
121
|
+
if (!file) {
|
|
122
|
+
throw new Error("Unable to find file");
|
|
123
|
+
}
|
|
124
|
+
return file.type;
|
|
125
|
+
};
|
|
126
|
+
exports.getBuildExt = getBuildExt;
|
|
127
|
+
const getTargetFieldFromPath = (filePath, table, ext) => {
|
|
128
|
+
return table === "sys_atf_step"
|
|
129
|
+
? "inputs.script"
|
|
130
|
+
: path_1.default.basename(filePath, ext);
|
|
131
|
+
};
|
|
132
|
+
const getFileContextFromPath = (filePath) => {
|
|
133
|
+
const ext = getFileExtension(filePath);
|
|
134
|
+
const [tableName, recordName] = path_1.default
|
|
135
|
+
.dirname(filePath)
|
|
136
|
+
.split(path_1.default.sep)
|
|
137
|
+
.slice(-2);
|
|
138
|
+
const targetField = getTargetFieldFromPath(filePath, tableName, ext);
|
|
139
|
+
const manifest = ConfigManager.getManifest();
|
|
140
|
+
if (!manifest) {
|
|
141
|
+
throw new Error("No manifest has been loaded!");
|
|
142
|
+
}
|
|
143
|
+
const { tables, scope } = manifest;
|
|
144
|
+
try {
|
|
145
|
+
const { records } = tables[tableName];
|
|
146
|
+
const record = records[recordName];
|
|
147
|
+
const { files, sys_id } = record;
|
|
148
|
+
const field = files.find((file) => file.name === targetField);
|
|
149
|
+
if (!field) {
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
filePath,
|
|
154
|
+
ext,
|
|
155
|
+
sys_id,
|
|
156
|
+
name: recordName,
|
|
157
|
+
scope,
|
|
158
|
+
tableName,
|
|
159
|
+
targetField,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
catch (e) {
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
exports.getFileContextFromPath = getFileContextFromPath;
|
|
167
|
+
const toAbsolutePath = (p) => path_1.default.isAbsolute(p) ? p : path_1.default.join(process.cwd(), p);
|
|
168
|
+
exports.toAbsolutePath = toAbsolutePath;
|
|
169
|
+
const isDirectory = async (p) => {
|
|
170
|
+
const stats = await fs_1.promises.stat(p);
|
|
171
|
+
return stats.isDirectory();
|
|
172
|
+
};
|
|
173
|
+
exports.isDirectory = isDirectory;
|
|
174
|
+
const getPathsInPath = async (p) => {
|
|
175
|
+
if (!(0, exports.isUnderPath)(ConfigManager.getSourcePath(), p) &&
|
|
176
|
+
!(0, exports.isUnderPath)(ConfigManager.getBuildPath(), p)) {
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
const isDir = await (0, exports.isDirectory)(p);
|
|
180
|
+
if (!isDir) {
|
|
181
|
+
return [p];
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
const childPaths = await fs_1.promises.readdir(p);
|
|
185
|
+
const pathPromises = childPaths.map((childPath) => (0, exports.getPathsInPath)(path_1.default.resolve(p, childPath)));
|
|
186
|
+
const stackedPaths = await Promise.all(pathPromises);
|
|
187
|
+
return stackedPaths.flat();
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
exports.getPathsInPath = getPathsInPath;
|
|
191
|
+
const splitEncodedPaths = (encodedPaths) => encodedPaths.split(constants_1.PATH_DELIMITER).filter((p) => p && p !== "");
|
|
192
|
+
exports.splitEncodedPaths = splitEncodedPaths;
|
|
193
|
+
const isValidPath = async (path) => {
|
|
194
|
+
return (0, exports.pathExists)(path);
|
|
195
|
+
};
|
|
196
|
+
exports.isValidPath = isValidPath;
|
|
197
|
+
const encodedPathsToFilePaths = async (encodedPaths) => {
|
|
198
|
+
const pathSplits = (0, exports.splitEncodedPaths)(encodedPaths);
|
|
199
|
+
const validChecks = await Promise.all(pathSplits.map(exports.isValidPath));
|
|
200
|
+
const validSplits = pathSplits.filter((_, index) => validChecks[index]);
|
|
201
|
+
const splitPaths = await Promise.all(validSplits.map(exports.getPathsInPath));
|
|
202
|
+
const deDupedPaths = splitPaths.flat().reduce((acc, cur) => {
|
|
203
|
+
acc.add(cur);
|
|
204
|
+
return acc;
|
|
205
|
+
}, new Set());
|
|
206
|
+
return Array.from(deDupedPaths);
|
|
207
|
+
};
|
|
208
|
+
exports.encodedPathsToFilePaths = encodedPathsToFilePaths;
|
|
209
|
+
const summarizeFile = (ctx) => {
|
|
210
|
+
const { tableName, name: recordName, sys_id } = ctx;
|
|
211
|
+
return `${tableName}/${recordName}/${sys_id}`;
|
|
212
|
+
};
|
|
213
|
+
exports.summarizeFile = summarizeFile;
|
|
214
|
+
const writeBuildFile = async (folderPath, newPath, fileContents) => {
|
|
215
|
+
try {
|
|
216
|
+
await fs_1.promises.access(folderPath, fs_1.default.constants.F_OK);
|
|
217
|
+
}
|
|
218
|
+
catch (e) {
|
|
219
|
+
await fs_1.promises.mkdir(folderPath, { recursive: true });
|
|
220
|
+
}
|
|
221
|
+
try {
|
|
222
|
+
await fs_1.promises.writeFile(newPath, fileContents);
|
|
223
|
+
}
|
|
224
|
+
catch (e) {
|
|
225
|
+
throw e;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
exports.writeBuildFile = writeBuildFile;
|
|
229
|
+
exports.writeSNFileIfNotExists = (0, exports.writeSNFileCurry)(true);
|
|
230
|
+
exports.writeSNFileForce = (0, exports.writeSNFileCurry)(false);
|
|
231
|
+
exports.writeFileForce = fs_1.promises.writeFile;
|
|
232
|
+
});
|
package/dist/Logger.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
|
+
if (k2 === undefined) k2 = k;
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
8
|
+
}) : (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
o[k2] = m[k];
|
|
11
|
+
}));
|
|
12
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
13
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
14
|
+
}) : function(o, v) {
|
|
15
|
+
o["default"] = v;
|
|
16
|
+
});
|
|
17
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
18
|
+
if (mod && mod.__esModule) return mod;
|
|
19
|
+
var result = {};
|
|
20
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
+
__setModuleDefault(result, mod);
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
+
};
|
|
27
|
+
(function (factory) {
|
|
28
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
29
|
+
var v = factory(require, exports);
|
|
30
|
+
if (v !== undefined) module.exports = v;
|
|
31
|
+
}
|
|
32
|
+
else if (typeof define === "function" && define.amd) {
|
|
33
|
+
define(["require", "exports", "winston", "chalk"], factory);
|
|
34
|
+
}
|
|
35
|
+
})(function (require, exports) {
|
|
36
|
+
"use strict";
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.logger = void 0;
|
|
39
|
+
const winston_1 = __importStar(require("winston"));
|
|
40
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
41
|
+
class SincLogger {
|
|
42
|
+
constructor() {
|
|
43
|
+
this.logger = winston_1.default.createLogger(this.genLoggerOpts());
|
|
44
|
+
}
|
|
45
|
+
setLogLevel(level) {
|
|
46
|
+
this.logger = winston_1.default.createLogger(this.genLoggerOpts(level));
|
|
47
|
+
}
|
|
48
|
+
getLogLevel() {
|
|
49
|
+
return this.logger.level;
|
|
50
|
+
}
|
|
51
|
+
genLoggerOpts(level = "info") {
|
|
52
|
+
return {
|
|
53
|
+
format: winston_1.format.printf(info => {
|
|
54
|
+
return `${info.message}`;
|
|
55
|
+
}),
|
|
56
|
+
level,
|
|
57
|
+
transports: [new winston_1.transports.Console()]
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
info(text) {
|
|
61
|
+
this.logger.info(chalk_1.default.blue(text));
|
|
62
|
+
}
|
|
63
|
+
error(text) {
|
|
64
|
+
this.logger.error(chalk_1.default.red(text));
|
|
65
|
+
}
|
|
66
|
+
warn(text) {
|
|
67
|
+
this.logger.warn(chalk_1.default.yellow(text));
|
|
68
|
+
}
|
|
69
|
+
success(text) {
|
|
70
|
+
this.logger.info(chalk_1.default.green(text));
|
|
71
|
+
}
|
|
72
|
+
verbose(text) {
|
|
73
|
+
this.logger.verbose(text);
|
|
74
|
+
}
|
|
75
|
+
debug(text) {
|
|
76
|
+
this.logger.debug(text);
|
|
77
|
+
}
|
|
78
|
+
silly(text) {
|
|
79
|
+
this.logger.silly(text);
|
|
80
|
+
}
|
|
81
|
+
getInternalLogger() {
|
|
82
|
+
return this.logger;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const loggerInst = new SincLogger();
|
|
86
|
+
exports.logger = loggerInst;
|
|
87
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
|
+
if (k2 === undefined) k2 = k;
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
8
|
+
}) : (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
o[k2] = m[k];
|
|
11
|
+
}));
|
|
12
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
13
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
14
|
+
}) : function(o, v) {
|
|
15
|
+
o["default"] = v;
|
|
16
|
+
});
|
|
17
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
18
|
+
if (mod && mod.__esModule) return mod;
|
|
19
|
+
var result = {};
|
|
20
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
+
__setModuleDefault(result, mod);
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
+
};
|
|
27
|
+
(function (factory) {
|
|
28
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
29
|
+
var v = factory(require, exports);
|
|
30
|
+
if (v !== undefined) module.exports = v;
|
|
31
|
+
}
|
|
32
|
+
else if (typeof define === "function" && define.amd) {
|
|
33
|
+
define(["require", "exports", "./config", "fs", "path"], factory);
|
|
34
|
+
}
|
|
35
|
+
})(function (require, exports) {
|
|
36
|
+
"use strict";
|
|
37
|
+
var __syncRequire = typeof module === "object" && typeof module.exports === "object";
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const ConfigManager = __importStar(require("./config"));
|
|
40
|
+
const fs_1 = __importDefault(require("fs"));
|
|
41
|
+
const path_1 = __importDefault(require("path"));
|
|
42
|
+
const fsp = fs_1.default.promises;
|
|
43
|
+
class PluginManager {
|
|
44
|
+
constructor() {
|
|
45
|
+
this.pluginRules = [];
|
|
46
|
+
}
|
|
47
|
+
async loadPluginConfig() {
|
|
48
|
+
let conf = ConfigManager.getConfig();
|
|
49
|
+
if (conf && conf.rules) {
|
|
50
|
+
this.pluginRules = conf.rules;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
determinePlugins(context) {
|
|
54
|
+
let plugins = [];
|
|
55
|
+
for (let rule of this.pluginRules) {
|
|
56
|
+
let reg = rule.match;
|
|
57
|
+
if (reg.test(context.filePath)) {
|
|
58
|
+
plugins = rule.plugins;
|
|
59
|
+
//only match first rule
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return plugins;
|
|
64
|
+
}
|
|
65
|
+
async runPlugins(plugins, context, content) {
|
|
66
|
+
try {
|
|
67
|
+
let output = content;
|
|
68
|
+
for (let pConfig of plugins) {
|
|
69
|
+
let pluginPath = path_1.default.join(ConfigManager.getRootDir(), "node_modules", pConfig.name);
|
|
70
|
+
let plugin = await (__syncRequire ? Promise.resolve(`${pluginPath}`).then(s => __importStar(require(s))) : new Promise((resolve_1, reject_1) => { require([pluginPath], resolve_1, reject_1); }).then(__importStar));
|
|
71
|
+
let results = await plugin.run(context, output, pConfig.options);
|
|
72
|
+
if (!results.success) {
|
|
73
|
+
return {
|
|
74
|
+
success: false,
|
|
75
|
+
content: "",
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
output = results.output;
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
success: true,
|
|
82
|
+
content: output,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
throw e;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async processFile(context, content) {
|
|
90
|
+
const plugins = this.determinePlugins(context);
|
|
91
|
+
if (plugins.length > 0) {
|
|
92
|
+
try {
|
|
93
|
+
const pluginResults = await this.runPlugins(plugins, context, content);
|
|
94
|
+
if (pluginResults.success) {
|
|
95
|
+
return pluginResults.content;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
throw new Error(`Failed to build ${context.tableName}=>${context.sys_id}!`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
throw e;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return content;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async getFinalFileContents(context, processFile = true) {
|
|
110
|
+
const { filePath } = context;
|
|
111
|
+
try {
|
|
112
|
+
const contents = await fsp.readFile(filePath, "utf-8");
|
|
113
|
+
if (processFile) {
|
|
114
|
+
await this.loadPluginConfig();
|
|
115
|
+
return await this.processFile(context, contents);
|
|
116
|
+
}
|
|
117
|
+
return contents;
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
throw e;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.default = new PluginManager();
|
|
125
|
+
});
|
package/dist/Watcher.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
2
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
3
|
+
};
|
|
4
|
+
(function (factory) {
|
|
5
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
6
|
+
var v = factory(require, exports);
|
|
7
|
+
if (v !== undefined) module.exports = v;
|
|
8
|
+
}
|
|
9
|
+
else if (typeof define === "function" && define.amd) {
|
|
10
|
+
define(["require", "exports", "chokidar", "./logMessages", "lodash", "./FileUtils", "./appUtils"], factory);
|
|
11
|
+
}
|
|
12
|
+
})(function (require, exports) {
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.stopWatching = exports.startWatching = void 0;
|
|
16
|
+
const chokidar_1 = __importDefault(require("chokidar"));
|
|
17
|
+
const logMessages_1 = require("./logMessages");
|
|
18
|
+
const lodash_1 = require("lodash");
|
|
19
|
+
const FileUtils_1 = require("./FileUtils");
|
|
20
|
+
const appUtils_1 = require("./appUtils");
|
|
21
|
+
const DEBOUNCE_MS = 300;
|
|
22
|
+
let pushQueue = [];
|
|
23
|
+
let watcher = undefined;
|
|
24
|
+
const processQueue = (0, lodash_1.debounce)(async () => {
|
|
25
|
+
if (pushQueue.length > 0) {
|
|
26
|
+
//dedupe pushes
|
|
27
|
+
const toProcess = Array.from(new Set([...pushQueue]));
|
|
28
|
+
pushQueue = [];
|
|
29
|
+
const fileContexts = toProcess
|
|
30
|
+
.map(FileUtils_1.getFileContextFromPath)
|
|
31
|
+
.filter((ctx) => !!ctx);
|
|
32
|
+
const buildables = (0, appUtils_1.groupAppFiles)(fileContexts);
|
|
33
|
+
const updateResults = await (0, appUtils_1.pushFiles)(buildables);
|
|
34
|
+
updateResults.forEach((res, index) => {
|
|
35
|
+
(0, logMessages_1.logFilePush)(fileContexts[index], res);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}, DEBOUNCE_MS);
|
|
39
|
+
function startWatching(directory) {
|
|
40
|
+
watcher = chokidar_1.default.watch(directory);
|
|
41
|
+
watcher.on("change", fileChanged);
|
|
42
|
+
}
|
|
43
|
+
exports.startWatching = startWatching;
|
|
44
|
+
async function fileChanged(path) {
|
|
45
|
+
pushQueue.push(path);
|
|
46
|
+
processQueue();
|
|
47
|
+
}
|
|
48
|
+
function stopWatching() {
|
|
49
|
+
if (watcher) {
|
|
50
|
+
watcher.close();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.stopWatching = stopWatching;
|
|
54
|
+
});
|