@webos-tools/cli 3.0.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.
- package/.eslintignore +1 -0
- package/.eslintrc.js +52 -0
- package/APIs.js +79 -0
- package/CHANGELOG.md +110 -0
- package/LICENSE +201 -0
- package/README.md +218 -0
- package/bin/ares-config.js +199 -0
- package/bin/ares-device-info.js +30 -0
- package/bin/ares-device.js +219 -0
- package/bin/ares-generate.js +270 -0
- package/bin/ares-inspect.js +179 -0
- package/bin/ares-install.js +223 -0
- package/bin/ares-launch.js +318 -0
- package/bin/ares-log.js +255 -0
- package/bin/ares-novacom.js +223 -0
- package/bin/ares-package.js +336 -0
- package/bin/ares-pull.js +156 -0
- package/bin/ares-push.js +155 -0
- package/bin/ares-server.js +174 -0
- package/bin/ares-setup-device.js +520 -0
- package/bin/ares-shell.js +132 -0
- package/bin/ares.js +166 -0
- package/files/conf/ares.json +49 -0
- package/files/conf/command-service.json +73 -0
- package/files/conf/config.json +22 -0
- package/files/conf/ipk.json +30 -0
- package/files/conf/novacom-devices.json +35 -0
- package/files/conf/query/query-app.json +14 -0
- package/files/conf/query/query-hosted.json +18 -0
- package/files/conf/query/query-package.json +10 -0
- package/files/conf/query/query-service.json +6 -0
- package/files/conf/sdk.json +8 -0
- package/files/conf/template.json +57 -0
- package/files/conf/webos_emul +27 -0
- package/files/conf-base/env/sdk-ose.json +8 -0
- package/files/conf-base/env/sdk-tv.json +8 -0
- package/files/conf-base/profile/config-ose.json +21 -0
- package/files/conf-base/profile/config-tv.json +22 -0
- package/files/conf-base/query/query-app.json +14 -0
- package/files/conf-base/query/query-hosted.json +18 -0
- package/files/conf-base/query/query-package.json +10 -0
- package/files/conf-base/query/query-service.json +6 -0
- package/files/conf-base/template-conf/ose-templates.json +67 -0
- package/files/conf-base/template-conf/tv-sdk-templates.json +57 -0
- package/files/help/ares-config.help +43 -0
- package/files/help/ares-device.help +94 -0
- package/files/help/ares-generate.help +65 -0
- package/files/help/ares-inspect.help +70 -0
- package/files/help/ares-install.help +90 -0
- package/files/help/ares-launch.help +100 -0
- package/files/help/ares-log-pmlogd.help +84 -0
- package/files/help/ares-log.help +101 -0
- package/files/help/ares-novacom.help +68 -0
- package/files/help/ares-package.help +101 -0
- package/files/help/ares-pull.help +38 -0
- package/files/help/ares-push.help +38 -0
- package/files/help/ares-server.help +39 -0
- package/files/help/ares-setup-device.help +75 -0
- package/files/help/ares-shell.help +42 -0
- package/files/help/ares.help +47 -0
- package/files/help/readme.help +23 -0
- package/files/schema/ApplicationDescription.schema +319 -0
- package/files/schema/NovacomDevices.schema +61 -0
- package/files/templates/ose-sdk-templates/appinfo/appinfo.json +10 -0
- package/files/templates/ose-sdk-templates/bootplate-web/index.html +88 -0
- package/files/templates/ose-sdk-templates/hosted-webapp/index.html +14 -0
- package/files/templates/ose-sdk-templates/icon/icon.png +0 -0
- package/files/templates/ose-sdk-templates/js-service/helloclient.js +31 -0
- package/files/templates/ose-sdk-templates/js-service/helloworld_webos_service.js +188 -0
- package/files/templates/ose-sdk-templates/qml-app/main.qml +68 -0
- package/files/templates/ose-sdk-templates/qmlappinfo/appinfo.json +10 -0
- package/files/templates/ose-sdk-templates/serviceinfo/package.json +11 -0
- package/files/templates/ose-sdk-templates/serviceinfo/services.json +8 -0
- package/files/templates/tv-sdk-templates/appinfo/appinfo.json +10 -0
- package/files/templates/tv-sdk-templates/bootplate-web/index.html +58 -0
- package/files/templates/tv-sdk-templates/bootplate-web/webOSTVjs-1.2.4/LICENSE-2.0.txt +202 -0
- package/files/templates/tv-sdk-templates/bootplate-web/webOSTVjs-1.2.4/webOSTV-dev.js +1 -0
- package/files/templates/tv-sdk-templates/bootplate-web/webOSTVjs-1.2.4/webOSTV.js +1 -0
- package/files/templates/tv-sdk-templates/hosted-webapp/index.html +14 -0
- package/files/templates/tv-sdk-templates/js-service/helloworld_service.js +37 -0
- package/files/templates/tv-sdk-templates/packageinfo/packageinfo.json +4 -0
- package/files/templates/tv-sdk-templates/serviceinfo/package.json +11 -0
- package/files/templates/tv-sdk-templates/serviceinfo/services.json +8 -0
- package/files/templates/tv-sdk-templates/webicon/icon.png +0 -0
- package/files/templates/tv-sdk-templates/webicon/largeIcon.png +0 -0
- package/lib/base/ares.html +40 -0
- package/lib/base/cli-appdata.js +289 -0
- package/lib/base/cli-control.js +44 -0
- package/lib/base/common-tools.js +29 -0
- package/lib/base/error-handler.js +265 -0
- package/lib/base/file-watcher.js +155 -0
- package/lib/base/help-format.js +147 -0
- package/lib/base/luna.js +178 -0
- package/lib/base/novacom.js +1191 -0
- package/lib/base/sdkenv.js +59 -0
- package/lib/base/server.js +137 -0
- package/lib/base/setup-device.js +324 -0
- package/lib/base/version-tools.js +79 -0
- package/lib/com.sdk.ares.hostedapp.ipk +0 -0
- package/lib/device.js +1419 -0
- package/lib/generator.js +377 -0
- package/lib/inspect.js +494 -0
- package/lib/install.js +463 -0
- package/lib/launch.js +605 -0
- package/lib/log.js +584 -0
- package/lib/package.js +2129 -0
- package/lib/pull.js +231 -0
- package/lib/pusher.js +210 -0
- package/lib/session.js +74 -0
- package/lib/shell.js +193 -0
- package/lib/tar-filter-pack.js +62 -0
- package/lib/util/copy.js +31 -0
- package/lib/util/createFileName.js +40 -0
- package/lib/util/eof.js +30 -0
- package/lib/util/json.js +63 -0
- package/lib/util/merge.js +14 -0
- package/lib/util/objclone.js +40 -0
- package/lib/util/spinner.js +37 -0
- package/npm-shrinkwrap.json +85 -0
- package/package.json +98 -0
- package/spec/helpers/reporter.js +65 -0
- package/spec/jsSpecs/apiTest/generator.spec.js +372 -0
- package/spec/jsSpecs/apiTest/inspector.spec.js +89 -0
- package/spec/jsSpecs/apiTest/installer.spec.js +67 -0
- package/spec/jsSpecs/apiTest/launcher.spec.js +150 -0
- package/spec/jsSpecs/apiTest/packager.spec.js +194 -0
- package/spec/jsSpecs/apiTest/puller.spec.js +101 -0
- package/spec/jsSpecs/apiTest/pusher.spec.js +103 -0
- package/spec/jsSpecs/apiTest/server.spec.js +115 -0
- package/spec/jsSpecs/apiTest/setupDevice.spec.js +93 -0
- package/spec/jsSpecs/apiTest/shell.spec.js +49 -0
- package/spec/jsSpecs/ares-config.spec.js +78 -0
- package/spec/jsSpecs/ares-device.spec.js +443 -0
- package/spec/jsSpecs/ares-generate.spec.js +397 -0
- package/spec/jsSpecs/ares-inspect.spec.js +252 -0
- package/spec/jsSpecs/ares-install.spec.js +150 -0
- package/spec/jsSpecs/ares-launch.spec.js +301 -0
- package/spec/jsSpecs/ares-log.spec.js +824 -0
- package/spec/jsSpecs/ares-novacom.spec.js +149 -0
- package/spec/jsSpecs/ares-package.spec.js +1211 -0
- package/spec/jsSpecs/ares-pull.spec.js +157 -0
- package/spec/jsSpecs/ares-push.spec.js +146 -0
- package/spec/jsSpecs/ares-server.spec.js +160 -0
- package/spec/jsSpecs/ares-setup-device.spec.js +281 -0
- package/spec/jsSpecs/ares-shell.spec.js +220 -0
- package/spec/jsSpecs/ares.spec.js +83 -0
- package/spec/jsSpecs/common-spec.js +169 -0
- package/spec/support/jasmine.json +22 -0
- package/spec/tempFiles/com.jasmine.native.app_0.0.1_arm.ipk +0 -0
- package/spec/tempFiles/com.jasmine.native.app_0.0.1_x86.ipk +0 -0
- package/spec/tempFiles/com.jasmine.web.app_0.0.1_all.ipk +0 -0
- package/spec/tempFiles/com.logtest.web.app_1.0.0_all.ipk +0 -0
- package/spec/tempFiles/copyFiles/helloFile.txt +1 -0
- package/spec/tempFiles/copyFiles/testFile.txt +1 -0
- package/spec/tempFiles/ipks/com.sample.echo_0.0.1_all.ipk +0 -0
- package/spec/tempFiles/ipks/com.web.app_1.0.0_all.ipk +0 -0
- package/spec/tempFiles/nativeApp/auto/pkg_arm64/GLES2 +0 -0
- package/spec/tempFiles/nativeApp/auto/pkg_arm64/appinfo.json +9 -0
- package/spec/tempFiles/nativeApp/auto/pkg_arm64/icon.png +0 -0
- package/spec/tempFiles/nativeApp/auto/pkg_arm64/largeIcon.png +0 -0
- package/spec/tempFiles/nativeApp/ose/pkg_arm/Hello +0 -0
- package/spec/tempFiles/nativeApp/ose/pkg_arm/appinfo.json +9 -0
- package/spec/tempFiles/nativeApp/ose/pkg_arm/icon.png +0 -0
- package/spec/tempFiles/nativeApp/ose/pkg_arm/largeIcon.png +0 -0
- package/spec/tempFiles/nativeApp/ose/pkg_arm/package.properties +2 -0
- package/spec/tempFiles/nativeApp/oseEmul/pkg_x86/Hello +0 -0
- package/spec/tempFiles/nativeApp/oseEmul/pkg_x86/appinfo.json +9 -0
- package/spec/tempFiles/nativeApp/oseEmul/pkg_x86/icon.png +0 -0
- package/spec/tempFiles/nativeApp/oseEmul/pkg_x86/largeIcon.png +0 -0
- package/spec/tempFiles/nativeApp/rsi/pkg_x86/GLES2 +0 -0
- package/spec/tempFiles/nativeApp/rsi/pkg_x86/appinfo.json +9 -0
- package/spec/tempFiles/nativeApp/rsi/pkg_x86/icon.png +0 -0
- package/spec/tempFiles/nativeApp/rsi/pkg_x86/largeIcon.png +0 -0
- package/spec/tempFiles/sign/sign.crt +32 -0
- package/spec/tempFiles/sign/signPriv.key +52 -0
- package/spec/test_data/ares-generate.json +41 -0
- package/spec/test_data/ares.json +33 -0
package/lib/generator.js
ADDED
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2020-2024 LG Electronics Inc.
|
|
5
|
+
*
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const promise = require('bluebird'),
|
|
10
|
+
Table = require('easy-table'),
|
|
11
|
+
fs = promise.promisifyAll(require('fs-extra')),
|
|
12
|
+
log = require('npmlog'),
|
|
13
|
+
path = require('path'),
|
|
14
|
+
errHndl = require('./base/error-handler'),
|
|
15
|
+
copyToDirAsync = require('./util/copy').copyToDirAsync,
|
|
16
|
+
readJsonSync = require('./util/json').readJsonSync,
|
|
17
|
+
merge = require('./util/merge');
|
|
18
|
+
|
|
19
|
+
const templatePath = path.join(__dirname, '/../files/conf/', 'template.json');
|
|
20
|
+
let templates;
|
|
21
|
+
|
|
22
|
+
log.heading = 'generator';
|
|
23
|
+
log.level = 'warn';
|
|
24
|
+
|
|
25
|
+
function Generator() {
|
|
26
|
+
if (templatePath) {
|
|
27
|
+
const cliPath = path.join(__dirname, '..');
|
|
28
|
+
let contents = fs.readFileSync(templatePath);
|
|
29
|
+
contents = contents.toString().replace(/\$cli-root/gi, cliPath).replace(/\\/g,'/');
|
|
30
|
+
templates = JSON.parse(contents);
|
|
31
|
+
} else {
|
|
32
|
+
templates = null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
Generator.prototype.showTemplates = function(listType, next) {
|
|
37
|
+
const templateList = this.getTmpl(),
|
|
38
|
+
table = new Table(),
|
|
39
|
+
_displayType = {
|
|
40
|
+
"webapp": "Web App",
|
|
41
|
+
"nativeapp": "Native App",
|
|
42
|
+
"webappinfo": "Web App Info",
|
|
43
|
+
"nativeappinfo": "Native App Info",
|
|
44
|
+
"jsservice": "JS Service",
|
|
45
|
+
"nativeservice": "Native Service",
|
|
46
|
+
"jsserviceinfo": "JS Service Info",
|
|
47
|
+
"nativeserviceinfo": "Native Service Info",
|
|
48
|
+
"icon": "Icon",
|
|
49
|
+
"library": "Library",
|
|
50
|
+
"packageinfo": "Package Info",
|
|
51
|
+
"qmlapp": "QML App",
|
|
52
|
+
"qmlappinfo": "QML App Info"
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
for (const name in templateList) {
|
|
56
|
+
if (templateList[name].hide === true || !templateList[name].type) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const isDefault = (templateList[name].default) ? "(default) " : "",
|
|
60
|
+
type = _displayType[templateList[name].type] || templateList[name].type;
|
|
61
|
+
|
|
62
|
+
if (listType && ["true", "false", true, false].indexOf(listType) === -1) {
|
|
63
|
+
if (templateList[name].type &&
|
|
64
|
+
(templateList[name].type.match(new RegExp(listType+"$","gi")) === null)) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
table.cell('ID', name);
|
|
69
|
+
table.cell('Project Type', type);
|
|
70
|
+
table.cell('Description', isDefault + templateList[name].description);
|
|
71
|
+
table.newRow();
|
|
72
|
+
}
|
|
73
|
+
return next(null, {msg: table.toString()});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
Generator.prototype.generate = function(options, next) {
|
|
77
|
+
// For API
|
|
78
|
+
if (!options.tmplName) {
|
|
79
|
+
return next(errHndl.getErrMsg("EMPTY_VALUE", "TEMPLATE"));
|
|
80
|
+
}
|
|
81
|
+
if (!options.out) {
|
|
82
|
+
return next(errHndl.getErrMsg("EMPTY_VALUE", "APP_DIR"));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const tmplName = options.tmplName,
|
|
86
|
+
pkginfo = options.pkginfo || {},
|
|
87
|
+
svcinfo = options.svcinfo || {},
|
|
88
|
+
svcName = options.svcName,
|
|
89
|
+
out = options.out,
|
|
90
|
+
dest = path.resolve(out),
|
|
91
|
+
existDir = this.existOutDir(dest),
|
|
92
|
+
templateList = this.getTmpl(),
|
|
93
|
+
template = templateList[tmplName];
|
|
94
|
+
let appinfo = options.appinfo || {};
|
|
95
|
+
|
|
96
|
+
// For API
|
|
97
|
+
if (!template) {
|
|
98
|
+
return next(errHndl.getErrMsg("INVALID_VALUE", "TEMPLATE", options.tmplName));
|
|
99
|
+
}
|
|
100
|
+
if (!options.overwrite && existDir) {
|
|
101
|
+
return next(errHndl.getErrMsg("NOT_OVERWRITE_DIR", dest));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (template.metadata && template.metadata.data && typeof template.metadata.data === 'object') {
|
|
105
|
+
appinfo = merge(appinfo, template.metadata.data);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
promise.resolve()
|
|
109
|
+
.then(function() {
|
|
110
|
+
// If props is not exist, this input from query-mode
|
|
111
|
+
// If props is exist, this input from props
|
|
112
|
+
// Check argv.query, argv["no-query"], options.props and conditional statement.
|
|
113
|
+
if (template.type.match(/(app$|appinfo$)/)) {
|
|
114
|
+
parsePropArgs(options.props, appinfo);
|
|
115
|
+
} else if (template.type.match(/(service$|serviceinfo$)/)) {
|
|
116
|
+
parsePropArgs(options.props, svcinfo);
|
|
117
|
+
} else if (template.type.match(/(package$|packageinfo$)/)) {
|
|
118
|
+
parsePropArgs(options.props, pkginfo);
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
.then(function() {
|
|
122
|
+
if (svcName) {
|
|
123
|
+
svcinfo.id = svcName;
|
|
124
|
+
svcinfo.services = [{
|
|
125
|
+
"name": svcName
|
|
126
|
+
}];
|
|
127
|
+
} else if (!svcName && svcinfo && !!svcinfo.id) {
|
|
128
|
+
svcinfo.services = [{
|
|
129
|
+
"name": svcinfo.id
|
|
130
|
+
}];
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
return promise.resolve()
|
|
135
|
+
.then(function() {
|
|
136
|
+
log.info("generator#generate()", "template name:" + tmplName);
|
|
137
|
+
next(null, {msg: "Generating " + tmplName + " in " + dest});
|
|
138
|
+
|
|
139
|
+
let srcs;
|
|
140
|
+
if (tmplName.match(/(^hosted)/)) {
|
|
141
|
+
srcs = [].concat(template.path);
|
|
142
|
+
return promise.all(srcs.map(function(src) {
|
|
143
|
+
return copyToDirAsync(src, dest);
|
|
144
|
+
})).then(function() {
|
|
145
|
+
let metaTmpl;
|
|
146
|
+
let url;
|
|
147
|
+
if (template.metadata && template.metadata.id) {
|
|
148
|
+
metaTmpl = templateList[template.metadata.id];
|
|
149
|
+
}
|
|
150
|
+
if (metaTmpl) {
|
|
151
|
+
if (appinfo.url) {
|
|
152
|
+
url = appinfo.url;
|
|
153
|
+
delete appinfo.url;
|
|
154
|
+
const urlTmpl = {"path":path.join(srcs[0],'index.html')};
|
|
155
|
+
_writeURLdata(urlTmpl, url);
|
|
156
|
+
}
|
|
157
|
+
return _writeMetadata(metaTmpl, appinfo, svcinfo, pkginfo);
|
|
158
|
+
} else {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
} else if (tmplName.match(/(^qmlapp$)/)) {
|
|
163
|
+
srcs = [].concat(template.path);
|
|
164
|
+
return promise.all(srcs.map(function(src) {
|
|
165
|
+
return copyToDirAsync(src, dest);
|
|
166
|
+
})).then(function() {
|
|
167
|
+
let metaTmpl;
|
|
168
|
+
if (template.metadata && template.metadata.id) {
|
|
169
|
+
metaTmpl = templateList[template.metadata.id];
|
|
170
|
+
}
|
|
171
|
+
if (metaTmpl) {
|
|
172
|
+
if (appinfo.id) {
|
|
173
|
+
const qmlTmpl = {"path":path.join(srcs[0],'main.qml')};
|
|
174
|
+
_writeAppIDdata(qmlTmpl, appinfo.id);
|
|
175
|
+
}
|
|
176
|
+
return _writeMetadata(metaTmpl, appinfo, svcinfo, pkginfo);
|
|
177
|
+
} else {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
} else if (template.type.match(/info$/)) {
|
|
182
|
+
return _writeMetadata(template, appinfo, svcinfo, pkginfo);
|
|
183
|
+
} else {
|
|
184
|
+
srcs = [].concat(template.path);
|
|
185
|
+
return promise.all(srcs.map(function(src) {
|
|
186
|
+
log.info("generator#generate()", "template src:" + src);
|
|
187
|
+
return copyToDirAsync(src, dest);
|
|
188
|
+
})).then(function() {
|
|
189
|
+
let metaTmpl;
|
|
190
|
+
if (template.metadata && template.metadata.id) {
|
|
191
|
+
metaTmpl = templateList[template.metadata.id];
|
|
192
|
+
}
|
|
193
|
+
if (metaTmpl) {
|
|
194
|
+
return _writeMetadata(metaTmpl, appinfo, svcinfo, pkginfo);
|
|
195
|
+
} else {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
})
|
|
201
|
+
.then(function() {
|
|
202
|
+
const deps = templateList[tmplName].deps || [];
|
|
203
|
+
return promise.all(deps.map(function(dep) {
|
|
204
|
+
if (!templateList[dep]) {
|
|
205
|
+
log.warn("generator#generate()", "Invalid template id:" + dep);
|
|
206
|
+
return;
|
|
207
|
+
} else if (!templateList[dep].path) {
|
|
208
|
+
log.warn("generator#generate()", "Invalid template path:" + dep);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
return copyToDirAsync(templateList[dep].path, dest);
|
|
212
|
+
}));
|
|
213
|
+
})
|
|
214
|
+
.then(function() {
|
|
215
|
+
log.info("generator#generate()", "done");
|
|
216
|
+
return next(null, {
|
|
217
|
+
msg: "Success"
|
|
218
|
+
});
|
|
219
|
+
})
|
|
220
|
+
.catch(function(err) {
|
|
221
|
+
log.silly("generator#generate()", "err:", err);
|
|
222
|
+
throw err;
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
function _writeAppIDdata(qmlTmpl, appId) {
|
|
226
|
+
const filePaths = [].concat(qmlTmpl.path);
|
|
227
|
+
return promise.all(filePaths.map(function(file) {
|
|
228
|
+
return fs.lstatAsync(file)
|
|
229
|
+
.then(function(stats) {
|
|
230
|
+
if (!stats.isFile()) {
|
|
231
|
+
throw errHndl.getErrMsg("INVALID_PATH", "meta template", file);
|
|
232
|
+
}
|
|
233
|
+
// eslint-disable-next-line no-useless-escape
|
|
234
|
+
const exp = /appId\s*:\s*[\'\"][\w.]*[\'\"]/g;
|
|
235
|
+
const destFile = path.join(dest, path.basename(file));
|
|
236
|
+
let qmlFile = fs.readFileSync(file, 'utf8');
|
|
237
|
+
qmlFile = qmlFile.replace(exp, "appId: \"" + appId + "\"");
|
|
238
|
+
|
|
239
|
+
fs.writeFileSync(destFile, qmlFile, {encoding: 'utf8'});
|
|
240
|
+
});
|
|
241
|
+
}))
|
|
242
|
+
.then(function() {
|
|
243
|
+
log.info("generator#generate()#_writeAppIDdata()", "done");
|
|
244
|
+
return;
|
|
245
|
+
})
|
|
246
|
+
.catch(function(err) {
|
|
247
|
+
log.silly("generator#generate()#_writeAppIDdata()", "err:", err);
|
|
248
|
+
throw err;
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function _writeURLdata(urlTmpl, url) {
|
|
253
|
+
const filePaths = [].concat(urlTmpl.path);
|
|
254
|
+
return promise.all(filePaths.map(function(file) {
|
|
255
|
+
return fs.lstatAsync(file)
|
|
256
|
+
.then(function(stats) {
|
|
257
|
+
if (!stats.isFile()) {
|
|
258
|
+
throw errHndl.getErrMsg("INVALID_PATH", "meta template", file);
|
|
259
|
+
}
|
|
260
|
+
let html = fs.readFileSync(file, 'utf8');
|
|
261
|
+
// eslint-disable-next-line no-useless-escape
|
|
262
|
+
const exp = new RegExp("(?:[\'\"])([\:/.A-z?<_&\s=>0-9;-]+\')");
|
|
263
|
+
// eslint-disable-next-line no-useless-escape
|
|
264
|
+
html = html.replace(exp, "\'" + url + "\'");
|
|
265
|
+
const destFile = path.join(dest, path.basename(file));
|
|
266
|
+
|
|
267
|
+
fs.writeFileSync(destFile, html, {encoding: 'utf8'});
|
|
268
|
+
});
|
|
269
|
+
}))
|
|
270
|
+
.then(function() {
|
|
271
|
+
log.info("generator#generate()#_writeURLdata()", "done");
|
|
272
|
+
return;
|
|
273
|
+
})
|
|
274
|
+
.catch(function(err) {
|
|
275
|
+
log.silly("generator#generate()#_writeURLdata()", "err:", err);
|
|
276
|
+
throw err;
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function _writeMetadata(metaTmpl, _appinfo, _svcinfo, _pkginfo) {
|
|
281
|
+
const metaPaths = [].concat(metaTmpl.path),
|
|
282
|
+
appInfo = _appinfo || {},
|
|
283
|
+
svcInfo = _svcinfo || {},
|
|
284
|
+
pkgInfo = _pkginfo || {};
|
|
285
|
+
|
|
286
|
+
return promise.all(metaPaths.map(function(file) {
|
|
287
|
+
return fs.lstatAsync(file)
|
|
288
|
+
.then(function(stats) {
|
|
289
|
+
if (!stats.isFile()) {
|
|
290
|
+
throw errHndl.getErrMsg("INVALID_PATH", "meta template", file);
|
|
291
|
+
}
|
|
292
|
+
const fileName = path.basename(file);
|
|
293
|
+
let info = readJsonSync(file);
|
|
294
|
+
|
|
295
|
+
if (fileName === 'appinfo.json') {
|
|
296
|
+
info = merge(info, appInfo);
|
|
297
|
+
} else if (fileName === "services.json") {
|
|
298
|
+
info = merge(info, svcInfo);
|
|
299
|
+
} else if (fileName === "package.json" &&
|
|
300
|
+
(metaTmpl.type === "jsserviceinfo" || metaTmpl.type === "nativeserviceinfo")) {
|
|
301
|
+
info.name = svcInfo.id || info.name;
|
|
302
|
+
} else if (fileName === "packageinfo.json") {
|
|
303
|
+
info = merge(info, pkgInfo);
|
|
304
|
+
}
|
|
305
|
+
return info;
|
|
306
|
+
})
|
|
307
|
+
.then(function(info) {
|
|
308
|
+
const destFile = path.join(dest, path.basename(file));
|
|
309
|
+
return fs.mkdirsAsync(dest)
|
|
310
|
+
.then(function() {
|
|
311
|
+
return fs.writeFileSync(destFile, JSON.stringify(info, null, 2), {
|
|
312
|
+
encoding: 'utf8'
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
}))
|
|
317
|
+
.then(function() {
|
|
318
|
+
log.info("generator#generate()#_writeMetadata()", "done");
|
|
319
|
+
return;
|
|
320
|
+
})
|
|
321
|
+
.catch(function(err) {
|
|
322
|
+
log.silly("generator#generate()#_writeMetadata()", "err:", err);
|
|
323
|
+
throw err;
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
Generator.prototype.getTmpl = function() {
|
|
329
|
+
return templates;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
Generator.prototype.existOutDir = function(outDir) {
|
|
333
|
+
log.verbose("generator#existOutDir()", outDir);
|
|
334
|
+
try {
|
|
335
|
+
const files = fs.readdirSync(outDir);
|
|
336
|
+
if (files.length > 0)
|
|
337
|
+
return true;
|
|
338
|
+
} catch (err) {
|
|
339
|
+
if (err && err.code === 'ENOTDIR') {
|
|
340
|
+
throw errHndl.getErrMsg("NOT_DIRTYPE_PATH", outDir);
|
|
341
|
+
}
|
|
342
|
+
if (err && err.code === 'ENOENT') {
|
|
343
|
+
log.verbose("generator#generate()", "The directory does not exist.");
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
throw err;
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
// Internal functions
|
|
351
|
+
function parsePropArgs(property, targetInfo) {
|
|
352
|
+
const props = property || [],
|
|
353
|
+
info = targetInfo || {};
|
|
354
|
+
if (props.length === 1 && props[0].indexOf('{') !== -1 && props[0].indexOf('}') !== -1 &&
|
|
355
|
+
((props[0].split("'").length - 1) % 2) === 0)
|
|
356
|
+
{
|
|
357
|
+
// eslint-disable-next-line no-useless-escape
|
|
358
|
+
props[0] = props[0].replace(/\'/g,'"');
|
|
359
|
+
}
|
|
360
|
+
props.forEach(function(prop) {
|
|
361
|
+
try {
|
|
362
|
+
const data = JSON.parse(prop);
|
|
363
|
+
for (const k in data) {
|
|
364
|
+
info[k] = data[k];
|
|
365
|
+
}
|
|
366
|
+
} catch (err) {
|
|
367
|
+
const tokens = prop.split('=');
|
|
368
|
+
if (tokens.length === 2) {
|
|
369
|
+
info[tokens[0]] = tokens[1];
|
|
370
|
+
} else {
|
|
371
|
+
log.warn('Ignoring invalid arguments:', prop);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
module.exports = Generator;
|