directus-template-cli 0.4.0 → 0.4.2
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/README.md +1 -1
- package/dist/commands/apply.js +24 -14
- package/dist/lib/utils/open-url.d.ts +1 -0
- package/dist/lib/utils/open-url.js +19 -0
- package/dist/lib/utils/protected-domains.d.ts +1 -0
- package/dist/lib/utils/protected-domains.js +6 -0
- package/dist/lib/utils/validate-url.js +3 -2
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ A CLI tool to make applying or extracting Directus "templates" a little easier..
|
|
|
4
4
|
|
|
5
5
|
**Notes:**
|
|
6
6
|
|
|
7
|
-
- This is a pre-release. It is recommended for use on POC or
|
|
7
|
+
- This is a pre-release. It is recommended for use on POC, demo, or greenfield projects only.
|
|
8
8
|
- ⚠️ Known issues with using MySQL currently, please use ONLY PostgreSQL or SQLite for your database provider.
|
|
9
9
|
- Templates are applied / extracted on an all or nothing basis – meaning that all the schema, content, and system settings are extracted or applied. We'd love to support more granular operations in the future. (PRs welcome 🙏)
|
|
10
10
|
- If you are extracting or applying from a remote source, the script can take quite a while depending on the "size" of your instance (how many collections, how many items in each collection, number and size of assets, etc). The script applies a strict rate limit of 10 requests per second using bottleneck.
|
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);
|
|
@@ -44,7 +49,7 @@ async function getTemplate() {
|
|
|
44
49
|
throw new Error(`Invalid download directory: ${node_path_1.default.join(__dirname, '..', 'downloads', 'official')}`);
|
|
45
50
|
}
|
|
46
51
|
try {
|
|
47
|
-
const { dir } = await (0, giget_1.downloadTemplate)('github:directus-
|
|
52
|
+
const { dir } = await (0, giget_1.downloadTemplate)('github:directus-labs/directus-templates', {
|
|
48
53
|
dir: downloadDir,
|
|
49
54
|
force: true,
|
|
50
55
|
preferOffline: true,
|
|
@@ -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.';
|
|
@@ -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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const protectedDomains: string[];
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const protected_domains_1 = require("./protected-domains");
|
|
3
4
|
function validateUrl(url) {
|
|
4
5
|
try {
|
|
5
|
-
new URL(url);
|
|
6
|
-
return
|
|
6
|
+
const parsedUrl = new URL(url);
|
|
7
|
+
return !protected_domains_1.protectedDomains.includes(parsedUrl.hostname);
|
|
7
8
|
}
|
|
8
9
|
catch {
|
|
9
10
|
return false;
|
package/oclif.manifest.json
CHANGED