@reldens/cms 0.26.0 → 0.28.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/install/index.html +128 -124
- package/lib/frontend.js +274 -268
- package/lib/installer.js +500 -497
- package/lib/manager.js +515 -507
- package/lib/template-engine/asset-transformer.js +43 -41
- package/lib/template-engine/system-variables-provider.js +127 -108
- package/lib/template-engine/url-transformer.js +41 -41
- package/lib/template-engine.js +223 -213
- package/package.json +3 -3
- package/templates/.env.dist +1 -0
|
@@ -1,41 +1,43 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Reldens - CMS - AssetTransformer
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const { sc } = require('@reldens/utils');
|
|
8
|
-
|
|
9
|
-
class AssetTransformer
|
|
10
|
-
{
|
|
11
|
-
|
|
12
|
-
async transform(template, domain, req, systemVariables)
|
|
13
|
-
{
|
|
14
|
-
if(!template){
|
|
15
|
-
return template;
|
|
16
|
-
}
|
|
17
|
-
let currentRequest = sc.get(systemVariables, 'currentRequest', {});
|
|
18
|
-
let assetPattern = /\[asset\(([^)]+)\)\]/g;
|
|
19
|
-
let matches = [...template.matchAll(assetPattern)];
|
|
20
|
-
for(let i = matches.length - 1; i >= 0; i--){
|
|
21
|
-
let match = matches[i];
|
|
22
|
-
let assetPath = match[1].replace(/['"]/g, '');
|
|
23
|
-
let absoluteUrl = this.buildAssetUrl(assetPath, currentRequest);
|
|
24
|
-
template = template.substring(0, match.index) +
|
|
25
|
-
absoluteUrl +
|
|
26
|
-
template.substring(match.index + match[0].length);
|
|
27
|
-
}
|
|
28
|
-
return template;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
buildAssetUrl(assetPath, currentRequest)
|
|
32
|
-
{
|
|
33
|
-
if(!assetPath || assetPath.startsWith('http')){
|
|
34
|
-
return assetPath;
|
|
35
|
-
}
|
|
36
|
-
return sc.get(currentRequest, '
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reldens - CMS - AssetTransformer
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { sc } = require('@reldens/utils');
|
|
8
|
+
|
|
9
|
+
class AssetTransformer
|
|
10
|
+
{
|
|
11
|
+
|
|
12
|
+
async transform(template, domain, req, systemVariables)
|
|
13
|
+
{
|
|
14
|
+
if(!template){
|
|
15
|
+
return template;
|
|
16
|
+
}
|
|
17
|
+
let currentRequest = sc.get(systemVariables, 'currentRequest', {});
|
|
18
|
+
let assetPattern = /\[asset\(([^)]+)\)\]/g;
|
|
19
|
+
let matches = [...template.matchAll(assetPattern)];
|
|
20
|
+
for(let i = matches.length - 1; i >= 0; i--){
|
|
21
|
+
let match = matches[i];
|
|
22
|
+
let assetPath = match[1].replace(/['"]/g, '');
|
|
23
|
+
let absoluteUrl = this.buildAssetUrl(assetPath, currentRequest);
|
|
24
|
+
template = template.substring(0, match.index) +
|
|
25
|
+
absoluteUrl +
|
|
26
|
+
template.substring(match.index + match[0].length);
|
|
27
|
+
}
|
|
28
|
+
return template;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
buildAssetUrl(assetPath, currentRequest)
|
|
32
|
+
{
|
|
33
|
+
if(!assetPath || assetPath.startsWith('http')){
|
|
34
|
+
return assetPath;
|
|
35
|
+
}
|
|
36
|
+
return sc.get(currentRequest, 'publicUrl', '')
|
|
37
|
+
+'/assets'
|
|
38
|
+
+(assetPath.startsWith('/') ? assetPath : '/'+assetPath);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports.AssetTransformer = AssetTransformer;
|
|
@@ -1,108 +1,127 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Reldens - CMS - SystemVariablesProvider
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const { sc } = require('@reldens/utils');
|
|
8
|
-
|
|
9
|
-
class SystemVariablesProvider
|
|
10
|
-
{
|
|
11
|
-
|
|
12
|
-
constructor(props)
|
|
13
|
-
{
|
|
14
|
-
this.defaultDomain = sc.get(props, 'defaultDomain', 'default');
|
|
15
|
-
this.projectRoot = sc.get(props, 'projectRoot', './');
|
|
16
|
-
this.publicPath = sc.get(props, 'publicPath', './public');
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
let
|
|
24
|
-
let
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
let
|
|
41
|
-
let
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reldens - CMS - SystemVariablesProvider
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { sc } = require('@reldens/utils');
|
|
8
|
+
|
|
9
|
+
class SystemVariablesProvider
|
|
10
|
+
{
|
|
11
|
+
|
|
12
|
+
constructor(props)
|
|
13
|
+
{
|
|
14
|
+
this.defaultDomain = sc.get(props, 'defaultDomain', 'default');
|
|
15
|
+
this.projectRoot = sc.get(props, 'projectRoot', './');
|
|
16
|
+
this.publicPath = sc.get(props, 'publicPath', './public');
|
|
17
|
+
this.domainPublicUrlMapping = sc.get(props, 'domainPublicUrlMapping', {});
|
|
18
|
+
this.defaultPublicUrl = sc.get(props, 'defaultPublicUrl', '');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
buildSystemVariables(req, route, domain)
|
|
22
|
+
{
|
|
23
|
+
let currentRequest = this.buildCurrentRequestData(req, domain);
|
|
24
|
+
let currentRoute = this.buildCurrentRouteData(route);
|
|
25
|
+
let currentDomain = this.buildCurrentDomainData(domain);
|
|
26
|
+
let systemInfo = this.buildSystemInfo();
|
|
27
|
+
return {
|
|
28
|
+
currentRequest,
|
|
29
|
+
currentRoute,
|
|
30
|
+
currentDomain,
|
|
31
|
+
systemInfo
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
buildCurrentRequestData(req, domain)
|
|
36
|
+
{
|
|
37
|
+
if(!req){
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
40
|
+
let protocol = sc.get(req, 'protocol', 'http');
|
|
41
|
+
let host = req.get('host') || 'localhost';
|
|
42
|
+
let originalUrl = sc.get(req, 'originalUrl', sc.get(req, 'path', '/'));
|
|
43
|
+
let baseUrl = protocol+'://'+host;
|
|
44
|
+
let publicUrl = baseUrl;
|
|
45
|
+
let customPublicUrl = req.get('x-public-url');
|
|
46
|
+
if(customPublicUrl){
|
|
47
|
+
publicUrl = customPublicUrl;
|
|
48
|
+
}
|
|
49
|
+
if(!customPublicUrl && domain && sc.hasOwn(this.domainPublicUrlMapping, domain)){
|
|
50
|
+
publicUrl = this.domainPublicUrlMapping[domain];
|
|
51
|
+
}
|
|
52
|
+
if(publicUrl === baseUrl && '' !== this.defaultPublicUrl){
|
|
53
|
+
publicUrl = this.defaultPublicUrl;
|
|
54
|
+
}
|
|
55
|
+
if('' === baseUrl && '' !== this.defaultPublicUrl){
|
|
56
|
+
baseUrl = this.defaultPublicUrl;
|
|
57
|
+
}
|
|
58
|
+
let fullUrl = protocol+'://'+host+originalUrl;
|
|
59
|
+
return {
|
|
60
|
+
method: sc.get(req, 'method', 'GET'),
|
|
61
|
+
path: sc.get(req, 'path', '/'),
|
|
62
|
+
originalUrl,
|
|
63
|
+
fullUrl,
|
|
64
|
+
protocol,
|
|
65
|
+
host,
|
|
66
|
+
domain: domain || host.split(':')[0],
|
|
67
|
+
query: sc.get(req, 'query', {}),
|
|
68
|
+
params: sc.get(req, 'params', {}),
|
|
69
|
+
headers: sc.get(req, 'headers', {}),
|
|
70
|
+
userAgent: req.get('user-agent') || '',
|
|
71
|
+
ip: sc.get(req, 'ip', ''),
|
|
72
|
+
baseUrl,
|
|
73
|
+
publicUrl,
|
|
74
|
+
defaultPublicUrl: this.defaultPublicUrl,
|
|
75
|
+
timestamp: sc.getCurrentDate(),
|
|
76
|
+
isSecure: 'https' === protocol
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
buildCurrentRouteData(route)
|
|
81
|
+
{
|
|
82
|
+
if(!route){
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
id: sc.get(route, 'id', null),
|
|
87
|
+
path: sc.get(route, 'path', ''),
|
|
88
|
+
router: sc.get(route, 'router', ''),
|
|
89
|
+
domain: sc.get(route, 'domain', null),
|
|
90
|
+
enabled: sc.get(route, 'enabled', false),
|
|
91
|
+
title: sc.get(route, 'title', ''),
|
|
92
|
+
template: sc.get(route, 'template', ''),
|
|
93
|
+
layout: sc.get(route, 'layout', ''),
|
|
94
|
+
meta_title: sc.get(route, 'meta_title', ''),
|
|
95
|
+
meta_description: sc.get(route, 'meta_description', ''),
|
|
96
|
+
sort_order: sc.get(route, 'sort_order', 0)
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
buildCurrentDomainData(domain)
|
|
101
|
+
{
|
|
102
|
+
return {
|
|
103
|
+
current: domain || this.defaultDomain,
|
|
104
|
+
default: this.defaultDomain,
|
|
105
|
+
resolved: domain || this.defaultDomain
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
buildSystemInfo()
|
|
110
|
+
{
|
|
111
|
+
let date = new Date();
|
|
112
|
+
return {
|
|
113
|
+
projectRoot: this.projectRoot,
|
|
114
|
+
publicPath: this.publicPath,
|
|
115
|
+
nodeVersion: process.version,
|
|
116
|
+
platform: process.platform,
|
|
117
|
+
environment: process.env.NODE_ENV || 'development',
|
|
118
|
+
timestamp: sc.getCurrentDate(),
|
|
119
|
+
uptime: process.uptime(),
|
|
120
|
+
currentDate: sc.formatDate(date),
|
|
121
|
+
currentYear: sc.formatDate(date, 'Y')
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
module.exports.SystemVariablesProvider = SystemVariablesProvider;
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Reldens - CMS - UrlTransformer
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const { sc } = require('@reldens/utils');
|
|
8
|
-
|
|
9
|
-
class UrlTransformer
|
|
10
|
-
{
|
|
11
|
-
|
|
12
|
-
async transform(template, domain, req, systemVariables)
|
|
13
|
-
{
|
|
14
|
-
if(!template){
|
|
15
|
-
return template;
|
|
16
|
-
}
|
|
17
|
-
let currentRequest = sc.get(systemVariables, 'currentRequest', {});
|
|
18
|
-
let urlPattern = /\[url\(([^)]+)\)\]/g;
|
|
19
|
-
let matches = [...template.matchAll(urlPattern)];
|
|
20
|
-
for(let i = matches.length - 1; i >= 0; i--){
|
|
21
|
-
let match = matches[i];
|
|
22
|
-
let urlPath = match[1].replace(/['"]/g, '');
|
|
23
|
-
let absoluteUrl = this.buildAbsoluteUrl(urlPath, currentRequest);
|
|
24
|
-
template = template.substring(0, match.index) +
|
|
25
|
-
absoluteUrl +
|
|
26
|
-
template.substring(match.index + match[0].length);
|
|
27
|
-
}
|
|
28
|
-
return template;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
buildAbsoluteUrl(relativePath, currentRequest)
|
|
32
|
-
{
|
|
33
|
-
if(!relativePath || relativePath.startsWith('http')){
|
|
34
|
-
return relativePath;
|
|
35
|
-
}
|
|
36
|
-
return sc.get(currentRequest, '
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
module.exports.UrlTransformer = UrlTransformer;
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reldens - CMS - UrlTransformer
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { sc } = require('@reldens/utils');
|
|
8
|
+
|
|
9
|
+
class UrlTransformer
|
|
10
|
+
{
|
|
11
|
+
|
|
12
|
+
async transform(template, domain, req, systemVariables)
|
|
13
|
+
{
|
|
14
|
+
if(!template){
|
|
15
|
+
return template;
|
|
16
|
+
}
|
|
17
|
+
let currentRequest = sc.get(systemVariables, 'currentRequest', {});
|
|
18
|
+
let urlPattern = /\[url\(([^)]+)\)\]/g;
|
|
19
|
+
let matches = [...template.matchAll(urlPattern)];
|
|
20
|
+
for(let i = matches.length - 1; i >= 0; i--){
|
|
21
|
+
let match = matches[i];
|
|
22
|
+
let urlPath = match[1].replace(/['"]/g, '');
|
|
23
|
+
let absoluteUrl = this.buildAbsoluteUrl(urlPath, currentRequest);
|
|
24
|
+
template = template.substring(0, match.index) +
|
|
25
|
+
absoluteUrl +
|
|
26
|
+
template.substring(match.index + match[0].length);
|
|
27
|
+
}
|
|
28
|
+
return template;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
buildAbsoluteUrl(relativePath, currentRequest)
|
|
32
|
+
{
|
|
33
|
+
if(!relativePath || relativePath.startsWith('http')){
|
|
34
|
+
return relativePath;
|
|
35
|
+
}
|
|
36
|
+
return sc.get(currentRequest, 'publicUrl', '') + relativePath;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports.UrlTransformer = UrlTransformer;
|