@ixon-cdk/core 1.4.0-next.2 → 1.5.0-next.1
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/api/api.utils.js +8 -2
- package/api/deploy.service.js +39 -20
- package/config/schema.json +7 -21
- package/http-request.js +6 -2
- package/package.json +1 -1
- package/prompts.js +2 -2
- package/server/index.js +10 -4
- package/template/template.service.js +101 -41
- package/utils.js +13 -3
package/api/api.utils.js
CHANGED
|
@@ -2,9 +2,15 @@ async function whileMoreAfter(reqFn) {
|
|
|
2
2
|
const fetcher = async (seed, moreAfter) => {
|
|
3
3
|
const response = await reqFn(moreAfter);
|
|
4
4
|
const data = [...seed, ...response.data.data];
|
|
5
|
-
return response.data.moreAfter
|
|
5
|
+
return response.data.moreAfter
|
|
6
|
+
? fetcher(data, response.data.moreAfter)
|
|
7
|
+
: data;
|
|
6
8
|
};
|
|
7
|
-
return fetcher([]).then(
|
|
9
|
+
return fetcher([]).then(data => ({
|
|
10
|
+
data: { data },
|
|
11
|
+
moreAfter: null,
|
|
12
|
+
status: 'success',
|
|
13
|
+
}));
|
|
8
14
|
}
|
|
9
15
|
|
|
10
16
|
module.exports = {
|
package/api/deploy.service.js
CHANGED
|
@@ -7,27 +7,35 @@ const { whileMoreAfter } = require('./api.utils');
|
|
|
7
7
|
module.exports = class DeployService extends ApiBaseService {
|
|
8
8
|
deploy(companyId, templateId, file) {
|
|
9
9
|
const url = `${this._getApiBaseUrl()}/page-component-templates/${templateId}/version-upload`;
|
|
10
|
-
const body = fs.readFileSync(
|
|
10
|
+
const body = fs.readFileSync(
|
|
11
|
+
path.join(require('../utils').getRootDir(), file),
|
|
12
|
+
);
|
|
11
13
|
const headers = {
|
|
12
14
|
...this._getApiDefaultHeaders(),
|
|
13
15
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
14
16
|
'Api-Company': companyId,
|
|
15
17
|
Authorization: this._getApiAuthHeaderValue(),
|
|
16
18
|
};
|
|
17
|
-
return httpRequest({ method: 'POST', url, data: body, headers }).then(
|
|
19
|
+
return httpRequest({ method: 'POST', url, data: body, headers }).then(
|
|
20
|
+
res => res.data.data,
|
|
21
|
+
);
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
deployAndPublish(companyId, templateId, file) {
|
|
21
|
-
return this.deploy(companyId, templateId, file).then(
|
|
25
|
+
return this.deploy(companyId, templateId, file).then(data =>
|
|
22
26
|
this._publish(companyId, data.publicId),
|
|
23
27
|
);
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
fetchPublishable(companyId, templateId) {
|
|
27
|
-
return this._fetchDescTemplateVersions(companyId, templateId).then(
|
|
28
|
-
|
|
31
|
+
return this._fetchDescTemplateVersions(companyId, templateId).then(
|
|
32
|
+
versions => {
|
|
33
|
+
const publishedIdx = versions.findIndex(
|
|
34
|
+
v => typeof v.publishedOn === 'string',
|
|
35
|
+
);
|
|
29
36
|
return publishedIdx !== -1 ? versions.slice(0, publishedIdx) : versions;
|
|
30
|
-
|
|
37
|
+
},
|
|
38
|
+
);
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
generatePreviewLink(companyId, versionId) {
|
|
@@ -36,11 +44,9 @@ module.exports = class DeployService extends ApiBaseService {
|
|
|
36
44
|
this._fetchTemplateVersion(companyId, versionId),
|
|
37
45
|
])
|
|
38
46
|
.then(([fqdn, version]) =>
|
|
39
|
-
this._fetchTemplate(companyId, version.template.publicId).then(
|
|
40
|
-
fqdn,
|
|
41
|
-
|
|
42
|
-
template,
|
|
43
|
-
]),
|
|
47
|
+
this._fetchTemplate(companyId, version.template.publicId).then(
|
|
48
|
+
template => [fqdn, version, template],
|
|
49
|
+
),
|
|
44
50
|
)
|
|
45
51
|
.then(([fqdn, version, template]) => {
|
|
46
52
|
const hash = require('../utils').generatePreviewHash(
|
|
@@ -62,17 +68,19 @@ module.exports = class DeployService extends ApiBaseService {
|
|
|
62
68
|
? Promise.reject('Template has no publishable versions')
|
|
63
69
|
: Promise.resolve('Template has no publishable versions');
|
|
64
70
|
}
|
|
65
|
-
const latest = data.sort(
|
|
71
|
+
const latest = data.sort(
|
|
72
|
+
(v1, v2) => Number(v2.number) - Number(v1.number),
|
|
73
|
+
)[0];
|
|
66
74
|
return this._publish(companyId, latest.publicId);
|
|
67
75
|
});
|
|
68
76
|
}
|
|
69
77
|
|
|
70
78
|
publishVersion(companyId, templateId, versionNumber) {
|
|
71
|
-
return this.fetchPublishable(companyId, templateId).then(
|
|
79
|
+
return this.fetchPublishable(companyId, templateId).then(data => {
|
|
72
80
|
if (!data.length) {
|
|
73
81
|
return Promise.reject('Template has no publishable versions');
|
|
74
82
|
}
|
|
75
|
-
const _version = data.find(
|
|
83
|
+
const _version = data.find(v => v.number === String(versionNumber));
|
|
76
84
|
if (_version) {
|
|
77
85
|
return this._publish(companyId, _version.publicId);
|
|
78
86
|
}
|
|
@@ -89,7 +97,7 @@ module.exports = class DeployService extends ApiBaseService {
|
|
|
89
97
|
Authorization: this._getApiAuthHeaderValue(),
|
|
90
98
|
};
|
|
91
99
|
// Lookup company FQDN (premium branding)
|
|
92
|
-
return httpRequest({ method: 'GET', url, params, headers }).then(
|
|
100
|
+
return httpRequest({ method: 'GET', url, params, headers }).then(res => {
|
|
93
101
|
const myCompany = res.data.data;
|
|
94
102
|
if (myCompany.branding && myCompany.branding.fqdn) {
|
|
95
103
|
return myCompany.branding.fqdn;
|
|
@@ -97,7 +105,12 @@ module.exports = class DeployService extends ApiBaseService {
|
|
|
97
105
|
// Or fallback to sector FQDN
|
|
98
106
|
const _url = `${this._getApiBaseUrl()}/sectors/me`;
|
|
99
107
|
const _headers = { ...this._getApiDefaultHeaders() };
|
|
100
|
-
return httpRequest({
|
|
108
|
+
return httpRequest({
|
|
109
|
+
method: 'GET',
|
|
110
|
+
url: _url,
|
|
111
|
+
params,
|
|
112
|
+
headers: _headers,
|
|
113
|
+
}).then(res => {
|
|
101
114
|
const mySector = res.data.data;
|
|
102
115
|
if (mySector.branding && mySector.branding.fqdn) {
|
|
103
116
|
return mySector.branding.fqdn;
|
|
@@ -119,14 +132,16 @@ module.exports = class DeployService extends ApiBaseService {
|
|
|
119
132
|
'Api-Company': companyId,
|
|
120
133
|
Authorization: this._getApiAuthHeaderValue(),
|
|
121
134
|
};
|
|
122
|
-
return whileMoreAfter(
|
|
135
|
+
return whileMoreAfter(pageAfter =>
|
|
123
136
|
httpRequest({
|
|
124
137
|
method: 'GET',
|
|
125
138
|
url,
|
|
126
139
|
params: pageAfter ? { ...params, 'page-after': pageAfter } : params,
|
|
127
140
|
headers,
|
|
128
141
|
}),
|
|
129
|
-
).then(
|
|
142
|
+
).then(res =>
|
|
143
|
+
res.data.data.sort((v1, v2) => Number(v2.number) - Number(v1.number)),
|
|
144
|
+
);
|
|
130
145
|
}
|
|
131
146
|
|
|
132
147
|
_fetchTemplate(companyId, templateId) {
|
|
@@ -137,7 +152,9 @@ module.exports = class DeployService extends ApiBaseService {
|
|
|
137
152
|
'Api-Company': companyId,
|
|
138
153
|
Authorization: this._getApiAuthHeaderValue(),
|
|
139
154
|
};
|
|
140
|
-
return httpRequest({ method: 'GET', url, params, headers }).then(
|
|
155
|
+
return httpRequest({ method: 'GET', url, params, headers }).then(
|
|
156
|
+
res => res.data.data,
|
|
157
|
+
);
|
|
141
158
|
}
|
|
142
159
|
|
|
143
160
|
_fetchTemplateVersion(companyId, versionId) {
|
|
@@ -148,7 +165,9 @@ module.exports = class DeployService extends ApiBaseService {
|
|
|
148
165
|
'Api-Company': companyId,
|
|
149
166
|
Authorization: this._getApiAuthHeaderValue(),
|
|
150
167
|
};
|
|
151
|
-
return httpRequest({ method: 'GET', url, params, headers }).then(
|
|
168
|
+
return httpRequest({ method: 'GET', url, params, headers }).then(
|
|
169
|
+
res => res.data.data,
|
|
170
|
+
);
|
|
152
171
|
}
|
|
153
172
|
|
|
154
173
|
_publish(companyId, versionId) {
|
package/config/schema.json
CHANGED
|
@@ -39,9 +39,7 @@
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
|
-
"required": [
|
|
43
|
-
"components"
|
|
44
|
-
],
|
|
42
|
+
"required": ["components"],
|
|
45
43
|
"title": "UI Component Workspace Configuration",
|
|
46
44
|
"definitions": {
|
|
47
45
|
"component": {
|
|
@@ -80,10 +78,7 @@
|
|
|
80
78
|
"description": "List of static component assets. Can be passed as glob paths relative to the component root or as objects for more fine-tuned configuration."
|
|
81
79
|
}
|
|
82
80
|
},
|
|
83
|
-
"required": [
|
|
84
|
-
"builder",
|
|
85
|
-
"input"
|
|
86
|
-
]
|
|
81
|
+
"required": ["builder", "input"]
|
|
87
82
|
},
|
|
88
83
|
"deploy": {
|
|
89
84
|
"type": "object",
|
|
@@ -97,20 +92,13 @@
|
|
|
97
92
|
"description": "PageComponentTemplate ID"
|
|
98
93
|
}
|
|
99
94
|
},
|
|
100
|
-
"required": [
|
|
101
|
-
"company",
|
|
102
|
-
"template"
|
|
103
|
-
]
|
|
95
|
+
"required": ["company", "template"]
|
|
104
96
|
}
|
|
105
97
|
},
|
|
106
|
-
"required": [
|
|
107
|
-
"build"
|
|
108
|
-
]
|
|
98
|
+
"required": ["build"]
|
|
109
99
|
}
|
|
110
100
|
},
|
|
111
|
-
"required": [
|
|
112
|
-
"runner"
|
|
113
|
-
]
|
|
101
|
+
"required": ["runner"]
|
|
114
102
|
},
|
|
115
103
|
"asset": {
|
|
116
104
|
"type": "object",
|
|
@@ -128,9 +116,7 @@
|
|
|
128
116
|
"description": "A path relative to the component output path (default is dist/component-name)."
|
|
129
117
|
}
|
|
130
118
|
},
|
|
131
|
-
"required": [
|
|
132
|
-
"glob"
|
|
133
|
-
]
|
|
119
|
+
"required": ["glob"]
|
|
134
120
|
}
|
|
135
121
|
}
|
|
136
|
-
}
|
|
122
|
+
}
|
package/http-request.js
CHANGED
|
@@ -10,14 +10,18 @@ module.exports = function request(options) {
|
|
|
10
10
|
const customRequest = require(customPath);
|
|
11
11
|
|
|
12
12
|
if (typeof customRequest !== 'function') {
|
|
13
|
-
logErrorMessage(
|
|
13
|
+
logErrorMessage(
|
|
14
|
+
'The custom "http-request.js" file must export a function.',
|
|
15
|
+
);
|
|
14
16
|
process.exit(1);
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
const promise = customRequest(options);
|
|
18
20
|
|
|
19
21
|
if (typeof promise !== 'object' || typeof promise.then !== 'function') {
|
|
20
|
-
logErrorMessage(
|
|
22
|
+
logErrorMessage(
|
|
23
|
+
'The exported function in the custom "http-request.js" file must return a Promise.',
|
|
24
|
+
);
|
|
21
25
|
process.exit(1);
|
|
22
26
|
}
|
|
23
27
|
|
package/package.json
CHANGED
package/prompts.js
CHANGED
|
@@ -4,7 +4,7 @@ module.exports = {
|
|
|
4
4
|
type: 'text',
|
|
5
5
|
name,
|
|
6
6
|
message: 'What is the ID of your Company?',
|
|
7
|
-
validate:
|
|
7
|
+
validate: value => {
|
|
8
8
|
if (!value) {
|
|
9
9
|
return 'Company ID is required.';
|
|
10
10
|
}
|
|
@@ -20,7 +20,7 @@ module.exports = {
|
|
|
20
20
|
type: 'text',
|
|
21
21
|
name,
|
|
22
22
|
message: 'What is the ID of the PageComponentTemplate?',
|
|
23
|
-
validate:
|
|
23
|
+
validate: value => {
|
|
24
24
|
if (!value) {
|
|
25
25
|
return 'Template ID is required.';
|
|
26
26
|
}
|
package/server/index.js
CHANGED
|
@@ -31,17 +31,23 @@ module.exports = class Server {
|
|
|
31
31
|
// CORS
|
|
32
32
|
app.use((_, res, next) => {
|
|
33
33
|
res.header('Access-Control-Allow-Origin', '*');
|
|
34
|
-
res.header(
|
|
34
|
+
res.header(
|
|
35
|
+
'Access-Control-Allow-Headers',
|
|
36
|
+
'Origin, X-Requested-With, Content-Type, Accept',
|
|
37
|
+
);
|
|
35
38
|
next();
|
|
36
39
|
});
|
|
37
40
|
|
|
38
41
|
// Components
|
|
39
42
|
if (names) {
|
|
40
|
-
names.forEach(
|
|
43
|
+
names.forEach(name => {
|
|
41
44
|
const outputDir = this._getOutputDir(name);
|
|
42
45
|
if (outputDir) {
|
|
43
46
|
const dir = path.resolve(this._rootDir, outputDir);
|
|
44
|
-
app.use(
|
|
47
|
+
app.use(
|
|
48
|
+
`/${this._opts.componentBasePath}/${name}`,
|
|
49
|
+
express.static(dir),
|
|
50
|
+
);
|
|
45
51
|
}
|
|
46
52
|
});
|
|
47
53
|
}
|
|
@@ -53,7 +59,7 @@ module.exports = class Server {
|
|
|
53
59
|
const _refresh = () => lrServer.refresh('/');
|
|
54
60
|
const _debouncedRefresh = require('lodash/debounce')(_refresh, 250);
|
|
55
61
|
names
|
|
56
|
-
.flatMap(
|
|
62
|
+
.flatMap(name => [
|
|
57
63
|
[path.join(this._rootDir, this._getOutput(name)), 100],
|
|
58
64
|
[path.join(this._rootDir, `dist/${name}/manifest.json`), 500],
|
|
59
65
|
])
|
|
@@ -24,14 +24,21 @@ module.exports = class TemplateService {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
async addFromExample(componentName, componentPrefix) {
|
|
27
|
-
const examplesRoot = path.join(
|
|
27
|
+
const examplesRoot = path.join(
|
|
28
|
+
this._rootDir,
|
|
29
|
+
'node_modules/ixon-custom-component-examples',
|
|
30
|
+
);
|
|
28
31
|
|
|
29
32
|
if (!fs.existsSync(examplesRoot)) {
|
|
30
|
-
logErrorMessage(
|
|
33
|
+
logErrorMessage(
|
|
34
|
+
"Package 'ixon-custom-component-examples' is not installed.",
|
|
35
|
+
);
|
|
31
36
|
process.exit(1);
|
|
32
37
|
}
|
|
33
38
|
|
|
34
|
-
const examplesConfigSrv = new ConfigService(
|
|
39
|
+
const examplesConfigSrv = new ConfigService(
|
|
40
|
+
'node_modules/ixon-custom-component-examples/config.json',
|
|
41
|
+
);
|
|
35
42
|
const { components } = examplesConfigSrv._config;
|
|
36
43
|
|
|
37
44
|
if (!Object.keys(components).length) {
|
|
@@ -46,7 +53,10 @@ module.exports = class TemplateService {
|
|
|
46
53
|
type: 'select',
|
|
47
54
|
name: 'name',
|
|
48
55
|
message: 'Pick a template',
|
|
49
|
-
choices: Object.keys(components).map(
|
|
56
|
+
choices: Object.keys(components).map(name => ({
|
|
57
|
+
title: name,
|
|
58
|
+
value: name,
|
|
59
|
+
})),
|
|
50
60
|
initial: 0,
|
|
51
61
|
});
|
|
52
62
|
const exampleName = result.name;
|
|
@@ -60,11 +70,13 @@ module.exports = class TemplateService {
|
|
|
60
70
|
|
|
61
71
|
const { build } = components[exampleName].runner;
|
|
62
72
|
const { builder } = build;
|
|
63
|
-
|
|
73
|
+
|
|
64
74
|
// make sure the builders for this example are installed.
|
|
65
75
|
if (components[exampleName].runner) {
|
|
66
|
-
const moduleNames = this._getModuleNamesForRunner(
|
|
67
|
-
|
|
76
|
+
const moduleNames = this._getModuleNamesForRunner(
|
|
77
|
+
components[exampleName].runner,
|
|
78
|
+
);
|
|
79
|
+
moduleNames.forEach(name => ensureModule(name));
|
|
68
80
|
}
|
|
69
81
|
|
|
70
82
|
const isVue = builder.startsWith('@ixon-cdk/vue-builder');
|
|
@@ -72,12 +84,21 @@ module.exports = class TemplateService {
|
|
|
72
84
|
const isSvelte = builder.startsWith('@ixon-cdk/svelte-builder');
|
|
73
85
|
|
|
74
86
|
// find source files, read and replace.
|
|
75
|
-
const exampleDir = path.join(
|
|
87
|
+
const exampleDir = path.join(
|
|
88
|
+
examplesRoot,
|
|
89
|
+
exampleComponentRoot,
|
|
90
|
+
exampleName,
|
|
91
|
+
);
|
|
76
92
|
const inputFilePath = path.join(exampleDir, build.input);
|
|
77
|
-
let inputFileContents = fs.readFileSync(inputFilePath, {
|
|
93
|
+
let inputFileContents = fs.readFileSync(inputFilePath, {
|
|
94
|
+
encoding: 'utf-8',
|
|
95
|
+
});
|
|
78
96
|
|
|
79
97
|
if (isVue) {
|
|
80
|
-
inputFileContents = this._findAndReplaceVueInputFile(
|
|
98
|
+
inputFileContents = this._findAndReplaceVueInputFile(
|
|
99
|
+
inputFileContents,
|
|
100
|
+
componentName,
|
|
101
|
+
);
|
|
81
102
|
} else if (isStatic) {
|
|
82
103
|
inputFileContents = this._findAndReplaceStaticInputFile(
|
|
83
104
|
inputFileContents,
|
|
@@ -89,9 +110,15 @@ module.exports = class TemplateService {
|
|
|
89
110
|
}
|
|
90
111
|
|
|
91
112
|
// find manifest file, read and replace.
|
|
92
|
-
const manifestFilePath = path.join(
|
|
113
|
+
const manifestFilePath = path.join(
|
|
114
|
+
path.dirname(inputFilePath),
|
|
115
|
+
'manifest.json',
|
|
116
|
+
);
|
|
93
117
|
const manifestFileContents = JSON.parse(fs.readFileSync(manifestFilePath));
|
|
94
|
-
manifestFileContents.main = `${this._getTag(
|
|
118
|
+
manifestFileContents.main = `${this._getTag(
|
|
119
|
+
componentPrefix,
|
|
120
|
+
componentName,
|
|
121
|
+
)}.min.js`;
|
|
95
122
|
manifestFileContents.version = '1';
|
|
96
123
|
|
|
97
124
|
let input;
|
|
@@ -106,10 +133,12 @@ module.exports = class TemplateService {
|
|
|
106
133
|
const files = await getFiles(exampleDir).catch(logErrorMessage);
|
|
107
134
|
|
|
108
135
|
// find and install any missing dependencies.
|
|
109
|
-
files.forEach(
|
|
136
|
+
files.forEach(file => {
|
|
110
137
|
if (/\.(jsx?|tsx?|svelte|vue)$/i.test(file)) {
|
|
111
138
|
const fileContents = fs.readFileSync(file);
|
|
112
|
-
const { dependencies } = require(
|
|
139
|
+
const { dependencies } = require(
|
|
140
|
+
path.join(examplesRoot, 'package.json'),
|
|
141
|
+
);
|
|
113
142
|
this._checkDependencies(fileContents, dependencies || {});
|
|
114
143
|
}
|
|
115
144
|
});
|
|
@@ -117,14 +146,17 @@ module.exports = class TemplateService {
|
|
|
117
146
|
// else start copying input, and menifest files
|
|
118
147
|
const componentRoot = this._configSrv.getNewComponentRoot();
|
|
119
148
|
const dir = path.join(this._rootDir, componentRoot, componentName);
|
|
120
|
-
const _logCreatedInDir =
|
|
121
|
-
logFileCrudMessage(
|
|
149
|
+
const _logCreatedInDir = fileName => {
|
|
150
|
+
logFileCrudMessage(
|
|
151
|
+
'CREATE',
|
|
152
|
+
path.join(componentRoot, componentName, fileName),
|
|
153
|
+
);
|
|
122
154
|
};
|
|
123
155
|
fs.mkdirSync(dir, { recursive: true });
|
|
124
156
|
|
|
125
157
|
files
|
|
126
|
-
.map(
|
|
127
|
-
.forEach(
|
|
158
|
+
.map(file => file.slice(exampleDir.length + 1))
|
|
159
|
+
.forEach(file => {
|
|
128
160
|
// create directory if it doesn't exist.
|
|
129
161
|
const _dir = path.dirname(path.join(dir, file));
|
|
130
162
|
if (!fs.existsSync(_dir)) {
|
|
@@ -132,7 +164,9 @@ module.exports = class TemplateService {
|
|
|
132
164
|
}
|
|
133
165
|
// for the input-file and manifest use the replaced file contents.
|
|
134
166
|
if (file === build.input) {
|
|
135
|
-
fs.writeFileSync(path.join(dir, input), inputFileContents, {
|
|
167
|
+
fs.writeFileSync(path.join(dir, input), inputFileContents, {
|
|
168
|
+
encoding: 'utf-8',
|
|
169
|
+
});
|
|
136
170
|
_logCreatedInDir(input);
|
|
137
171
|
} else if (file === 'manifest.json') {
|
|
138
172
|
const json = `${JSON.stringify(manifestFileContents, null, 2)}\n`;
|
|
@@ -144,7 +178,9 @@ module.exports = class TemplateService {
|
|
|
144
178
|
}
|
|
145
179
|
});
|
|
146
180
|
|
|
147
|
-
return Promise.resolve({
|
|
181
|
+
return Promise.resolve({
|
|
182
|
+
config: { runner: { build: { builder, input } } },
|
|
183
|
+
});
|
|
148
184
|
}
|
|
149
185
|
|
|
150
186
|
async add(componentName, componentPrefix) {
|
|
@@ -154,7 +190,7 @@ module.exports = class TemplateService {
|
|
|
154
190
|
type: 'select',
|
|
155
191
|
name: 'templateName',
|
|
156
192
|
message: 'Pick a template',
|
|
157
|
-
choices: Object.keys(this._schemas).map(
|
|
193
|
+
choices: Object.keys(this._schemas).map(key => ({
|
|
158
194
|
title: this._schemas[key].name,
|
|
159
195
|
value: key,
|
|
160
196
|
})),
|
|
@@ -166,7 +202,10 @@ module.exports = class TemplateService {
|
|
|
166
202
|
}
|
|
167
203
|
|
|
168
204
|
if (schema) {
|
|
169
|
-
const context = {
|
|
205
|
+
const context = {
|
|
206
|
+
name: componentName,
|
|
207
|
+
tag: this._getTag(componentPrefix, componentName),
|
|
208
|
+
};
|
|
170
209
|
let variantIdx = null;
|
|
171
210
|
|
|
172
211
|
if (schema.variants) {
|
|
@@ -186,7 +225,7 @@ module.exports = class TemplateService {
|
|
|
186
225
|
}
|
|
187
226
|
|
|
188
227
|
if (variantIdx === undefined) {
|
|
189
|
-
logErrorMessage(
|
|
228
|
+
logErrorMessage('No variant selected');
|
|
190
229
|
process.exit(1);
|
|
191
230
|
}
|
|
192
231
|
}
|
|
@@ -196,11 +235,14 @@ module.exports = class TemplateService {
|
|
|
196
235
|
// make sure the builders for this template are installed.
|
|
197
236
|
if (schema.config.runner) {
|
|
198
237
|
const moduleNames = this._getModuleNamesForRunner(schema.config.runner);
|
|
199
|
-
moduleNames.forEach(
|
|
238
|
+
moduleNames.forEach(name => ensureModule(name));
|
|
200
239
|
}
|
|
201
240
|
|
|
202
241
|
// optionally install types
|
|
203
|
-
if (
|
|
242
|
+
if (
|
|
243
|
+
variantIdx !== null &&
|
|
244
|
+
/typescript/i.test(schema.variants[variantIdx].name)
|
|
245
|
+
) {
|
|
204
246
|
ensureModule('@ixon-cdk/types');
|
|
205
247
|
}
|
|
206
248
|
|
|
@@ -219,22 +261,26 @@ module.exports = class TemplateService {
|
|
|
219
261
|
const deps = schema.variants[variantIdx].dependencies;
|
|
220
262
|
const devDeps = schema.variants[variantIdx].devDependencies;
|
|
221
263
|
if (!!deps) {
|
|
222
|
-
Object.keys(deps).forEach(name =>
|
|
264
|
+
Object.keys(deps).forEach(name =>
|
|
265
|
+
ensureModule(name, deps[name], false),
|
|
266
|
+
);
|
|
223
267
|
}
|
|
224
268
|
if (!!devDeps) {
|
|
225
|
-
Object.keys(devDeps).forEach(name =>
|
|
269
|
+
Object.keys(devDeps).forEach(name =>
|
|
270
|
+
ensureModule(name, devDeps[name]),
|
|
271
|
+
);
|
|
226
272
|
}
|
|
227
273
|
}
|
|
228
274
|
|
|
229
275
|
const componentRoot = this._configSrv.getNewComponentRoot();
|
|
230
276
|
|
|
231
|
-
schema.files.forEach(
|
|
277
|
+
schema.files.forEach(file => {
|
|
232
278
|
file.dest = `${componentRoot}/${componentName}/${file.dest}`;
|
|
233
279
|
this.createFile(file, context);
|
|
234
280
|
});
|
|
235
281
|
|
|
236
282
|
if (variantIdx !== null) {
|
|
237
|
-
schema.variants[variantIdx].files.forEach(
|
|
283
|
+
schema.variants[variantIdx].files.forEach(file => {
|
|
238
284
|
file.dest = `${componentRoot}/${componentName}/${file.dest}`;
|
|
239
285
|
this.createFile(file, context);
|
|
240
286
|
});
|
|
@@ -250,7 +296,10 @@ module.exports = class TemplateService {
|
|
|
250
296
|
});
|
|
251
297
|
if (file.interpolateContent) {
|
|
252
298
|
const text = fs.readFileSync(
|
|
253
|
-
path.join(
|
|
299
|
+
path.join(
|
|
300
|
+
path.dirname(require.resolve('@ixon-cdk/templates')),
|
|
301
|
+
file.source,
|
|
302
|
+
),
|
|
254
303
|
{ encoding: 'utf-8' },
|
|
255
304
|
);
|
|
256
305
|
const data = this._interpolateText(text, ctx);
|
|
@@ -259,7 +308,10 @@ module.exports = class TemplateService {
|
|
|
259
308
|
});
|
|
260
309
|
} else {
|
|
261
310
|
fs.copyFileSync(
|
|
262
|
-
path.join(
|
|
311
|
+
path.join(
|
|
312
|
+
path.dirname(require.resolve('@ixon-cdk/templates')),
|
|
313
|
+
file.source,
|
|
314
|
+
),
|
|
263
315
|
path.join(this._rootDir, file.dest),
|
|
264
316
|
);
|
|
265
317
|
}
|
|
@@ -272,8 +324,9 @@ module.exports = class TemplateService {
|
|
|
272
324
|
* already be a depencency in your workspace. If not, the package will get installed and saved.
|
|
273
325
|
*/
|
|
274
326
|
_checkDependencies(fileContents, dependencies) {
|
|
275
|
-
const rootDeps =
|
|
276
|
-
|
|
327
|
+
const rootDeps =
|
|
328
|
+
require(path.join(this._rootDir, 'package.json')).dependencies || {};
|
|
329
|
+
Object.keys(dependencies).forEach(pkg => {
|
|
277
330
|
const matcher = new RegExp(`^\\s*import.*\\s['"]${pkg}\\S*['"]`, 'gm');
|
|
278
331
|
if (matcher.test(fileContents) && !(pkg in rootDeps)) {
|
|
279
332
|
const version = dependencies[pkg];
|
|
@@ -288,7 +341,9 @@ module.exports = class TemplateService {
|
|
|
288
341
|
*/
|
|
289
342
|
_findAndReplaceVueInputFile(fileContents, componentName) {
|
|
290
343
|
const matcher = /export\s+default\s+{\s+name:\s+['"](\S+)['"]/gm;
|
|
291
|
-
return fileContents.replaceAll(matcher, (match, p1) =>
|
|
344
|
+
return fileContents.replaceAll(matcher, (match, p1) =>
|
|
345
|
+
match.replace(p1, componentName),
|
|
346
|
+
);
|
|
292
347
|
}
|
|
293
348
|
|
|
294
349
|
/**
|
|
@@ -326,16 +381,21 @@ module.exports = class TemplateService {
|
|
|
326
381
|
const searchTag = this._getTag(searchPrefix, searchName);
|
|
327
382
|
const replacementTag = this._getTag(replacementPrefix, replacementName);
|
|
328
383
|
return fileContents
|
|
329
|
-
.replaceAll(
|
|
330
|
-
|
|
384
|
+
.replaceAll(
|
|
385
|
+
new RegExp(`class\\s+(${pascalCase(searchTag)})`, 'gm'),
|
|
386
|
+
(match, p1) => match.replace(p1, pascalCase(replacementTag)),
|
|
331
387
|
)
|
|
332
388
|
.replaceAll(
|
|
333
389
|
new RegExp(
|
|
334
|
-
`define\\s*\\(\\s*['"](${searchTag})['"]\\s*,\\s+(${pascalCase(
|
|
390
|
+
`define\\s*\\(\\s*['"](${searchTag})['"]\\s*,\\s+(${pascalCase(
|
|
391
|
+
searchTag,
|
|
392
|
+
)})\\)`,
|
|
335
393
|
'gm',
|
|
336
394
|
),
|
|
337
395
|
(match, p1, p2) =>
|
|
338
|
-
match
|
|
396
|
+
match
|
|
397
|
+
.replace(p1, replacementTag)
|
|
398
|
+
.replace(p2, pascalCase(replacementTag)),
|
|
339
399
|
);
|
|
340
400
|
}
|
|
341
401
|
|
|
@@ -373,8 +433,8 @@ module.exports = class TemplateService {
|
|
|
373
433
|
* ```
|
|
374
434
|
* ["@ixon-cdk/svelte-builder"]
|
|
375
435
|
* ```
|
|
376
|
-
*
|
|
377
|
-
* @param {Object} runner
|
|
436
|
+
*
|
|
437
|
+
* @param {Object} runner
|
|
378
438
|
* @returns {Array.<String>} names
|
|
379
439
|
*/
|
|
380
440
|
_getModuleNamesForRunner(runner) {
|
|
@@ -387,7 +447,7 @@ module.exports = class TemplateService {
|
|
|
387
447
|
}
|
|
388
448
|
return names;
|
|
389
449
|
}, []);
|
|
390
|
-
}
|
|
450
|
+
}
|
|
391
451
|
|
|
392
452
|
_getTag(prefix, name) {
|
|
393
453
|
return prefix ? `${prefix}-${name}` : name;
|
package/utils.js
CHANGED
|
@@ -93,7 +93,11 @@ function apiHttpErrorToMessage(error, exit = true) {
|
|
|
93
93
|
if (errors) {
|
|
94
94
|
logErrorMessage(
|
|
95
95
|
errors
|
|
96
|
-
.map(
|
|
96
|
+
.map(err =>
|
|
97
|
+
err.propertyName
|
|
98
|
+
? `${err.propertyName}: ${err.message}`
|
|
99
|
+
: err.message,
|
|
100
|
+
)
|
|
97
101
|
.join('\n'),
|
|
98
102
|
);
|
|
99
103
|
exit && process.exit(1);
|
|
@@ -105,7 +109,13 @@ function apiHttpErrorToMessage(error, exit = true) {
|
|
|
105
109
|
exit && process.exit(1);
|
|
106
110
|
}
|
|
107
111
|
|
|
108
|
-
function generatePreviewHash(
|
|
112
|
+
function generatePreviewHash(
|
|
113
|
+
templateId,
|
|
114
|
+
templateName,
|
|
115
|
+
versionId,
|
|
116
|
+
versionNumber,
|
|
117
|
+
versionMainPath,
|
|
118
|
+
) {
|
|
109
119
|
const ref = {
|
|
110
120
|
tid: templateId,
|
|
111
121
|
tnm: templateName,
|
|
@@ -120,7 +130,7 @@ function generatePreviewHash(templateId, templateName, versionId, versionNumber,
|
|
|
120
130
|
async function getFiles(dir) {
|
|
121
131
|
const dirents = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
122
132
|
const files = await Promise.all(
|
|
123
|
-
dirents.map(
|
|
133
|
+
dirents.map(dirent => {
|
|
124
134
|
const res = path.resolve(dir, dirent.name);
|
|
125
135
|
return dirent.isDirectory() ? getFiles(res) : res;
|
|
126
136
|
}),
|