forked from IgniteUI/typedoc-plugin-localization
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
83 lines (69 loc) · 2.78 KB
/
index.ts
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import * as process from 'process';
import * as fs from 'fs-extra';
import { Application } from 'typedoc/dist/lib/application'
import { ConvertComponent } from './components/convert-component';
import { RenderComponenet } from './components/render-component';
import { OptComponent } from './components/options-component';
import { Constants } from './utils/constants';
import { GlobalFuncs } from './utils/global-funcs';
import { HardcodedStrings } from './utils/template-strings';
import { ThemeComponent } from './components/theme-component';
module.exports = (PluginHost: Application) => {
const app = PluginHost.owner;
/**
* Add Options register Component.
*/
app.options.addComponent('options-component', OptComponent);
let startConverter = false;
let startRenderer = false;
const processArgs = process.argv;
/**
* Determines it it is necessary to run Conversion or Render process based on the
* Command line arguments(Options).
*/
processArgs.forEach(command => {
if (command.indexOf(Constants.CONVERT_OPTION) >= 0 ||
command.indexOf(Constants.SHORT_CONVERT_OPTION) >= 0) {
startConverter = true;
}
if (command.indexOf(Constants.RENDER_OPTION) >= 0 ||
command.indexOf(Constants.SHORT_RENDER_OPTION) >= 0) {
startRenderer = true;
}
});
if (startConverter) {
/**
* We set the 'default' value of 'out' option because this option is checked before the converter has been started.
* As we kill the process after the convertion of the json's we or not interested in the value of the 'out' option.
*/
app.options.setValue('out', 'defult');
/**
* Register component responsible for the convertion.
*/
app.converter.addComponent('convert-component', ConvertComponent);
}
if (startRenderer) {
/**
* Register component responsible for the Renderer.
*/
app.renderer.addComponent('render-component', RenderComponenet);
}
/**
* Register theme component.
*/
app.renderer.addComponent('theme-component', ThemeComponent);
registerHardcodedTemplateStrings(processArgs);
}
/**
* Build the Cache containing all localized template strings.
*/
function registerHardcodedTemplateStrings(options) {
const shellStringsFilePath = GlobalFuncs.getCmdLineArgumentValue(options, Constants.TEMPLATE_STRINGS_OPTION);
const local = GlobalFuncs.getCmdLineArgumentValue(options, Constants.LOCALIZE_OPTION);
if (!shellStringsFilePath || !local) {
return;
}
const templateStrings = fs.readJsonSync(shellStringsFilePath);
HardcodedStrings.setLocal(local);
HardcodedStrings.setTemplateStrings(templateStrings);
}