@ixon-cdk/core 1.2.0-next.1 → 1.2.0-next.10
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/auth.service.js +2 -1
- package/config/config.service.js +17 -4
- package/meta-files.js +58 -64
- package/package.json +6 -6
- package/server/index.js +12 -1
- package/template/template.service.js +46 -8
- package/utils.js +16 -10
package/api/auth.service.js
CHANGED
|
@@ -5,10 +5,11 @@ const httpRequest = require('../http-request');
|
|
|
5
5
|
module.exports = class AuthService extends ApiBaseService {
|
|
6
6
|
logIn(credentials) {
|
|
7
7
|
const c = credentials;
|
|
8
|
+
const expiresIn = 2592000; // 30 days
|
|
8
9
|
return httpRequest({
|
|
9
10
|
method: 'POST',
|
|
10
11
|
url: `${this._getApiBaseUrl()}/access-tokens`,
|
|
11
|
-
data: { expiresIn
|
|
12
|
+
data: { expiresIn },
|
|
12
13
|
headers: {
|
|
13
14
|
...this._getApiDefaultHeaders(),
|
|
14
15
|
'User-Agent': 'ComponentDevKit',
|
package/config/config.service.js
CHANGED
|
@@ -8,7 +8,7 @@ module.exports = class ConfigService {
|
|
|
8
8
|
|
|
9
9
|
constructor(configFile) {
|
|
10
10
|
// When the CDK is part of a larger project workspace it may be desirable to have a more explicit config-file name. Therefore, unless
|
|
11
|
-
// a specific config file path was defined in the
|
|
11
|
+
// a specific config file path was defined in the constructor, we'll first try to find `cdk.config.json`, before falling back to the
|
|
12
12
|
// default file name `config.json`.
|
|
13
13
|
if (configFile !== undefined) {
|
|
14
14
|
this._path = path.join(getRootDir(), configFile);
|
|
@@ -23,8 +23,21 @@ module.exports = class ConfigService {
|
|
|
23
23
|
let config;
|
|
24
24
|
|
|
25
25
|
if (!fs.existsSync(this._path)) {
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
this._path = path.join(getRootDir(), 'cdk.config.json');
|
|
27
|
+
fs.writeFileSync(
|
|
28
|
+
this._path,
|
|
29
|
+
`${JSON.stringify(
|
|
30
|
+
{
|
|
31
|
+
$schema: './node_modules/@ixon-cdk/core/config/schema.json',
|
|
32
|
+
prefix: 'pct',
|
|
33
|
+
components: {},
|
|
34
|
+
},
|
|
35
|
+
null,
|
|
36
|
+
2,
|
|
37
|
+
)}\n`,
|
|
38
|
+
{ encoding: 'utf-8' },
|
|
39
|
+
);
|
|
40
|
+
logFileCrudMessage('CREATE', 'cdk.config.json');
|
|
28
41
|
}
|
|
29
42
|
|
|
30
43
|
try {
|
|
@@ -88,6 +101,6 @@ module.exports = class ConfigService {
|
|
|
88
101
|
encoding: 'utf8',
|
|
89
102
|
flag: 'w',
|
|
90
103
|
});
|
|
91
|
-
logFileCrudMessage('UPDATE',
|
|
104
|
+
logFileCrudMessage('UPDATE', path.basename(this._path));
|
|
92
105
|
}
|
|
93
106
|
};
|
package/meta-files.js
CHANGED
|
@@ -1,78 +1,73 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
|
+
const fse = require('fs-extra');
|
|
2
3
|
const path = require('path');
|
|
4
|
+
const { watch } = require('chokidar');
|
|
5
|
+
const { globSync } = require('glob');
|
|
3
6
|
const { debounce, uniq } = require('lodash');
|
|
4
|
-
const
|
|
7
|
+
const { getRootDir } = require('./utils');
|
|
5
8
|
|
|
6
9
|
const ICON_FILE_NAME = 'icon.svg';
|
|
7
10
|
const MANIFEST_FILE_NAME = 'manifest.json';
|
|
8
11
|
const WATCH_OPTIONS = {
|
|
9
|
-
cwd:
|
|
12
|
+
cwd: getRootDir(),
|
|
10
13
|
usePolling: process.platform !== 'darwin',
|
|
11
14
|
};
|
|
12
15
|
|
|
13
16
|
module.exports = {
|
|
14
17
|
cleanDir(dir) {
|
|
15
|
-
|
|
16
|
-
rimraf.sync(dir);
|
|
17
|
-
}
|
|
18
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
18
|
+
fse.emptyDirSync(dir);
|
|
19
19
|
},
|
|
20
20
|
copyAssets(assets, inputDir, outputDir) {
|
|
21
|
-
const paths = uniq([MANIFEST_FILE_NAME, ICON_FILE_NAME, ...assets]).map(
|
|
22
|
-
path.join(inputDir, asset),
|
|
21
|
+
const paths = uniq([MANIFEST_FILE_NAME, ICON_FILE_NAME, ...assets]).map(
|
|
22
|
+
asset => path.join(inputDir, asset),
|
|
23
23
|
);
|
|
24
|
-
paths.forEach(
|
|
24
|
+
paths.forEach(_path => {
|
|
25
25
|
const globFilePath = _path.replaceAll('\\', '/');
|
|
26
|
-
|
|
27
|
-
.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
_copyFileNameFromToSync(fileName, inputDir, outputDir);
|
|
31
|
-
});
|
|
26
|
+
globSync(globFilePath).forEach(file => {
|
|
27
|
+
const filePath = file.slice(inputDir.length + 1);
|
|
28
|
+
_copyFromToSync(filePath, inputDir, outputDir);
|
|
29
|
+
});
|
|
32
30
|
});
|
|
33
31
|
},
|
|
34
32
|
watchAssets(assets, inputDir, outputDir) {
|
|
35
|
-
const root =
|
|
36
|
-
return
|
|
37
|
-
.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
33
|
+
const root = getRootDir();
|
|
34
|
+
return watch(
|
|
35
|
+
uniq([MANIFEST_FILE_NAME, ICON_FILE_NAME, ...assets]).map(asset =>
|
|
36
|
+
path.join(inputDir, asset),
|
|
37
|
+
),
|
|
38
|
+
WATCH_OPTIONS,
|
|
39
|
+
).on('all', (type, file) => {
|
|
40
|
+
const filePath = path.join(root, file).slice(inputDir.length + 1);
|
|
41
|
+
switch (type) {
|
|
42
|
+
case 'add':
|
|
43
|
+
case 'addDir':
|
|
44
|
+
case 'change':
|
|
45
|
+
case 'changeDir':
|
|
46
|
+
_copyFromToSync(filePath, inputDir, outputDir);
|
|
47
|
+
break;
|
|
48
|
+
case 'unlink':
|
|
49
|
+
case 'unlinkDir':
|
|
50
|
+
fse.removeSync(path.join(outputDir, filePath));
|
|
51
|
+
break;
|
|
52
|
+
default:
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
59
56
|
},
|
|
60
57
|
watchInputDir(dir, watchCallback) {
|
|
61
58
|
const _debouncedCallback = debounce(() => watchCallback(), 300);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
});
|
|
59
|
+
watch([`${dir}/**`], WATCH_OPTIONS).on('all', (_, _path) => {
|
|
60
|
+
if (
|
|
61
|
+
_path.endsWith(path.join(dir, MANIFEST_FILE_NAME)) ||
|
|
62
|
+
_path.endsWith(path.join(dir, ICON_FILE_NAME))
|
|
63
|
+
) {
|
|
64
|
+
watchCallback(true);
|
|
65
|
+
} else {
|
|
66
|
+
_debouncedCallback();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
74
69
|
},
|
|
75
|
-
writeDemoFile
|
|
70
|
+
writeDemoFile(tag, outputDir, outputFile) {
|
|
76
71
|
const demoFileContent = `<meta charset="utf-8">\n<title>${tag} demo</title>\n<script src="./${path.basename(
|
|
77
72
|
outputFile,
|
|
78
73
|
)}"></script>\n\n\n<${tag}></${tag}>\n\n`;
|
|
@@ -83,18 +78,17 @@ module.exports = {
|
|
|
83
78
|
},
|
|
84
79
|
};
|
|
85
80
|
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Copies an asset file or directory from the source directory to a destination directory.
|
|
83
|
+
*
|
|
84
|
+
* @param {String} filePath
|
|
85
|
+
* @param {String} sourceDir
|
|
86
|
+
* @param {String} destDir
|
|
87
|
+
*/
|
|
88
|
+
function _copyFromToSync(filePath, sourceDir, destDir) {
|
|
89
|
+
const sourceFile = path.join(sourceDir, filePath);
|
|
88
90
|
if (fs.existsSync(sourceFile)) {
|
|
89
|
-
const destFile = path.join(destDir,
|
|
90
|
-
|
|
91
|
-
fs.mkdirSync(destDir, { recursive: true });
|
|
92
|
-
}
|
|
93
|
-
if (!fs.existsSync(path.dirname(path.join(destDir, fileName)))) {
|
|
94
|
-
fs.mkdirSync(path.dirname(path.join(destDir, fileName)), {
|
|
95
|
-
recursive: true,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
fs.copyFileSync(sourceFile, destFile);
|
|
91
|
+
const destFile = path.join(destDir, filePath);
|
|
92
|
+
fse.copySync(sourceFile, destFile);
|
|
99
93
|
}
|
|
100
94
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ixon-cdk/core",
|
|
3
|
-
"version": "1.2.0-next.
|
|
3
|
+
"version": "1.2.0-next.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "",
|
|
@@ -8,18 +8,18 @@
|
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"app-root-dir": "^1.0.2",
|
|
10
10
|
"archiver": "^5.3.1",
|
|
11
|
-
"axios": "^
|
|
11
|
+
"axios": "^1.3.4",
|
|
12
12
|
"chalk": "^4.1.2",
|
|
13
13
|
"chokidar": "^3.5.3",
|
|
14
14
|
"cors": "^2.8.5",
|
|
15
15
|
"crypto-js": "^4.1.1",
|
|
16
|
-
"express": "^4.
|
|
17
|
-
"
|
|
16
|
+
"express": "^4.18.2",
|
|
17
|
+
"fs-extra": "^11.1.1",
|
|
18
|
+
"glob": "^9.2.1",
|
|
18
19
|
"livereload": "^0.9.3",
|
|
19
20
|
"lodash": "^4.17.21",
|
|
20
21
|
"opener": "^1.5.2",
|
|
21
22
|
"prompts": "^2.4.2",
|
|
22
|
-
"
|
|
23
|
-
"yargs": "^17.4.1"
|
|
23
|
+
"yargs": "^17.7.1"
|
|
24
24
|
}
|
|
25
25
|
}
|
package/server/index.js
CHANGED
|
@@ -62,7 +62,18 @@ module.exports = class Server {
|
|
|
62
62
|
);
|
|
63
63
|
|
|
64
64
|
// Simulator app
|
|
65
|
-
|
|
65
|
+
let appDir;
|
|
66
|
+
try {
|
|
67
|
+
appDir = path.dirname(require.resolve('@ixon-cdk/simulator'));
|
|
68
|
+
} catch (e) {
|
|
69
|
+
// If require.resolve is invoked immediately after the simulator is installed, it will return
|
|
70
|
+
// a "MODULE_NOT_FOUND" error. In that case (as a fallback) we'll find the simulator app dir
|
|
71
|
+
// relative to the core module (which should have already been installed).
|
|
72
|
+
appDir = path.join(
|
|
73
|
+
require.resolve('@ixon-cdk/core'),
|
|
74
|
+
'../../simulator/dist',
|
|
75
|
+
);
|
|
76
|
+
}
|
|
66
77
|
app.get(`/${this._opts.componentBasePath}/*`, (req, res) => {
|
|
67
78
|
res.sendStatus(404);
|
|
68
79
|
});
|
|
@@ -184,6 +184,11 @@ module.exports = class TemplateService {
|
|
|
184
184
|
if (_result) {
|
|
185
185
|
variantIdx = _result.variantIdx;
|
|
186
186
|
}
|
|
187
|
+
|
|
188
|
+
if (variantIdx === undefined) {
|
|
189
|
+
logErrorMessage("No variant selected");
|
|
190
|
+
process.exit(1);
|
|
191
|
+
}
|
|
187
192
|
}
|
|
188
193
|
|
|
189
194
|
schema = this._interpolateSchema(schema, context);
|
|
@@ -194,6 +199,33 @@ module.exports = class TemplateService {
|
|
|
194
199
|
moduleNames.forEach((name) => ensureModule(name));
|
|
195
200
|
}
|
|
196
201
|
|
|
202
|
+
// optionally install types
|
|
203
|
+
if (variantIdx !== null && /typescript/i.test(schema.variants[variantIdx].name)) {
|
|
204
|
+
ensureModule('@ixon-cdk/types');
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// install dependencies
|
|
208
|
+
if (!!schema.dependencies) {
|
|
209
|
+
Object.keys(schema.dependencies).forEach(name =>
|
|
210
|
+
ensureModule(name, schema.dependencies[name], false),
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
if (!!schema.devDependencies) {
|
|
214
|
+
Object.keys(schema.devDependencies).forEach(name =>
|
|
215
|
+
ensureModule(name, schema.devDependencies[name]),
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
if (variantIdx !== null) {
|
|
219
|
+
const deps = schema.variants[variantIdx].dependencies;
|
|
220
|
+
const devDeps = schema.variants[variantIdx].devDependencies;
|
|
221
|
+
if (!!deps) {
|
|
222
|
+
Object.keys(deps).forEach(name => ensureModule(name, deps[name], false));
|
|
223
|
+
}
|
|
224
|
+
if (!!devDeps) {
|
|
225
|
+
Object.keys(devDeps).forEach(name => ensureModule(name, devDeps[name]));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
197
229
|
const componentRoot = this._configSrv.getNewComponentRoot();
|
|
198
230
|
|
|
199
231
|
schema.files.forEach((file) => {
|
|
@@ -310,15 +342,21 @@ module.exports = class TemplateService {
|
|
|
310
342
|
_discover() {
|
|
311
343
|
const dir = path.dirname(require.resolve('@ixon-cdk/templates'));
|
|
312
344
|
const files = fs.readdirSync(dir);
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
if (
|
|
317
|
-
|
|
318
|
-
|
|
345
|
+
const tail = ['iframe-wrapper'];
|
|
346
|
+
files
|
|
347
|
+
.sort((a, b) => {
|
|
348
|
+
if (tail.includes(a)) return 1;
|
|
349
|
+
return tail.includes(b) ? -1 : 0;
|
|
350
|
+
})
|
|
351
|
+
.forEach(file => {
|
|
352
|
+
if (fs.lstatSync(path.join(dir, file)).isDirectory()) {
|
|
353
|
+
const schemaFile = path.join(dir, file, 'schema.json');
|
|
354
|
+
if (fs.existsSync(schemaFile)) {
|
|
355
|
+
const schema = JSON.parse(fs.readFileSync(schemaFile));
|
|
356
|
+
this._schemas = { ...this._schemas, [file]: schema };
|
|
357
|
+
}
|
|
319
358
|
}
|
|
320
|
-
}
|
|
321
|
-
});
|
|
359
|
+
});
|
|
322
360
|
}
|
|
323
361
|
|
|
324
362
|
/**
|
package/utils.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
|
+
const fse = require('fs-extra');
|
|
2
3
|
const path = require('path');
|
|
3
4
|
const chalk = require('chalk');
|
|
5
|
+
const { globSync } = require('glob');
|
|
4
6
|
const flow = require('lodash/flow');
|
|
5
7
|
const camelCase = require('lodash/camelCase');
|
|
6
8
|
const upperFirst = require('lodash/upperFirst');
|
|
7
9
|
|
|
10
|
+
function dirContains(dir, globPattern) {
|
|
11
|
+
const files = globSync(path.join(dir, globPattern));
|
|
12
|
+
return !!files.length;
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
function getArgv() {
|
|
9
16
|
const remain = process.argv.slice(2);
|
|
10
17
|
const { argv } = require('yargs/yargs')(remain).version(false);
|
|
@@ -45,19 +52,17 @@ function moduleExists(moduleName) {
|
|
|
45
52
|
return exists;
|
|
46
53
|
}
|
|
47
54
|
|
|
48
|
-
function ensureModule(moduleName) {
|
|
49
|
-
if (!moduleName.startsWith('@ixon-cdk/')) {
|
|
50
|
-
logErrorMessage('Cannot install this module.');
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
55
|
+
function ensureModule(moduleName, moduleVersion = null, dev = true) {
|
|
53
56
|
if (!moduleExists(moduleName)) {
|
|
54
|
-
console.log(`Installing package '${moduleName}'...`);
|
|
55
57
|
if (moduleName.startsWith('@ixon-cdk/')) {
|
|
56
58
|
const cdkVersion = require('./package.json').version;
|
|
57
|
-
|
|
58
|
-
} else {
|
|
59
|
-
require('child_process').execSync(`npm install --save-dev ${moduleName}`);
|
|
59
|
+
moduleVersion = cdkVersion;
|
|
60
60
|
}
|
|
61
|
+
const v = !!moduleVersion ? '@' + moduleVersion : '';
|
|
62
|
+
console.log(`Installing package '${moduleName}${v}...`);
|
|
63
|
+
require('child_process').execSync(
|
|
64
|
+
`npm install --save${dev ? '-dev' : ''} ${moduleName}${v}`,
|
|
65
|
+
);
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
68
|
|
|
@@ -66,7 +71,7 @@ function zip(output, callback) {
|
|
|
66
71
|
const zipFile = path.join(`${outputDir}.zip`);
|
|
67
72
|
const stream = fs.createWriteStream(zipFile);
|
|
68
73
|
stream.on('close', () => {
|
|
69
|
-
|
|
74
|
+
fse.removeSync(outputDir);
|
|
70
75
|
callback(zipFile);
|
|
71
76
|
});
|
|
72
77
|
const archive = require('archiver')('zip', { zlib: { level: 9 } });
|
|
@@ -122,6 +127,7 @@ async function getFiles(dir) {
|
|
|
122
127
|
}
|
|
123
128
|
|
|
124
129
|
module.exports = {
|
|
130
|
+
dirContains,
|
|
125
131
|
getArgv,
|
|
126
132
|
getRootDir,
|
|
127
133
|
logErrorMessage,
|