-
Notifications
You must be signed in to change notification settings - Fork 31
/
index.js
executable file
·43 lines (35 loc) · 1.32 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const { getOptions: getCLIOptions } = require('codemod-cli');
const { getTelemetry } = require('ember-codemods-telemetry-helpers');
const path = require('path');
const fs = require('fs');
const transform = require('./transform');
const { getInvokableData } = require('./telemetry/invokable');
function getOptions() {
let options = {};
let cliOptions = getCLIOptions();
if (cliOptions.config) {
let filePath = path.join(process.cwd(), cliOptions.config);
let config = JSON.parse(fs.readFileSync(filePath));
if (config.helpers) {
options.helpers = config.helpers;
}
if (config.skipAttributesThatMatchRegex) {
options.skipAttributesThatMatchRegex = config.skipAttributesThatMatchRegex;
}
if (config.skipFilesThatMatchRegex) {
options.skipFilesThatMatchRegex = new RegExp(config.skipFilesThatMatchRegex);
}
options.skipBuiltInComponents = !!config.skipBuiltInComponents;
}
return options;
}
module.exports = function(file) {
let invokableData = getInvokableData(getTelemetry());
try {
return transform(file, getOptions(), invokableData);
} catch (e) {
throw new Error(
`Transformation errored on file ${file.path}. Reason ${e}. Please report this in https://github.com/ember-codemods/ember-angle-brackets-codemod/issues\n\nStack trace:\n${e.stack}`
);
}
};