directus-template-cli 0.7.0-beta.3 → 0.7.0-beta.5
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/bin/dev +2 -3
- package/bin/dev.js +3 -0
- package/bin/run +0 -1
- package/bin/run.js +5 -0
- package/dist/commands/apply.d.ts +17 -17
- package/dist/commands/apply.js +160 -173
- package/dist/commands/extract.d.ts +13 -7
- package/dist/commands/extract.js +89 -73
- package/dist/commands/init.d.ts +7 -7
- package/dist/commands/init.js +78 -80
- package/dist/flags/common.d.ts +7 -7
- package/dist/flags/common.js +8 -11
- package/dist/index.js +1 -5
- package/dist/lib/constants.js +6 -9
- package/dist/lib/extract/extract-access.js +11 -15
- package/dist/lib/extract/extract-assets.js +20 -25
- package/dist/lib/extract/extract-collections.js +12 -16
- package/dist/lib/extract/extract-content.js +14 -19
- package/dist/lib/extract/extract-dashboards.js +22 -28
- package/dist/lib/extract/extract-extensions.js +12 -16
- package/dist/lib/extract/extract-fields.js +13 -17
- package/dist/lib/extract/extract-files.js +15 -19
- package/dist/lib/extract/extract-flows.js +22 -28
- package/dist/lib/extract/extract-folders.js +15 -19
- package/dist/lib/extract/extract-permissions.js +12 -16
- package/dist/lib/extract/extract-policies.js +12 -16
- package/dist/lib/extract/extract-presets.js +12 -16
- package/dist/lib/extract/extract-relations.js +14 -18
- package/dist/lib/extract/extract-roles.js +15 -19
- package/dist/lib/extract/extract-schema.js +17 -21
- package/dist/lib/extract/extract-settings.js +12 -16
- package/dist/lib/extract/extract-translations.js +12 -16
- package/dist/lib/extract/extract-users.js +15 -19
- package/dist/lib/extract/index.js +47 -51
- package/dist/lib/init/config.d.ts +1 -1
- package/dist/lib/init/config.js +2 -5
- package/dist/lib/init/index.js +54 -59
- package/dist/lib/init/types.js +1 -2
- package/dist/lib/init.d.ts +1 -0
- package/dist/lib/init.js +2 -0
- package/dist/lib/load/apply-flags.js +17 -23
- package/dist/lib/load/index.js +40 -44
- package/dist/lib/load/load-access.js +15 -20
- package/dist/lib/load/load-collections.js +27 -32
- package/dist/lib/load/load-dashboards.js +19 -25
- package/dist/lib/load/load-data.js +43 -49
- package/dist/lib/load/load-extensions.js +30 -38
- package/dist/lib/load/load-files.js +20 -24
- package/dist/lib/load/load-flows.js +23 -29
- package/dist/lib/load/load-folders.js +16 -20
- package/dist/lib/load/load-permissions.js +13 -17
- package/dist/lib/load/load-policies.js +14 -18
- package/dist/lib/load/load-presets.js +14 -18
- package/dist/lib/load/load-relations.d.ts +2 -0
- package/dist/lib/load/load-relations.js +16 -18
- package/dist/lib/load/load-roles.js +19 -23
- package/dist/lib/load/load-settings.js +18 -21
- package/dist/lib/load/load-translations.js +14 -18
- package/dist/lib/load/load-users.js +21 -25
- package/dist/lib/load/update-required-fields.js +13 -17
- package/dist/lib/sdk.d.ts +1 -2
- package/dist/lib/sdk.js +27 -27
- package/dist/lib/types/extension.js +1 -2
- package/dist/lib/utils/animated-bunny.js +9 -14
- package/dist/lib/utils/auth.d.ts +2 -2
- package/dist/lib/utils/auth.js +32 -33
- package/dist/lib/utils/catch-error.js +8 -11
- package/dist/lib/utils/check-template.js +4 -8
- package/dist/lib/utils/chunk-array.js +1 -5
- package/dist/lib/utils/ensure-dir.js +7 -12
- package/dist/lib/utils/filter-fields.js +1 -4
- package/dist/lib/utils/get-role-ids.d.ts +1 -1
- package/dist/lib/utils/get-role-ids.js +7 -12
- package/dist/lib/utils/get-template.js +33 -37
- package/dist/lib/utils/logger.js +11 -13
- package/dist/lib/utils/open-url.js +5 -8
- package/dist/lib/utils/parse-github-url.js +4 -9
- package/dist/lib/utils/path.js +6 -10
- package/dist/lib/utils/protected-domains.js +1 -4
- package/dist/lib/utils/read-file.js +8 -12
- package/dist/lib/utils/read-templates.js +9 -15
- package/dist/lib/utils/system-fields.js +19 -22
- package/dist/lib/utils/template-defaults.d.ts +1 -1
- package/dist/lib/utils/template-defaults.js +5 -14
- package/dist/lib/utils/transform-github-url.js +1 -5
- package/dist/lib/utils/validate-url.js +3 -6
- package/dist/lib/utils/wait.js +1 -5
- package/dist/lib/utils/write-to-file.js +8 -11
- package/dist/services/docker.js +19 -24
- package/dist/services/github.d.ts +1 -1
- package/dist/services/github.js +8 -12
- package/oclif.manifest.json +4 -4
- package/package.json +36 -32
package/bin/dev
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
|
|
3
2
|
const oclif = require('@oclif/core')
|
|
4
3
|
|
|
5
|
-
const path = require('path')
|
|
4
|
+
const path = require('node:path')
|
|
6
5
|
const project = path.join(__dirname, '..', 'tsconfig.json')
|
|
7
6
|
|
|
8
7
|
// In dev mode -> use ts-node and dev plugins
|
|
@@ -11,7 +10,7 @@ process.env.NODE_ENV = 'development'
|
|
|
11
10
|
require('ts-node').register({project})
|
|
12
11
|
|
|
13
12
|
// In dev mode, always show stack traces
|
|
14
|
-
oclif.settings.debug = true
|
|
13
|
+
oclif.settings.debug = true
|
|
15
14
|
|
|
16
15
|
// Start the CLI
|
|
17
16
|
oclif.run().then(oclif.flush).catch(oclif.Errors.handle)
|
package/bin/dev.js
ADDED
package/bin/run
CHANGED
package/bin/run.js
ADDED
package/dist/commands/apply.d.ts
CHANGED
|
@@ -3,23 +3,23 @@ export default class ApplyCommand extends Command {
|
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
|
-
content: import("@oclif/core/
|
|
7
|
-
dashboards: import("@oclif/core/
|
|
8
|
-
directusToken: import("@oclif/core/
|
|
9
|
-
directusUrl: import("@oclif/core/
|
|
10
|
-
extensions: import("@oclif/core/
|
|
11
|
-
files: import("@oclif/core/
|
|
12
|
-
flows: import("@oclif/core/
|
|
13
|
-
partial: import("@oclif/core/
|
|
14
|
-
permissions: import("@oclif/core/
|
|
15
|
-
programmatic: import("@oclif/core/
|
|
16
|
-
schema: import("@oclif/core/
|
|
17
|
-
settings: import("@oclif/core/
|
|
18
|
-
templateLocation: import("@oclif/core/
|
|
19
|
-
templateType: import("@oclif/core/
|
|
20
|
-
userEmail: import("@oclif/core/
|
|
21
|
-
userPassword: import("@oclif/core/
|
|
22
|
-
users: import("@oclif/core/
|
|
6
|
+
content: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
7
|
+
dashboards: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
8
|
+
directusToken: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
directusUrl: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
extensions: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
files: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
12
|
+
flows: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
13
|
+
partial: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
14
|
+
permissions: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
15
|
+
programmatic: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
16
|
+
schema: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
17
|
+
settings: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
18
|
+
templateLocation: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
19
|
+
templateType: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
20
|
+
userEmail: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
21
|
+
userPassword: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
22
|
+
users: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
25
|
* MAIN
|
package/dist/commands/apply.js
CHANGED
|
@@ -1,19 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { Command, Flags, ux } from '@oclif/core';
|
|
2
|
+
import { text, select, password } from '@clack/prompts';
|
|
3
|
+
import * as path from 'pathe';
|
|
4
|
+
import * as customFlags from '../flags/common.js';
|
|
5
|
+
import { DIRECTUS_PINK, SEPARATOR } from '../lib/constants.js';
|
|
6
|
+
import { validateInteractiveFlags, validateProgrammaticFlags } from '../lib/load/apply-flags.js';
|
|
7
|
+
import apply from '../lib/load/index.js';
|
|
8
|
+
import { getDirectusToken, getDirectusUrl, initializeDirectusApi } from '../lib/utils/auth.js';
|
|
9
|
+
import catchError from '../lib/utils/catch-error.js';
|
|
10
|
+
import { getCommunityTemplates, getGithubTemplate, getInteractiveLocalTemplate, getLocalTemplate } from '../lib/utils/get-template.js';
|
|
11
|
+
import { logger } from '../lib/utils/logger.js';
|
|
12
|
+
import openUrl from '../lib/utils/open-url.js';
|
|
13
|
+
export default class ApplyCommand extends Command {
|
|
14
|
+
static description = 'Apply a template to a blank Directus instance.';
|
|
15
|
+
static examples = [
|
|
16
|
+
'$ directus-template-cli apply',
|
|
17
|
+
'$ directus-template-cli apply -p --directusUrl="http://localhost:8055" --directusToken="admin-token-here" --templateLocation="./my-template" --templateType="local"',
|
|
18
|
+
'$ directus-template-cli@beta apply -p --directusUrl="http://localhost:8055" --directusToken="admin-token-here" --templateLocation="./my-template" --templateType="local" --partial --no-content --no-users',
|
|
19
|
+
];
|
|
20
|
+
static flags = {
|
|
21
|
+
content: Flags.boolean({
|
|
22
|
+
allowNo: true,
|
|
23
|
+
default: undefined,
|
|
24
|
+
description: 'Load Content (data)',
|
|
25
|
+
}),
|
|
26
|
+
dashboards: Flags.boolean({
|
|
27
|
+
allowNo: true,
|
|
28
|
+
default: undefined,
|
|
29
|
+
description: 'Load Dashboards (dashboards, panels)',
|
|
30
|
+
}),
|
|
31
|
+
directusToken: customFlags.directusToken,
|
|
32
|
+
directusUrl: customFlags.directusUrl,
|
|
33
|
+
extensions: Flags.boolean({
|
|
34
|
+
allowNo: true,
|
|
35
|
+
default: undefined,
|
|
36
|
+
description: 'Load Extensions',
|
|
37
|
+
}),
|
|
38
|
+
files: Flags.boolean({
|
|
39
|
+
allowNo: true,
|
|
40
|
+
default: undefined,
|
|
41
|
+
description: 'Load Files (files, folders)',
|
|
42
|
+
}),
|
|
43
|
+
flows: Flags.boolean({
|
|
44
|
+
allowNo: true,
|
|
45
|
+
default: undefined,
|
|
46
|
+
description: 'Load Flows (operations, flows)',
|
|
47
|
+
}),
|
|
48
|
+
partial: Flags.boolean({
|
|
49
|
+
dependsOn: ['programmatic'],
|
|
50
|
+
description: 'Enable partial template application (all components enabled by default)',
|
|
51
|
+
summary: 'Enable partial template application',
|
|
52
|
+
}),
|
|
53
|
+
permissions: Flags.boolean({
|
|
54
|
+
allowNo: true,
|
|
55
|
+
default: undefined,
|
|
56
|
+
description: 'Loads permissions data. Collections include: directus_roles, directus_policies, directus_access, directus_permissions.',
|
|
57
|
+
summary: 'Load permissions (roles, policies, access, permissions)',
|
|
58
|
+
}),
|
|
59
|
+
programmatic: customFlags.programmatic,
|
|
60
|
+
schema: Flags.boolean({
|
|
61
|
+
allowNo: true,
|
|
62
|
+
default: undefined,
|
|
63
|
+
description: 'Load schema (collections, relations)',
|
|
64
|
+
}),
|
|
65
|
+
settings: Flags.boolean({
|
|
66
|
+
allowNo: true,
|
|
67
|
+
default: undefined,
|
|
68
|
+
description: 'Load settings (project settings, translations, presets)',
|
|
69
|
+
}),
|
|
70
|
+
templateLocation: customFlags.templateLocation,
|
|
71
|
+
templateType: Flags.string({
|
|
72
|
+
default: 'local',
|
|
73
|
+
dependsOn: ['programmatic'],
|
|
74
|
+
description: 'Type of template to apply. You can apply templates from our community repo, local directories, or public repositories from Github. Defaults to local. ',
|
|
75
|
+
env: 'TEMPLATE_TYPE',
|
|
76
|
+
options: ['community', 'local', 'github'],
|
|
77
|
+
summary: 'Type of template to apply. Options: community, local, github.',
|
|
78
|
+
}),
|
|
79
|
+
userEmail: customFlags.userEmail,
|
|
80
|
+
userPassword: customFlags.userPassword,
|
|
81
|
+
users: Flags.boolean({
|
|
82
|
+
allowNo: true,
|
|
83
|
+
default: undefined,
|
|
84
|
+
description: 'Load users',
|
|
85
|
+
}),
|
|
86
|
+
};
|
|
17
87
|
/**
|
|
18
88
|
* MAIN
|
|
19
89
|
* Run the command
|
|
@@ -31,88 +101,83 @@ class ApplyCommand extends core_1.Command {
|
|
|
31
101
|
* @returns {Promise<void>} - Returns nothing
|
|
32
102
|
*/
|
|
33
103
|
async runInteractive(flags) {
|
|
34
|
-
const validatedFlags =
|
|
35
|
-
|
|
36
|
-
const templateType = await
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
name: 'templateType',
|
|
46
|
-
type: 'list',
|
|
47
|
-
},
|
|
48
|
-
]);
|
|
104
|
+
const validatedFlags = validateInteractiveFlags(flags);
|
|
105
|
+
// /* TODO: Replace with custom styledHeader function */ ux.styledHeader(ux.colorize(DIRECTUS_PURPLE, 'Directus Template CLI - Apply'))
|
|
106
|
+
const templateType = await select({
|
|
107
|
+
options: [
|
|
108
|
+
{ label: 'Community templates', value: 'community' },
|
|
109
|
+
{ label: 'From a local directory', value: 'local' },
|
|
110
|
+
{ label: 'From a public GitHub repository', value: 'github' },
|
|
111
|
+
{ label: 'Get premium templates', value: 'directus-plus' },
|
|
112
|
+
],
|
|
113
|
+
message: 'What type of template would you like to apply?',
|
|
114
|
+
});
|
|
49
115
|
let template;
|
|
50
|
-
switch (templateType
|
|
116
|
+
switch (templateType) {
|
|
51
117
|
case 'community': {
|
|
52
|
-
const templates = await
|
|
53
|
-
const
|
|
54
|
-
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
name: 'selectedTemplate',
|
|
58
|
-
type: 'list',
|
|
59
|
-
},
|
|
60
|
-
]);
|
|
118
|
+
const templates = await getCommunityTemplates();
|
|
119
|
+
const selectedTemplate = await select({
|
|
120
|
+
options: templates.map(t => ({ label: t.templateName, value: t })),
|
|
121
|
+
message: 'Select a template.',
|
|
122
|
+
});
|
|
61
123
|
template = selectedTemplate;
|
|
62
124
|
break;
|
|
63
125
|
}
|
|
64
126
|
case 'local': {
|
|
65
|
-
const localTemplateDir = await
|
|
127
|
+
const localTemplateDir = await text({
|
|
128
|
+
message: 'What is the local template directory?',
|
|
129
|
+
});
|
|
66
130
|
template = await this.selectLocalTemplate(localTemplateDir);
|
|
67
131
|
break;
|
|
68
132
|
}
|
|
69
133
|
case 'github': {
|
|
70
|
-
const ghTemplateUrl = await
|
|
71
|
-
|
|
134
|
+
const ghTemplateUrl = await text({
|
|
135
|
+
message: 'What is the public GitHub repository URL?',
|
|
136
|
+
});
|
|
137
|
+
template = await getGithubTemplate(ghTemplateUrl);
|
|
72
138
|
break;
|
|
73
139
|
}
|
|
74
140
|
case 'directus-plus': {
|
|
75
|
-
(
|
|
76
|
-
|
|
77
|
-
|
|
141
|
+
openUrl('https://directus.io/plus?utm_source=directus-template-cli&utm_content=apply-command');
|
|
142
|
+
ux.stdout('Redirecting to Directus website.');
|
|
143
|
+
ux.exit(0);
|
|
78
144
|
}
|
|
79
145
|
}
|
|
80
|
-
|
|
81
|
-
|
|
146
|
+
ux.stdout(`You selected ${ux.colorize(DIRECTUS_PINK, template.templateName)}`);
|
|
147
|
+
ux.stdout(SEPARATOR);
|
|
82
148
|
// Get Directus URL
|
|
83
|
-
const directusUrl = await
|
|
149
|
+
const directusUrl = await getDirectusUrl();
|
|
84
150
|
validatedFlags.directusUrl = directusUrl;
|
|
85
151
|
// Prompt for login method
|
|
86
|
-
const loginMethod = await
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
type: 'list',
|
|
96
|
-
},
|
|
97
|
-
]);
|
|
98
|
-
if (loginMethod.loginMethod === 'token') {
|
|
99
|
-
const directusToken = await (0, auth_1.getDirectusToken)(directusUrl);
|
|
152
|
+
const loginMethod = await select({
|
|
153
|
+
options: [
|
|
154
|
+
{ label: 'Directus Access Token', value: 'token' },
|
|
155
|
+
{ label: 'Email and Password', value: 'email' },
|
|
156
|
+
],
|
|
157
|
+
message: 'How do you want to log in?',
|
|
158
|
+
});
|
|
159
|
+
if (loginMethod === 'token') {
|
|
160
|
+
const directusToken = await getDirectusToken(directusUrl);
|
|
100
161
|
validatedFlags.directusToken = directusToken;
|
|
101
162
|
}
|
|
102
163
|
else {
|
|
103
|
-
const userEmail = await
|
|
164
|
+
const userEmail = await text({
|
|
165
|
+
message: 'What is your email?',
|
|
166
|
+
});
|
|
104
167
|
validatedFlags.userEmail = userEmail;
|
|
105
|
-
const userPassword = await
|
|
168
|
+
const userPassword = await password({
|
|
169
|
+
message: 'What is your password?',
|
|
170
|
+
});
|
|
106
171
|
validatedFlags.userPassword = userPassword;
|
|
107
172
|
}
|
|
108
|
-
await
|
|
173
|
+
await initializeDirectusApi(validatedFlags);
|
|
109
174
|
if (template) {
|
|
110
|
-
|
|
111
|
-
await (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
175
|
+
// /* TODO: Replace with custom styledHeader function */ ux.styledHeader(ux.colorize(DIRECTUS_PURPLE, `Applying template - ${template.templateName} to ${directusUrl}`))
|
|
176
|
+
await apply(template.directoryPath, validatedFlags);
|
|
177
|
+
ux.action.stop();
|
|
178
|
+
ux.stdout(SEPARATOR);
|
|
179
|
+
ux.stdout('Template applied successfully.');
|
|
180
|
+
ux.exit(0);
|
|
116
181
|
}
|
|
117
182
|
}
|
|
118
183
|
/**
|
|
@@ -122,36 +187,36 @@ class ApplyCommand extends core_1.Command {
|
|
|
122
187
|
* @returns {Promise<void>} - Returns nothing
|
|
123
188
|
*/
|
|
124
189
|
async runProgrammatic(flags) {
|
|
125
|
-
const validatedFlags =
|
|
190
|
+
const validatedFlags = validateProgrammaticFlags(flags);
|
|
126
191
|
let template;
|
|
127
192
|
switch (validatedFlags.templateType) {
|
|
128
193
|
case 'community': {
|
|
129
|
-
const templates = await
|
|
194
|
+
const templates = await getCommunityTemplates();
|
|
130
195
|
template = templates.find(t => t.templateName === validatedFlags.templateLocation) || templates[0];
|
|
131
196
|
break;
|
|
132
197
|
}
|
|
133
198
|
case 'local': {
|
|
134
|
-
template = await
|
|
199
|
+
template = await getLocalTemplate(validatedFlags.templateLocation);
|
|
135
200
|
break;
|
|
136
201
|
}
|
|
137
202
|
case 'github': {
|
|
138
|
-
template = await
|
|
203
|
+
template = await getGithubTemplate(validatedFlags.templateLocation);
|
|
139
204
|
break;
|
|
140
205
|
}
|
|
141
206
|
default: {
|
|
142
|
-
(
|
|
207
|
+
catchError('Invalid template type. Please check your template type.', {
|
|
143
208
|
fatal: true,
|
|
144
209
|
});
|
|
145
210
|
}
|
|
146
211
|
}
|
|
147
|
-
await
|
|
212
|
+
await initializeDirectusApi(validatedFlags);
|
|
148
213
|
const logMessage = `Applying template - ${template.templateName} to ${validatedFlags.directusUrl}`;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
await (
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
214
|
+
// /* TODO: Replace with custom styledHeader function */ ux.styledHeader(logMessage)
|
|
215
|
+
logger.log('info', logMessage);
|
|
216
|
+
await apply(template.directoryPath, validatedFlags);
|
|
217
|
+
ux.action.stop();
|
|
218
|
+
ux.stdout(SEPARATOR);
|
|
219
|
+
ux.stdout('Template applied successfully.');
|
|
155
220
|
// ux.exit(0)
|
|
156
221
|
}
|
|
157
222
|
/**
|
|
@@ -162,104 +227,26 @@ class ApplyCommand extends core_1.Command {
|
|
|
162
227
|
*/
|
|
163
228
|
async selectLocalTemplate(localTemplateDir) {
|
|
164
229
|
try {
|
|
165
|
-
const templates = await
|
|
230
|
+
const templates = await getInteractiveLocalTemplate(localTemplateDir);
|
|
166
231
|
if (templates.length === 1) {
|
|
167
232
|
return templates[0];
|
|
168
233
|
}
|
|
169
|
-
const
|
|
170
|
-
{
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
name: 'selectedTemplate',
|
|
177
|
-
type: 'list',
|
|
178
|
-
},
|
|
179
|
-
]);
|
|
234
|
+
const selectedTemplate = await select({
|
|
235
|
+
options: templates.map(t => ({
|
|
236
|
+
label: `${t.templateName} (${path.basename(t.directoryPath)})`,
|
|
237
|
+
value: t,
|
|
238
|
+
})),
|
|
239
|
+
message: 'Multiple templates found. Please select one:',
|
|
240
|
+
});
|
|
180
241
|
return selectedTemplate;
|
|
181
242
|
}
|
|
182
243
|
catch (error) {
|
|
183
244
|
if (error instanceof Error) {
|
|
184
|
-
|
|
245
|
+
ux.error(error.message);
|
|
185
246
|
}
|
|
186
247
|
else {
|
|
187
|
-
|
|
248
|
+
ux.error('An unknown error occurred while getting the local template.');
|
|
188
249
|
}
|
|
189
250
|
}
|
|
190
251
|
}
|
|
191
252
|
}
|
|
192
|
-
ApplyCommand.description = 'Apply a template to a blank Directus instance.';
|
|
193
|
-
ApplyCommand.examples = [
|
|
194
|
-
'$ directus-template-cli apply',
|
|
195
|
-
'$ directus-template-cli apply -p --directusUrl="http://localhost:8055" --directusToken="admin-token-here" --templateLocation="./my-template" --templateType="local"',
|
|
196
|
-
'$ directus-template-cli@beta apply -p --directusUrl="http://localhost:8055" --directusToken="admin-token-here" --templateLocation="./my-template" --templateType="local" --partial --no-content --no-users',
|
|
197
|
-
];
|
|
198
|
-
ApplyCommand.flags = {
|
|
199
|
-
content: core_1.Flags.boolean({
|
|
200
|
-
allowNo: true,
|
|
201
|
-
default: undefined,
|
|
202
|
-
description: 'Load Content (data)',
|
|
203
|
-
}),
|
|
204
|
-
dashboards: core_1.Flags.boolean({
|
|
205
|
-
allowNo: true,
|
|
206
|
-
default: undefined,
|
|
207
|
-
description: 'Load Dashboards (dashboards, panels)',
|
|
208
|
-
}),
|
|
209
|
-
directusToken: customFlags.directusToken,
|
|
210
|
-
directusUrl: customFlags.directusUrl,
|
|
211
|
-
extensions: core_1.Flags.boolean({
|
|
212
|
-
allowNo: true,
|
|
213
|
-
default: undefined,
|
|
214
|
-
description: 'Load Extensions',
|
|
215
|
-
}),
|
|
216
|
-
files: core_1.Flags.boolean({
|
|
217
|
-
allowNo: true,
|
|
218
|
-
default: undefined,
|
|
219
|
-
description: 'Load Files (files, folders)',
|
|
220
|
-
}),
|
|
221
|
-
flows: core_1.Flags.boolean({
|
|
222
|
-
allowNo: true,
|
|
223
|
-
default: undefined,
|
|
224
|
-
description: 'Load Flows (operations, flows)',
|
|
225
|
-
}),
|
|
226
|
-
partial: core_1.Flags.boolean({
|
|
227
|
-
dependsOn: ['programmatic'],
|
|
228
|
-
description: 'Enable partial template application (all components enabled by default)',
|
|
229
|
-
summary: 'Enable partial template application',
|
|
230
|
-
}),
|
|
231
|
-
permissions: core_1.Flags.boolean({
|
|
232
|
-
allowNo: true,
|
|
233
|
-
default: undefined,
|
|
234
|
-
description: 'Loads permissions data. Collections include: directus_roles, directus_policies, directus_access, directus_permissions.',
|
|
235
|
-
summary: 'Load permissions (roles, policies, access, permissions)',
|
|
236
|
-
}),
|
|
237
|
-
programmatic: customFlags.programmatic,
|
|
238
|
-
schema: core_1.Flags.boolean({
|
|
239
|
-
allowNo: true,
|
|
240
|
-
default: undefined,
|
|
241
|
-
description: 'Load schema (collections, relations)',
|
|
242
|
-
}),
|
|
243
|
-
settings: core_1.Flags.boolean({
|
|
244
|
-
allowNo: true,
|
|
245
|
-
default: undefined,
|
|
246
|
-
description: 'Load settings (project settings, translations, presets)',
|
|
247
|
-
}),
|
|
248
|
-
templateLocation: customFlags.templateLocation,
|
|
249
|
-
templateType: core_1.Flags.string({
|
|
250
|
-
default: 'local',
|
|
251
|
-
dependsOn: ['programmatic'],
|
|
252
|
-
description: 'Type of template to apply. You can apply templates from our community repo, local directories, or public repositories from Github. Defaults to local. ',
|
|
253
|
-
env: 'TEMPLATE_TYPE',
|
|
254
|
-
options: ['community', 'local', 'github'],
|
|
255
|
-
summary: 'Type of template to apply. Options: community, local, github.',
|
|
256
|
-
}),
|
|
257
|
-
userEmail: customFlags.userEmail,
|
|
258
|
-
userPassword: customFlags.userPassword,
|
|
259
|
-
users: core_1.Flags.boolean({
|
|
260
|
-
allowNo: true,
|
|
261
|
-
default: undefined,
|
|
262
|
-
description: 'Load users',
|
|
263
|
-
}),
|
|
264
|
-
};
|
|
265
|
-
exports.default = ApplyCommand;
|
|
@@ -3,13 +3,13 @@ export default class ExtractCommand extends Command {
|
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
|
-
directusToken: import("@oclif/core/
|
|
7
|
-
directusUrl: import("@oclif/core/
|
|
8
|
-
programmatic: import("@oclif/core/
|
|
9
|
-
templateLocation: import("@oclif/core/
|
|
10
|
-
templateName: import("@oclif/core/
|
|
11
|
-
userEmail: import("@oclif/core/
|
|
12
|
-
userPassword: import("@oclif/core/
|
|
6
|
+
directusToken: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
directusUrl: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
programmatic: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
templateLocation: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
templateName: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
userEmail: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
userPassword: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
15
|
* Main run method for the ExtractCommand
|
|
@@ -36,6 +36,12 @@ export default class ExtractCommand extends Command {
|
|
|
36
36
|
* @returns {Promise<void>} - Returns nothing
|
|
37
37
|
*/
|
|
38
38
|
private runProgrammatic;
|
|
39
|
+
/**
|
|
40
|
+
* Helper function to create styled headers since ux.styledHeader is removed in v4
|
|
41
|
+
* @param text - The text to style as a header
|
|
42
|
+
* @returns {void}
|
|
43
|
+
*/
|
|
44
|
+
private styledHeader;
|
|
39
45
|
/**
|
|
40
46
|
* Validates the flags for programmatic mode
|
|
41
47
|
* @param {ExtractFlags} flags - The command flags to validate
|