directus-template-cli 0.4.1 → 0.4.3
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/dist/commands/apply.js +23 -13
- package/dist/lib/extract/extract-fields.js +8 -2
- package/dist/lib/extract/extract-relations.js +1 -1
- package/dist/lib/utils/log-error.js +1 -1
- package/dist/lib/utils/open-url.d.ts +1 -0
- package/dist/lib/utils/open-url.js +19 -0
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/dist/commands/apply.js
CHANGED
|
@@ -8,6 +8,7 @@ const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
|
8
8
|
const load_1 = tslib_1.__importDefault(require("../lib/load/"));
|
|
9
9
|
const auth_1 = require("../lib/utils/auth");
|
|
10
10
|
const log_error_1 = tslib_1.__importDefault(require("../lib/utils/log-error"));
|
|
11
|
+
const open_url_1 = tslib_1.__importDefault(require("../lib/utils/open-url"));
|
|
11
12
|
const path_1 = tslib_1.__importDefault(require("../lib/utils/path"));
|
|
12
13
|
const read_templates_1 = require("../lib/utils/read-templates");
|
|
13
14
|
const transform_github_url_1 = require("../lib/utils/transform-github-url");
|
|
@@ -17,17 +18,21 @@ async function getTemplate() {
|
|
|
17
18
|
{
|
|
18
19
|
choices: [
|
|
19
20
|
{
|
|
20
|
-
name: '
|
|
21
|
-
value: '
|
|
21
|
+
name: 'Community templates',
|
|
22
|
+
value: 'community',
|
|
22
23
|
},
|
|
23
24
|
{
|
|
24
25
|
name: 'From a local directory',
|
|
25
26
|
value: 'local',
|
|
26
27
|
},
|
|
27
28
|
{
|
|
28
|
-
name: 'From a GitHub repository',
|
|
29
|
+
name: 'From a public GitHub repository',
|
|
29
30
|
value: 'github',
|
|
30
31
|
},
|
|
32
|
+
{
|
|
33
|
+
name: 'Get premium templates',
|
|
34
|
+
value: 'directus-plus',
|
|
35
|
+
},
|
|
31
36
|
],
|
|
32
37
|
message: 'What type of template would you like to apply?',
|
|
33
38
|
name: 'templateType',
|
|
@@ -35,8 +40,8 @@ async function getTemplate() {
|
|
|
35
40
|
},
|
|
36
41
|
]);
|
|
37
42
|
let template;
|
|
38
|
-
if (templateType.templateType === '
|
|
39
|
-
// Get
|
|
43
|
+
if (templateType.templateType === 'community') {
|
|
44
|
+
// Get community templates
|
|
40
45
|
let templates = [];
|
|
41
46
|
// Resolve the path for downloading
|
|
42
47
|
const downloadDir = (0, path_1.default)(node_path_1.default.join(__dirname, '..', 'downloads', 'official'), false);
|
|
@@ -54,10 +59,10 @@ async function getTemplate() {
|
|
|
54
59
|
catch (error) {
|
|
55
60
|
(0, log_error_1.default)(error, { fatal: true });
|
|
56
61
|
}
|
|
57
|
-
const
|
|
62
|
+
const communityTemplateChoices = templates.map((template) => ({ name: template.templateName, value: template }));
|
|
58
63
|
template = await inquirer.prompt([
|
|
59
64
|
{
|
|
60
|
-
choices:
|
|
65
|
+
choices: communityTemplateChoices,
|
|
61
66
|
message: 'Select a template.',
|
|
62
67
|
name: 'template',
|
|
63
68
|
type: 'list',
|
|
@@ -100,23 +105,28 @@ async function getTemplate() {
|
|
|
100
105
|
(0, log_error_1.default)(error, { fatal: true });
|
|
101
106
|
}
|
|
102
107
|
}
|
|
108
|
+
if (templateType.templateType === 'directus-plus') {
|
|
109
|
+
(0, open_url_1.default)('https://directus.io/plus?utm_source=directus-template-cli&utm_content=apply-command');
|
|
110
|
+
core_1.ux.log('Redirecting to Directus website.');
|
|
111
|
+
core_1.ux.exit(0);
|
|
112
|
+
}
|
|
103
113
|
return template;
|
|
104
114
|
}
|
|
105
115
|
class ApplyCommand extends core_1.Command {
|
|
106
116
|
async run() {
|
|
107
117
|
const chosenTemplate = await getTemplate();
|
|
108
|
-
|
|
109
|
-
|
|
118
|
+
core_1.ux.log(`You selected ${chosenTemplate.template.templateName}`);
|
|
119
|
+
core_1.ux.log(separator);
|
|
110
120
|
const directusUrl = await (0, auth_1.getDirectusUrl)();
|
|
111
121
|
await (0, auth_1.getDirectusToken)(directusUrl);
|
|
112
|
-
|
|
122
|
+
core_1.ux.log(separator);
|
|
113
123
|
// Run load script
|
|
114
124
|
core_1.ux.log(`Applying template - ${chosenTemplate.template.templateName} to ${directusUrl}`);
|
|
115
125
|
await (0, load_1.default)(chosenTemplate.template.directoryPath);
|
|
116
126
|
core_1.ux.action.stop();
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
127
|
+
core_1.ux.log(separator);
|
|
128
|
+
core_1.ux.log('Template applied successfully.');
|
|
129
|
+
core_1.ux.exit(0);
|
|
120
130
|
}
|
|
121
131
|
}
|
|
122
132
|
ApplyCommand.description = 'Apply a template to a blank Directus instance.';
|
|
@@ -11,12 +11,17 @@ const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"
|
|
|
11
11
|
async function extractFields(dir) {
|
|
12
12
|
try {
|
|
13
13
|
const response = await sdk_2.api.client.request((0, sdk_1.readFields)());
|
|
14
|
+
if (!Array.isArray(response)) {
|
|
15
|
+
throw new TypeError('Unexpected response format');
|
|
16
|
+
}
|
|
14
17
|
const fields = response
|
|
15
18
|
.filter(
|
|
16
19
|
// @ts-ignore
|
|
17
|
-
(i) => !i.meta.system)
|
|
20
|
+
(i) => i.meta && !i.meta.system)
|
|
18
21
|
.map(i => {
|
|
19
|
-
|
|
22
|
+
if (i.meta) {
|
|
23
|
+
delete i.meta.id;
|
|
24
|
+
}
|
|
20
25
|
return i;
|
|
21
26
|
});
|
|
22
27
|
await (0, write_to_file_1.default)('fields', fields, dir);
|
|
@@ -25,6 +30,7 @@ async function extractFields(dir) {
|
|
|
25
30
|
catch (error) {
|
|
26
31
|
core_1.ux.warn('Error extracting Fields:');
|
|
27
32
|
core_1.ux.warn(error.message);
|
|
33
|
+
console.error(error);
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
36
|
exports.default = extractFields;
|
|
@@ -13,7 +13,7 @@ async function extractRelations(dir) {
|
|
|
13
13
|
const response = await sdk_2.api.client.request((0, sdk_1.readRelations)());
|
|
14
14
|
// Fetching fields to filter out system fields while retaining custom fields on system collections
|
|
15
15
|
const fields = await sdk_2.api.client.request((0, sdk_1.readFields)());
|
|
16
|
-
const customFields = fields.filter((i) => !i.meta.system);
|
|
16
|
+
const customFields = fields.filter((i) => { var _a; return !((_a = i.meta) === null || _a === void 0 ? void 0 : _a.system); });
|
|
17
17
|
const relations = response
|
|
18
18
|
// Filter out relations where the collection starts with 'directus_' && the field is not within the customFields array
|
|
19
19
|
.filter((i) => !i.collection.startsWith('directus_', 0)
|
|
@@ -5,7 +5,7 @@ const core_1 = require("@oclif/core");
|
|
|
5
5
|
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
6
|
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
7
7
|
function logError(error, options = {}) {
|
|
8
|
-
const errorMessage = `Status ${error.response.status} • ${error.errors[0].message}\n`;
|
|
8
|
+
const errorMessage = `Status ${error.response.status} • ${JSON.stringify(error.errors[0].message)}\n`;
|
|
9
9
|
if (options.fatal) {
|
|
10
10
|
core_1.ux.error(errorMessage);
|
|
11
11
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function openUrl(url: string): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_child_process_1 = require("node:child_process");
|
|
4
|
+
function openUrl(url) {
|
|
5
|
+
switch (process.platform) {
|
|
6
|
+
case 'darwin': {
|
|
7
|
+
(0, node_child_process_1.exec)(`open ${url}`);
|
|
8
|
+
break;
|
|
9
|
+
}
|
|
10
|
+
case 'win32': {
|
|
11
|
+
(0, node_child_process_1.exec)(`start ${url}`);
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
default: {
|
|
15
|
+
(0, node_child_process_1.exec)(`xdg-open ${url}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.default = openUrl;
|
package/oclif.manifest.json
CHANGED