directus-template-cli 0.5.0-beta.8 → 0.5.0
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 +186 -17
- package/dist/commands/apply.d.ts +25 -3
- package/dist/commands/apply.js +78 -121
- package/dist/commands/extract.d.ts +29 -1
- package/dist/commands/extract.js +72 -50
- package/dist/flags/common.d.ts +7 -0
- package/dist/flags/common.js +41 -0
- package/dist/lib/extract/extract-access.js +5 -3
- package/dist/lib/extract/extract-assets.d.ts +0 -414
- package/dist/lib/extract/extract-assets.js +29 -25
- package/dist/lib/extract/extract-collections.js +5 -4
- package/dist/lib/extract/extract-content.d.ts +0 -2
- package/dist/lib/extract/extract-content.js +16 -15
- package/dist/lib/extract/extract-dashboards.js +8 -6
- package/dist/lib/extract/extract-extensions.js +5 -3
- package/dist/lib/extract/extract-fields.js +4 -2
- package/dist/lib/extract/extract-files.js +5 -3
- package/dist/lib/extract/extract-flows.js +8 -6
- package/dist/lib/extract/extract-folders.js +5 -3
- package/dist/lib/extract/extract-permissions.js +5 -3
- package/dist/lib/extract/extract-policies.js +5 -3
- package/dist/lib/extract/extract-presets.js +5 -3
- package/dist/lib/extract/extract-relations.js +5 -3
- package/dist/lib/extract/extract-roles.js +5 -3
- package/dist/lib/extract/extract-schema.js +6 -8
- package/dist/lib/extract/extract-settings.js +5 -3
- package/dist/lib/extract/extract-translations.js +6 -6
- package/dist/lib/extract/extract-users.js +6 -6
- package/dist/lib/load/apply-flags.d.ts +22 -0
- package/dist/lib/load/apply-flags.js +67 -0
- package/dist/lib/load/index.js +9 -5
- package/dist/lib/load/load-access.js +45 -37
- package/dist/lib/load/load-collections.js +20 -2
- package/dist/lib/load/load-dashboards.js +27 -25
- package/dist/lib/load/load-data.js +3 -3
- package/dist/lib/load/load-files.js +42 -46
- package/dist/lib/load/load-flows.js +33 -32
- package/dist/lib/load/load-folders.js +32 -30
- package/dist/lib/load/load-permissions.js +14 -12
- package/dist/lib/load/load-policies.js +21 -19
- package/dist/lib/load/load-presets.js +25 -23
- package/dist/lib/load/load-relations.js +17 -15
- package/dist/lib/load/load-roles.js +43 -41
- package/dist/lib/load/load-translations.js +22 -20
- package/dist/lib/load/load-users.js +42 -39
- package/dist/lib/load/update-required-fields.d.ts +1 -0
- package/dist/lib/load/update-required-fields.js +24 -0
- package/dist/lib/sdk.d.ts +20 -2
- package/dist/lib/sdk.js +124 -9
- package/dist/lib/utils/auth.d.ts +26 -0
- package/dist/lib/utils/auth.js +48 -4
- package/dist/lib/utils/catch-error.d.ts +15 -2
- package/dist/lib/utils/catch-error.js +31 -25
- package/oclif.manifest.json +74 -28
- package/package.json +2 -2
- package/dist/lib/interfaces.d.ts +0 -8
- package/dist/lib/interfaces.js +0 -2
package/README.md
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
# Directus Template CLI
|
|
2
2
|
|
|
3
|
-
A CLI tool
|
|
3
|
+
A streamlined CLI tool for managing Directus templates - making it easy to apply and extract template configurations across instances.
|
|
4
4
|
|
|
5
|
-
**
|
|
5
|
+
⚠️ **Beta Release Notice**: This tool is currently in beta and best suited for:
|
|
6
|
+
- Proof of Concept (POC) projects
|
|
7
|
+
- Demo environments
|
|
8
|
+
- New project setups
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
- ⚠️ Known issues with using MySQL currently, please use ONLY PostgreSQL or SQLite for your database provider.
|
|
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
|
-
- 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.
|
|
10
|
+
We strongly recommend against using this tool in existing production environments or as a critical part of your CI/CD pipeline without thorough testing. Always create backups before applying templates.
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
**Important Notes:**
|
|
13
|
+
- **Primary Purpose**: Built to deploy templates created by the Directus Core Team. While community templates are supported, the unlimited possible configurations make comprehensive support challenging.
|
|
14
|
+
- **Database Compatibility**: PostgreSQL and SQLite are recommended. MySQL users may encounter known issues.
|
|
15
|
+
- **Performance**: Remote operations (extract/apply) are rate-limited to 10 requests/second using bottleneck. Processing time varies based on your instance size (collections, items, assets).
|
|
16
|
+
- **Version Compatibility**:
|
|
17
|
+
- v0.5.0+: Compatible with Directus 11 and up
|
|
18
|
+
- v0.4.0: Use for Directus 10 compatibility (`npx directus-template-cli@0.4 extract/apply`)
|
|
18
19
|
|
|
19
20
|
Using the @latest tag ensures you're receiving the latest version of the packaged templates with the CLI. You can review [the specific versions on NPM](https://www.npmjs.com/package/directus-template-cli) and use @{version} syntax to apply the templates included with that version.
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
## Applying a Template
|
|
23
|
+
|
|
24
|
+
🚧 Make backups of your project/database before applying templates.
|
|
22
25
|
|
|
23
26
|
1. Create a Directus instance on [Directus Cloud](https://directus.cloud) or using self-hosted version.
|
|
24
27
|
2. Login and create a Static Access Token for the admin user.
|
|
@@ -26,24 +29,190 @@ Using the @latest tag ensures you're receiving the latest version of the package
|
|
|
26
29
|
4. Run the following command on the terminal and follow the prompts.
|
|
27
30
|
|
|
28
31
|
```
|
|
29
|
-
|
|
32
|
+
npx directus-template-cli@latest apply
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
You can choose from our community maintained templates or you can also choose a template from a local directory or a public GitHub repository.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### Programmatic Mode
|
|
39
|
+
|
|
40
|
+
By default, the CLI will run in interactive mode. For CI/CD pipelines or automated scripts, you can use the programmatic mode:
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
Using a token:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
npx directus-template-cli@latest apply -p --directusUrl="http://localhost:8055" --directusToken="admin-token-here" --templateLocation="./my-template" --templateType="local"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Using email/password:
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
npx directus-template-cli@latest apply -p --directusUrl="http://localhost:8055" --userEmail="admin@example.com" --userPassword="admin" --templateLocation="./my-template" --templateType="local"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Partial apply (apply only some of the parts of a template to the instance):
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
npx directus-template-cli@latest apply -p --directusUrl="http://localhost:8055" --userEmail="admin@example.com" --userPassword="your-password" --templateLocation="./my-template" --templateType="local" --partial --schema --permissions --no-content
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Available flags for programmatic mode:
|
|
63
|
+
|
|
64
|
+
- `--directusUrl`: URL of the Directus instance to apply the template to (required)
|
|
65
|
+
- `--directusToken`: Token to use for the Directus instance (required if not using email/password)
|
|
66
|
+
- `--userEmail`: Email for Directus authentication (required if not using token)
|
|
67
|
+
- `--userPassword`: Password for Directus authentication (required if not using token)
|
|
68
|
+
- `--templateLocation`: Location of the template to apply (required)
|
|
69
|
+
- `--templateType`: Type of template to apply. Options: community, local, github. Defaults to `local`.
|
|
70
|
+
- `--partial`: Enable partial template application
|
|
71
|
+
- `--content`: Load Content (data)
|
|
72
|
+
- `--dashboards`: Load Dashboards
|
|
73
|
+
- `--extensions`: Load Extensions
|
|
74
|
+
- `--files`: Load Files
|
|
75
|
+
- `--flows`: Load Flows
|
|
76
|
+
- `--permissions`: Load Permissions
|
|
77
|
+
- `--schema`: Load Schema
|
|
78
|
+
- `--settings`: Load Settings
|
|
79
|
+
- `--users`: Load Users
|
|
80
|
+
|
|
81
|
+
When using `--partial`, you can also use `--no` flags to exclude specific components from being applied. For example:
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
npx directus-template-cli@latest apply -p --directusUrl="http://localhost:8055" --userEmail="admin@example.com" --userPassword="your-password" --templateLocation="./my-template" --templateType="local" --partial --no-content --no-users
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
This command will apply the template but exclude content and users. Available `--no` flags include:
|
|
88
|
+
|
|
89
|
+
- `--no-content`: Skip loading Content (data)
|
|
90
|
+
- `--no-dashboards`: Skip loading Dashboards
|
|
91
|
+
- `--no-extensions`: Skip loading Extensions
|
|
92
|
+
- `--no-files`: Skip loading Files
|
|
93
|
+
- `--no-flows`: Skip loading Flows
|
|
94
|
+
- `--no-permissions`: Skip loading PermissionsI
|
|
95
|
+
- `--no-schema`: Skip loading Schema
|
|
96
|
+
- `--no-settings`: Skip loading Settings
|
|
97
|
+
- `--no-users`: Skip loading Users
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
#### Template Component Dependencies
|
|
101
|
+
|
|
102
|
+
When applying templates, certain components have dependencies on others. Here are the key relationships to be aware of:
|
|
103
|
+
|
|
104
|
+
- `--users`: Depends on `--permissions`. If you include users, permissions will automatically be included.
|
|
105
|
+
- `--permissions`: Depends on `--schema`. If you include permissions, the schema will automatically be included.
|
|
106
|
+
- `--content`: Depends on `--schema`. If you include content, the schema will automatically be included.
|
|
107
|
+
- `--files`: No direct dependencies, but often related to content. Consider including `--content` if you're including files.
|
|
108
|
+
- `--flows`: No direct dependencies, but may interact with other components. Consider your specific use case.
|
|
109
|
+
- `--dashboards`: No direct dependencies, but often rely on data from other components.
|
|
110
|
+
- `--extensions`: No direct dependencies, but may interact with other components.
|
|
111
|
+
- `--settings`: No direct dependencies, but affects the overall system configuration.
|
|
112
|
+
|
|
113
|
+
When using the `--partial` flag, keep these dependencies in mind. For example:
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
npx directus-template-cli@latest apply -p --directusUrl="http://localhost:8055" --directusToken="admin-token-here" --templateLocation="./my-template" --templateType="local" --partial --users
|
|
30
117
|
```
|
|
31
118
|
|
|
32
|
-
|
|
119
|
+
This command will automatically include `--permissions` and `--schema` along with `--users`, even if not explicitly specified.
|
|
33
120
|
|
|
34
|
-
|
|
121
|
+
If you use `--no-` flags, be cautious about excluding dependencies. For instance, using `--no-schema` while including `--content` may lead to errors or incomplete application of the template.
|
|
122
|
+
|
|
123
|
+
#### Using Environment Variables
|
|
124
|
+
|
|
125
|
+
You can also pass flags as environment variables. This can be useful for CI/CD pipelines or when you want to avoid exposing sensitive information in command-line arguments. Here are the available environment variables:
|
|
126
|
+
|
|
127
|
+
- `TARGET_DIRECTUS_URL`: Equivalent to `--directusUrl`
|
|
128
|
+
- `TARGET_DIRECTUS_TOKEN`: Equivalent to `--directusToken`
|
|
129
|
+
- `TARGET_DIRECTUS_EMAIL`: Equivalent to `--userEmail`
|
|
130
|
+
- `TARGET_DIRECTUS_PASSWORD`: Equivalent to `--userPassword`
|
|
131
|
+
- `TEMPLATE_LOCATION`: Equivalent to `--templateLocation`
|
|
132
|
+
- `TEMPLATE_TYPE`: Equivalent to `--templateType`
|
|
133
|
+
-
|
|
134
|
+
|
|
135
|
+
### Existing Data
|
|
136
|
+
|
|
137
|
+
You can apply a template to an existing Directus instance. This is nice because you can have smaller templates that you can "compose" for various use cases. The CLI tries to be smart about existing items in the target Directus instance. But mileage may vary depending on the size and complexity of the template and the existing instance.
|
|
138
|
+
|
|
139
|
+
**System Collections**
|
|
140
|
+
|
|
141
|
+
In most of the system collections (collections,roles, permissions, etc.), if an item with the same identifier already exists, it will be typically be SKIPPED vs overwritten.
|
|
142
|
+
|
|
143
|
+
Exceptions:
|
|
144
|
+
|
|
145
|
+
- directus_settings: The CLI attempts to merge the template's project settings with the existing settings in the target instance. Using the existing settings as a base and updating them with the values from the template. This should prevent overwriting branding, themes, and other customizations.
|
|
146
|
+
|
|
147
|
+
**Your Collections:**
|
|
148
|
+
|
|
149
|
+
For data in your own user-created collections, if an item has the same primary key, the data will be overwritten with the incoming data from the template.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Extracting a Template
|
|
35
154
|
|
|
36
155
|
The CLI can also extract a template from a Directus instance so that it can be applied to other instances.
|
|
37
156
|
|
|
157
|
+
Note: We do not currently support partial extraction. The entire template will be extracted. We thought it better to have the data and not need it, than need it and not have it.
|
|
158
|
+
|
|
38
159
|
1. Make sure you remove any sensitive data from the Directus instance you don't want to include in the template.
|
|
39
160
|
2. Login and create a Static Access Token for the admin user.
|
|
40
161
|
3. Copy the static token and your Directus URL.
|
|
41
162
|
4. Run the following command on the terminal and follow the prompts.
|
|
42
163
|
|
|
43
164
|
```
|
|
44
|
-
|
|
165
|
+
npx directus-template-cli@latest extract
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Programmatic Mode
|
|
169
|
+
|
|
170
|
+
By default, the CLI will run in interactive mode. For CI/CD pipelines or automated scripts, you can use the programmatic mode:
|
|
171
|
+
|
|
172
|
+
Using a token:
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
npx directus-template-cli@latest extract -p --templateName="My Template" --templateLocation="./my-template" --directusToken="admin-token-here" --directusUrl="http://localhost:8055"
|
|
45
176
|
```
|
|
46
177
|
|
|
178
|
+
Using email/password:
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
npx directus-template-cli@latest extract -p --templateName="My Template" --templateLocation="./my-template" --userEmail="admin@example.com" --userPassword="admin" --directusUrl="http://localhost:8055"
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Available flags for programmatic mode:
|
|
185
|
+
|
|
186
|
+
- `--directusUrl`: URL of the Directus instance to extract the template from (required)
|
|
187
|
+
- `--directusToken`: Token to use for the Directus instance (required if not using email/password)
|
|
188
|
+
- `--userEmail`: Email for Directus authentication (required if not using token)
|
|
189
|
+
- `--userPassword`: Password for Directus authentication (required if not using token)
|
|
190
|
+
- `--templateLocation`: Directory to extract the template to (required)
|
|
191
|
+
- `--templateName`: Name of the template (required)
|
|
192
|
+
|
|
193
|
+
#### Using Environment Variables
|
|
194
|
+
|
|
195
|
+
Similar to the Apply command, you can use environment variables for the Extract command as well:
|
|
196
|
+
|
|
197
|
+
- `SOURCE_DIRECTUS_URL`: Equivalent to `--directusUrl`
|
|
198
|
+
- `SOURCE_DIRECTUS_TOKEN`: Equivalent to `--directusToken`
|
|
199
|
+
- `SOURCE_DIRECTUS_EMAIL`: Equivalent to `--userEmail`
|
|
200
|
+
- `SOURCE_DIRECTUS_PASSWORD`: Equivalent to `--userPassword`
|
|
201
|
+
- `TEMPLATE_LOCATION`: Equivalent to `--templateLocation`
|
|
202
|
+
|
|
203
|
+
## Logs
|
|
204
|
+
|
|
205
|
+
The Directus Template CLI logs information to a file in the `.directus-template-cli/logs` directory.
|
|
206
|
+
|
|
207
|
+
Logs are automatically generated for each run of the CLI. Here's how the logging system works:
|
|
208
|
+
- A new log file is created for each CLI run.
|
|
209
|
+
- Log files are stored in the `.directus-template-cli/logs` directory within your current working directory.
|
|
210
|
+
- Each log file is named `run-[timestamp].log`, where `[timestamp]` is the ISO timestamp of when the CLI was initiated.
|
|
211
|
+
|
|
212
|
+
The logger automatically sanitizes sensitive information such as passwords, tokens, and keys before writing to the log file. But it may not catch everything. Just be aware of this and make sure to remove the log files when they are no longer needed.
|
|
213
|
+
|
|
214
|
+
Note: If you encounter any issues with the CLI, providing these log files can greatly assist in diagnosing and resolving the problem.
|
|
215
|
+
|
|
47
216
|
## License
|
|
48
217
|
|
|
49
218
|
This tool is licensed under the [MIT License](https://opensource.org/licenses/MIT).
|
package/dist/commands/apply.d.ts
CHANGED
|
@@ -17,13 +17,35 @@ export default class ApplyCommand extends Command {
|
|
|
17
17
|
settings: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
18
18
|
templateLocation: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
19
19
|
templateType: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
20
|
+
userEmail: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
21
|
+
userPassword: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
20
22
|
users: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
21
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* MAIN
|
|
26
|
+
* Run the command
|
|
27
|
+
* @returns {Promise<void>} - Returns nothing
|
|
28
|
+
*/
|
|
22
29
|
run(): Promise<void>;
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
/**
|
|
31
|
+
* INTERACTIVE
|
|
32
|
+
* Run the command in interactive mode
|
|
33
|
+
* @param flags - The ApplyFlags
|
|
34
|
+
* @returns {Promise<void>} - Returns nothing
|
|
35
|
+
*/
|
|
25
36
|
private runInteractive;
|
|
37
|
+
/**
|
|
38
|
+
* PROGRAMMATIC
|
|
39
|
+
* Run the command in programmatic mode
|
|
40
|
+
* @param flags - The ApplyFlags
|
|
41
|
+
* @returns {Promise<void>} - Returns nothing
|
|
42
|
+
*/
|
|
26
43
|
private runProgrammatic;
|
|
44
|
+
/**
|
|
45
|
+
* INTERACTIVE
|
|
46
|
+
* Select a local template from the given directory
|
|
47
|
+
* @param localTemplateDir - The local template directory path
|
|
48
|
+
* @returns {Promise<Template>} - Returns the selected template
|
|
49
|
+
*/
|
|
27
50
|
private selectLocalTemplate;
|
|
28
|
-
private validateFlags;
|
|
29
51
|
}
|
package/dist/commands/apply.js
CHANGED
|
@@ -1,45 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const sdk_1 = require("@directus/sdk");
|
|
5
4
|
const core_1 = require("@oclif/core");
|
|
6
5
|
const inquirer = tslib_1.__importStar(require("inquirer"));
|
|
6
|
+
const path = tslib_1.__importStar(require("node:path"));
|
|
7
|
+
const customFlags = tslib_1.__importStar(require("../flags/common"));
|
|
7
8
|
const constants_1 = require("../lib/constants");
|
|
9
|
+
const apply_flags_1 = require("../lib/load/apply-flags");
|
|
8
10
|
const index_js_1 = tslib_1.__importDefault(require("../lib/load/index.js"));
|
|
9
|
-
const sdk_2 = require("../lib/sdk");
|
|
10
11
|
const auth_1 = require("../lib/utils/auth");
|
|
11
12
|
const catch_error_1 = tslib_1.__importDefault(require("../lib/utils/catch-error"));
|
|
12
13
|
const get_template_1 = require("../lib/utils/get-template");
|
|
13
14
|
const logger_1 = require("../lib/utils/logger");
|
|
14
15
|
const open_url_1 = tslib_1.__importDefault(require("../lib/utils/open-url"));
|
|
15
16
|
class ApplyCommand extends core_1.Command {
|
|
16
|
-
|
|
17
|
+
/**
|
|
18
|
+
* MAIN
|
|
19
|
+
* Run the command
|
|
20
|
+
* @returns {Promise<void>} - Returns nothing
|
|
21
|
+
*/
|
|
17
22
|
async run() {
|
|
18
23
|
const { flags } = await this.parse(ApplyCommand);
|
|
19
24
|
const typedFlags = flags;
|
|
20
25
|
await (typedFlags.programmatic ? this.runProgrammatic(typedFlags) : this.runInteractive(typedFlags));
|
|
21
26
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
(0, catch_error_1.default)('-- Invalid Directus token. Please check your credentials.', {
|
|
31
|
-
fatal: true,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
redirectToDirectusPlus() {
|
|
36
|
-
(0, open_url_1.default)('https://directus.io/plus?utm_source=directus-template-cli&utm_content=apply-command');
|
|
37
|
-
core_1.ux.log('Redirecting to Directus website.');
|
|
38
|
-
core_1.ux.exit(0);
|
|
39
|
-
}
|
|
27
|
+
/**
|
|
28
|
+
* INTERACTIVE
|
|
29
|
+
* Run the command in interactive mode
|
|
30
|
+
* @param flags - The ApplyFlags
|
|
31
|
+
* @returns {Promise<void>} - Returns nothing
|
|
32
|
+
*/
|
|
40
33
|
async runInteractive(flags) {
|
|
41
|
-
const validatedFlags =
|
|
42
|
-
core_1.ux.styledHeader(core_1.ux.colorize(constants_1.DIRECTUS_PURPLE, '
|
|
34
|
+
const validatedFlags = (0, apply_flags_1.validateInteractiveFlags)(flags);
|
|
35
|
+
core_1.ux.styledHeader(core_1.ux.colorize(constants_1.DIRECTUS_PURPLE, 'Directus Template CLI - Apply'));
|
|
43
36
|
const templateType = await inquirer.prompt([
|
|
44
37
|
{
|
|
45
38
|
choices: [
|
|
@@ -79,16 +72,40 @@ class ApplyCommand extends core_1.Command {
|
|
|
79
72
|
break;
|
|
80
73
|
}
|
|
81
74
|
case 'directus-plus': {
|
|
82
|
-
|
|
75
|
+
(0, open_url_1.default)('https://directus.io/plus?utm_source=directus-template-cli&utm_content=apply-command');
|
|
76
|
+
core_1.ux.log('Redirecting to Directus website.');
|
|
77
|
+
core_1.ux.exit(0);
|
|
83
78
|
}
|
|
84
79
|
}
|
|
85
80
|
core_1.ux.log(`You selected ${core_1.ux.colorize(constants_1.DIRECTUS_PINK, template.templateName)}`);
|
|
86
81
|
core_1.ux.log(constants_1.SEPARATOR);
|
|
87
|
-
// Get Directus URL
|
|
82
|
+
// Get Directus URL
|
|
88
83
|
const directusUrl = await (0, auth_1.getDirectusUrl)();
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
84
|
+
validatedFlags.directusUrl = directusUrl;
|
|
85
|
+
// Prompt for login method
|
|
86
|
+
const loginMethod = await inquirer.prompt([
|
|
87
|
+
{
|
|
88
|
+
choices: [
|
|
89
|
+
{ name: 'Directus Access Token', value: 'token' },
|
|
90
|
+
{ name: 'Email and Password', value: 'email' },
|
|
91
|
+
],
|
|
92
|
+
default: 'token',
|
|
93
|
+
message: 'How do you want to log in?',
|
|
94
|
+
name: 'loginMethod',
|
|
95
|
+
type: 'list',
|
|
96
|
+
},
|
|
97
|
+
]);
|
|
98
|
+
if (loginMethod.loginMethod === 'token') {
|
|
99
|
+
const directusToken = await (0, auth_1.getDirectusToken)(directusUrl);
|
|
100
|
+
validatedFlags.directusToken = directusToken;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const userEmail = await core_1.ux.prompt('What is your email?');
|
|
104
|
+
validatedFlags.userEmail = userEmail;
|
|
105
|
+
const userPassword = await core_1.ux.prompt('What is your password?', { type: 'hide' });
|
|
106
|
+
validatedFlags.userPassword = userPassword;
|
|
107
|
+
}
|
|
108
|
+
await (0, auth_1.initializeDirectusApi)(validatedFlags);
|
|
92
109
|
if (template) {
|
|
93
110
|
core_1.ux.styledHeader(core_1.ux.colorize(constants_1.DIRECTUS_PURPLE, `Applying template - ${template.templateName} to ${directusUrl}`));
|
|
94
111
|
await (0, index_js_1.default)(template.directoryPath, validatedFlags);
|
|
@@ -98,8 +115,14 @@ class ApplyCommand extends core_1.Command {
|
|
|
98
115
|
core_1.ux.exit(0);
|
|
99
116
|
}
|
|
100
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* PROGRAMMATIC
|
|
120
|
+
* Run the command in programmatic mode
|
|
121
|
+
* @param flags - The ApplyFlags
|
|
122
|
+
* @returns {Promise<void>} - Returns nothing
|
|
123
|
+
*/
|
|
101
124
|
async runProgrammatic(flags) {
|
|
102
|
-
const validatedFlags =
|
|
125
|
+
const validatedFlags = (0, apply_flags_1.validateProgrammaticFlags)(flags);
|
|
103
126
|
let template;
|
|
104
127
|
switch (validatedFlags.templateType) {
|
|
105
128
|
case 'community': {
|
|
@@ -121,7 +144,7 @@ class ApplyCommand extends core_1.Command {
|
|
|
121
144
|
});
|
|
122
145
|
}
|
|
123
146
|
}
|
|
124
|
-
await
|
|
147
|
+
await (0, auth_1.initializeDirectusApi)(validatedFlags);
|
|
125
148
|
const logMessage = `Applying template - ${template.templateName} to ${validatedFlags.directusUrl}`;
|
|
126
149
|
core_1.ux.styledHeader(logMessage);
|
|
127
150
|
logger_1.logger.log('info', logMessage);
|
|
@@ -131,6 +154,12 @@ class ApplyCommand extends core_1.Command {
|
|
|
131
154
|
core_1.ux.info('Template applied successfully.');
|
|
132
155
|
core_1.ux.exit(0);
|
|
133
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* INTERACTIVE
|
|
159
|
+
* Select a local template from the given directory
|
|
160
|
+
* @param localTemplateDir - The local template directory path
|
|
161
|
+
* @returns {Promise<Template>} - Returns the selected template
|
|
162
|
+
*/
|
|
134
163
|
async selectLocalTemplate(localTemplateDir) {
|
|
135
164
|
try {
|
|
136
165
|
const templates = await (0, get_template_1.getInteractiveLocalTemplate)(localTemplateDir);
|
|
@@ -139,7 +168,10 @@ class ApplyCommand extends core_1.Command {
|
|
|
139
168
|
}
|
|
140
169
|
const { selectedTemplate } = await inquirer.prompt([
|
|
141
170
|
{
|
|
142
|
-
choices: templates.map(t => ({
|
|
171
|
+
choices: templates.map(t => ({
|
|
172
|
+
name: `${t.templateName} (${path.basename(t.directoryPath)})`,
|
|
173
|
+
value: t,
|
|
174
|
+
})),
|
|
143
175
|
message: 'Multiple templates found. Please select one:',
|
|
144
176
|
name: 'selectedTemplate',
|
|
145
177
|
type: 'list',
|
|
@@ -156,55 +188,6 @@ class ApplyCommand extends core_1.Command {
|
|
|
156
188
|
}
|
|
157
189
|
}
|
|
158
190
|
}
|
|
159
|
-
validateFlags(flags) {
|
|
160
|
-
if (flags.programmatic) {
|
|
161
|
-
if (!flags.directusUrl || !flags.directusToken) {
|
|
162
|
-
core_1.ux.error('Directus URL and token are required for programmatic mode.');
|
|
163
|
-
}
|
|
164
|
-
if (!flags.templateLocation) {
|
|
165
|
-
core_1.ux.error('Template location is required for programmatic mode.');
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
const loadFlags = [
|
|
169
|
-
'content',
|
|
170
|
-
'dashboards',
|
|
171
|
-
'extensions',
|
|
172
|
-
'files',
|
|
173
|
-
'flows',
|
|
174
|
-
'permissions',
|
|
175
|
-
'schema',
|
|
176
|
-
'settings',
|
|
177
|
-
'users',
|
|
178
|
-
];
|
|
179
|
-
const validatedFlags = { ...flags };
|
|
180
|
-
if (flags.partial) {
|
|
181
|
-
const enabledFlags = loadFlags.filter(flag => flags[flag] === true);
|
|
182
|
-
if (enabledFlags.length === 0) {
|
|
183
|
-
core_1.ux.error('When using --partial, at least one component flag must be set to true.');
|
|
184
|
-
}
|
|
185
|
-
// Handle dependencies
|
|
186
|
-
if (flags.content) {
|
|
187
|
-
validatedFlags.schema = true;
|
|
188
|
-
validatedFlags.files = true;
|
|
189
|
-
if (!flags.schema || !flags.files) {
|
|
190
|
-
core_1.ux.warn('Content loading requires schema and files. Enabling schema and files flags.');
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
if (flags.users) {
|
|
194
|
-
validatedFlags.permissions = true;
|
|
195
|
-
if (!flags.permissions) {
|
|
196
|
-
core_1.ux.warn('User loading requires permissions. Enabling permissions flag.');
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
// If not partial, set all flags to true
|
|
202
|
-
for (const flag of loadFlags) {
|
|
203
|
-
validatedFlags[flag] = true;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return validatedFlags;
|
|
207
|
-
}
|
|
208
191
|
}
|
|
209
192
|
ApplyCommand.description = 'Apply a template to a blank Directus instance.';
|
|
210
193
|
ApplyCommand.examples = [
|
|
@@ -215,38 +198,29 @@ ApplyCommand.examples = [
|
|
|
215
198
|
ApplyCommand.flags = {
|
|
216
199
|
content: core_1.Flags.boolean({
|
|
217
200
|
allowNo: true,
|
|
218
|
-
default:
|
|
201
|
+
default: undefined,
|
|
219
202
|
description: 'Load Content (data)',
|
|
220
|
-
relationships: [
|
|
221
|
-
{ flags: ['schema', 'files'], type: 'all' },
|
|
222
|
-
],
|
|
223
203
|
}),
|
|
224
204
|
dashboards: core_1.Flags.boolean({
|
|
225
205
|
allowNo: true,
|
|
226
|
-
default:
|
|
206
|
+
default: undefined,
|
|
227
207
|
description: 'Load Dashboards (dashboards, panels)',
|
|
228
208
|
}),
|
|
229
|
-
directusToken:
|
|
230
|
-
|
|
231
|
-
env: 'TARGET_DIRECTUS_TOKEN',
|
|
232
|
-
}),
|
|
233
|
-
directusUrl: core_1.Flags.string({
|
|
234
|
-
description: 'URL of the Directus instance to apply the template to',
|
|
235
|
-
env: 'TARGET_DIRECTUS_URL',
|
|
236
|
-
}),
|
|
209
|
+
directusToken: customFlags.directusToken,
|
|
210
|
+
directusUrl: customFlags.directusUrl,
|
|
237
211
|
extensions: core_1.Flags.boolean({
|
|
238
212
|
allowNo: true,
|
|
239
|
-
default:
|
|
213
|
+
default: undefined,
|
|
240
214
|
description: 'Load Extensions',
|
|
241
215
|
}),
|
|
242
216
|
files: core_1.Flags.boolean({
|
|
243
217
|
allowNo: true,
|
|
244
|
-
default:
|
|
218
|
+
default: undefined,
|
|
245
219
|
description: 'Load Files (files, folders)',
|
|
246
220
|
}),
|
|
247
221
|
flows: core_1.Flags.boolean({
|
|
248
222
|
allowNo: true,
|
|
249
|
-
default:
|
|
223
|
+
default: undefined,
|
|
250
224
|
description: 'Load Flows (operations, flows)',
|
|
251
225
|
}),
|
|
252
226
|
partial: core_1.Flags.boolean({
|
|
@@ -256,31 +230,22 @@ ApplyCommand.flags = {
|
|
|
256
230
|
}),
|
|
257
231
|
permissions: core_1.Flags.boolean({
|
|
258
232
|
allowNo: true,
|
|
259
|
-
default:
|
|
233
|
+
default: undefined,
|
|
260
234
|
description: 'Loads permissions data. Collections include: directus_roles, directus_policies, directus_access, directus_permissions.',
|
|
261
235
|
summary: 'Load permissions (roles, policies, access, permissions)',
|
|
262
236
|
}),
|
|
263
|
-
programmatic:
|
|
264
|
-
char: 'p',
|
|
265
|
-
default: false,
|
|
266
|
-
description: 'Run in programmatic mode (non-interactive) for use cases such as CI/CD pipelines.',
|
|
267
|
-
summary: 'Run in programmatic mode',
|
|
268
|
-
}),
|
|
237
|
+
programmatic: customFlags.programmatic,
|
|
269
238
|
schema: core_1.Flags.boolean({
|
|
270
239
|
allowNo: true,
|
|
271
|
-
default:
|
|
240
|
+
default: undefined,
|
|
272
241
|
description: 'Load schema (collections, relations)',
|
|
273
242
|
}),
|
|
274
243
|
settings: core_1.Flags.boolean({
|
|
275
244
|
allowNo: true,
|
|
276
|
-
default:
|
|
245
|
+
default: undefined,
|
|
277
246
|
description: 'Load settings (project settings, translations, presets)',
|
|
278
247
|
}),
|
|
279
|
-
templateLocation:
|
|
280
|
-
dependsOn: ['programmatic', 'templateType'],
|
|
281
|
-
description: 'Location of the template to apply',
|
|
282
|
-
env: 'TEMPLATE_LOCATION',
|
|
283
|
-
}),
|
|
248
|
+
templateLocation: customFlags.templateLocation,
|
|
284
249
|
templateType: core_1.Flags.string({
|
|
285
250
|
default: 'local',
|
|
286
251
|
dependsOn: ['programmatic'],
|
|
@@ -289,20 +254,12 @@ ApplyCommand.flags = {
|
|
|
289
254
|
options: ['community', 'local', 'github'],
|
|
290
255
|
summary: 'Type of template to apply. Options: community, local, github.',
|
|
291
256
|
}),
|
|
257
|
+
userEmail: customFlags.userEmail,
|
|
258
|
+
userPassword: customFlags.userPassword,
|
|
292
259
|
users: core_1.Flags.boolean({
|
|
293
260
|
allowNo: true,
|
|
294
|
-
default:
|
|
261
|
+
default: undefined,
|
|
295
262
|
description: 'Load users',
|
|
296
|
-
relationships: [
|
|
297
|
-
{ flags: ['permissions'], type: 'all' },
|
|
298
|
-
],
|
|
299
263
|
}),
|
|
300
264
|
};
|
|
301
265
|
exports.default = ApplyCommand;
|
|
302
|
-
function templateFlagsDefault({ flags }) {
|
|
303
|
-
// If programmatic is true, and partial is not set, return true
|
|
304
|
-
if (flags.programmatic && !flags.partial) {
|
|
305
|
-
return true;
|
|
306
|
-
}
|
|
307
|
-
return false;
|
|
308
|
-
}
|
|
@@ -8,11 +8,39 @@ export default class ExtractCommand extends Command {
|
|
|
8
8
|
programmatic: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
9
9
|
templateLocation: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
10
10
|
templateName: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
11
|
+
userEmail: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
12
|
+
userPassword: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
11
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Main run method for the ExtractCommand
|
|
16
|
+
* @returns {Promise<void>} - Returns nothing
|
|
17
|
+
*/
|
|
12
18
|
run(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Extracts the template to the specified directory
|
|
21
|
+
* @param {string} templateName - The name of the template to extract
|
|
22
|
+
* @param {string} directory - The directory to extract the template to
|
|
23
|
+
* @param {ExtractFlags} flags - The command flags
|
|
24
|
+
* @returns {Promise<void>} - Returns nothing
|
|
25
|
+
*/
|
|
13
26
|
private extractTemplate;
|
|
14
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Runs the interactive mode for template extraction
|
|
29
|
+
* @param {ExtractFlags} flags - The command flags
|
|
30
|
+
* @returns {Promise<void>} - Returns nothing
|
|
31
|
+
*/
|
|
15
32
|
private runInteractive;
|
|
33
|
+
/**
|
|
34
|
+
* Runs the programmatic mode for template extraction
|
|
35
|
+
* @param {ExtractFlags} flags - The command flags
|
|
36
|
+
* @returns {Promise<void>} - Returns nothing
|
|
37
|
+
*/
|
|
16
38
|
private runProgrammatic;
|
|
39
|
+
/**
|
|
40
|
+
* Validates the flags for programmatic mode
|
|
41
|
+
* @param {ExtractFlags} flags - The command flags to validate
|
|
42
|
+
* @throws {Error} If required flags are missing
|
|
43
|
+
* @returns {void}
|
|
44
|
+
*/
|
|
17
45
|
private validateProgrammaticFlags;
|
|
18
46
|
}
|