directus-template-cli 0.7.0-beta.1 → 0.7.0-beta.11
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.js +6 -0
- package/bin/run.js +5 -0
- package/dist/commands/apply.d.ts +17 -17
- package/dist/commands/apply.js +165 -173
- package/dist/commands/base.d.ts +15 -0
- package/dist/commands/base.js +45 -0
- package/dist/commands/extract.d.ts +16 -7
- package/dist/commands/extract.js +81 -73
- package/dist/commands/init.d.ts +21 -15
- package/dist/commands/init.js +209 -155
- package/dist/flags/common.d.ts +8 -7
- package/dist/flags/common.js +13 -11
- package/dist/index.js +1 -5
- package/dist/lib/constants.d.ts +7 -5
- package/dist/lib/constants.js +17 -14
- 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 +4 -7
- package/dist/lib/init/index.d.ts +10 -9
- package/dist/lib/init/index.js +129 -85
- package/dist/lib/init/types.js +1 -2
- package/dist/lib/load/apply-flags.js +17 -23
- package/dist/lib/load/index.d.ts +1 -12
- 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/types.d.ts +18 -0
- package/dist/lib/types.js +1 -0
- package/dist/lib/utils/animated-bunny.d.ts +2 -0
- package/dist/lib/utils/animated-bunny.js +62 -0
- package/dist/lib/utils/auth.d.ts +8 -6
- package/dist/lib/utils/auth.js +48 -39
- 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.d.ts +10 -5
- package/dist/lib/utils/parse-github-url.js +80 -45
- 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/sanitize-flags.d.ts +3 -0
- package/dist/lib/utils/sanitize-flags.js +4 -0
- package/dist/lib/utils/system-fields.js +19 -22
- package/dist/lib/utils/template-config.d.ts +16 -0
- package/dist/lib/utils/template-config.js +34 -0
- 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 +82 -29
- package/dist/services/github.d.ts +1 -1
- package/dist/services/github.js +53 -22
- package/dist/services/posthog.d.ts +37 -0
- package/dist/services/posthog.js +104 -0
- package/oclif.manifest.json +32 -13
- package/package.json +41 -31
- package/bin/dev +0 -17
- package/bin/run +0 -5
package/dist/commands/extract.js
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import { text, password, select, intro, log } from '@clack/prompts';
|
|
2
|
+
import { Command, ux } from '@oclif/core';
|
|
3
|
+
import slugify from '@sindresorhus/slugify';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'pathe';
|
|
7
|
+
import * as customFlags from '../flags/common.js';
|
|
8
|
+
import { DIRECTUS_PINK, DIRECTUS_PURPLE, SEPARATOR, BSL_LICENSE_TEXT } from '../lib/constants.js';
|
|
9
|
+
import { animatedBunny } from '../lib/utils/animated-bunny.js';
|
|
10
|
+
import extract from '../lib/extract/index.js';
|
|
11
|
+
import { getDirectusToken, getDirectusUrl, initializeDirectusApi, validateAuthFlags } from '../lib/utils/auth.js';
|
|
12
|
+
import catchError from '../lib/utils/catch-error.js';
|
|
13
|
+
import { generatePackageJsonContent, generateReadmeContent, } from '../lib/utils/template-defaults.js';
|
|
14
|
+
export default class ExtractCommand extends Command {
|
|
15
|
+
static description = 'Extract a template from a Directus instance.';
|
|
16
|
+
static examples = [
|
|
17
|
+
'$ directus-template-cli extract',
|
|
18
|
+
'$ directus-template-cli extract -p --templateName="My Template" --templateLocation="./my-template" --directusToken="admin-token-here" --directusUrl="http://localhost:8055"',
|
|
19
|
+
];
|
|
20
|
+
static flags = {
|
|
21
|
+
directusToken: customFlags.directusToken,
|
|
22
|
+
directusUrl: customFlags.directusUrl,
|
|
23
|
+
programmatic: customFlags.programmatic,
|
|
24
|
+
templateLocation: customFlags.templateLocation,
|
|
25
|
+
templateName: customFlags.templateName,
|
|
26
|
+
userEmail: customFlags.userEmail,
|
|
27
|
+
userPassword: customFlags.userPassword,
|
|
28
|
+
};
|
|
16
29
|
/**
|
|
17
30
|
* Main run method for the ExtractCommand
|
|
18
31
|
* @returns {Promise<void>} - Returns nothing
|
|
@@ -31,29 +44,30 @@ class ExtractCommand extends core_1.Command {
|
|
|
31
44
|
*/
|
|
32
45
|
async extractTemplate(templateName, directory, flags) {
|
|
33
46
|
try {
|
|
34
|
-
if (!
|
|
35
|
-
|
|
47
|
+
if (!fs.existsSync(directory)) {
|
|
48
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
36
49
|
}
|
|
37
|
-
const packageJSONContent =
|
|
38
|
-
const readmeContent =
|
|
39
|
-
const packageJSONPath =
|
|
40
|
-
const readmePath =
|
|
41
|
-
|
|
42
|
-
|
|
50
|
+
const packageJSONContent = generatePackageJsonContent(templateName);
|
|
51
|
+
const readmeContent = generateReadmeContent(templateName);
|
|
52
|
+
const packageJSONPath = path.join(directory, 'package.json');
|
|
53
|
+
const readmePath = path.join(directory, 'README.md');
|
|
54
|
+
fs.writeFileSync(packageJSONPath, packageJSONContent);
|
|
55
|
+
fs.writeFileSync(readmePath, readmeContent);
|
|
43
56
|
}
|
|
44
57
|
catch (error) {
|
|
45
|
-
(
|
|
58
|
+
catchError(error, {
|
|
46
59
|
context: { function: 'extractTemplate' },
|
|
47
60
|
fatal: true,
|
|
48
61
|
logToFile: true,
|
|
49
62
|
});
|
|
50
63
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
await (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
ux.stdout(SEPARATOR);
|
|
65
|
+
ux.action.start(`Extracting template - ${ux.colorize(DIRECTUS_PINK, templateName)} from ${ux.colorize(DIRECTUS_PINK, flags.directusUrl)} to ${ux.colorize(DIRECTUS_PINK, directory)}`);
|
|
66
|
+
await extract(directory);
|
|
67
|
+
ux.action.stop();
|
|
68
|
+
log.warn(BSL_LICENSE_TEXT);
|
|
69
|
+
ux.stdout(SEPARATOR);
|
|
70
|
+
ux.stdout('Template extracted successfully.');
|
|
57
71
|
this.exit(0);
|
|
58
72
|
}
|
|
59
73
|
/**
|
|
@@ -62,37 +76,46 @@ class ExtractCommand extends core_1.Command {
|
|
|
62
76
|
* @returns {Promise<void>} - Returns nothing
|
|
63
77
|
*/
|
|
64
78
|
async runInteractive(flags) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
79
|
+
await animatedBunny('Let\'s extract a template!');
|
|
80
|
+
intro(`${chalk.bgHex(DIRECTUS_PURPLE).white.bold('Directus Template CLI')} - Extract Template`);
|
|
81
|
+
const templateName = await text({
|
|
82
|
+
message: 'What is the name of the template you would like to extract?',
|
|
83
|
+
placeholder: 'My Template',
|
|
84
|
+
});
|
|
85
|
+
const directory = await text({
|
|
86
|
+
placeholder: `templates/${slugify(templateName)}`,
|
|
87
|
+
defaultValue: `templates/${slugify(templateName)}`,
|
|
88
|
+
message: "What directory would you like to extract the template to? If it doesn't exist, it will be created.",
|
|
89
|
+
});
|
|
90
|
+
ux.stdout(`You selected ${ux.colorize(DIRECTUS_PINK, directory)}`);
|
|
91
|
+
ux.stdout(SEPARATOR);
|
|
70
92
|
// Get Directus URL
|
|
71
|
-
const directusUrl = await
|
|
93
|
+
const directusUrl = await getDirectusUrl();
|
|
72
94
|
flags.directusUrl = directusUrl;
|
|
73
95
|
// Prompt for login method
|
|
74
|
-
const loginMethod = await
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
type: 'list',
|
|
84
|
-
},
|
|
85
|
-
]);
|
|
86
|
-
if (loginMethod.loginMethod === 'token') {
|
|
87
|
-
const directusToken = await (0, auth_1.getDirectusToken)(directusUrl);
|
|
96
|
+
const loginMethod = await select({
|
|
97
|
+
options: [
|
|
98
|
+
{ label: 'Directus Access Token', value: 'token' },
|
|
99
|
+
{ label: 'Email and Password', value: 'email' },
|
|
100
|
+
],
|
|
101
|
+
message: 'How do you want to log in?',
|
|
102
|
+
});
|
|
103
|
+
if (loginMethod === 'token') {
|
|
104
|
+
const directusToken = await getDirectusToken(directusUrl);
|
|
88
105
|
flags.directusToken = directusToken;
|
|
89
106
|
}
|
|
90
107
|
else {
|
|
91
|
-
|
|
92
|
-
|
|
108
|
+
const email = await text({
|
|
109
|
+
message: 'What is your email?',
|
|
110
|
+
});
|
|
111
|
+
flags.userEmail = email;
|
|
112
|
+
const userPassword = await password({
|
|
113
|
+
message: 'What is our password?',
|
|
114
|
+
});
|
|
115
|
+
flags.userPassword = userPassword;
|
|
93
116
|
}
|
|
94
|
-
|
|
95
|
-
await
|
|
117
|
+
ux.stdout(SEPARATOR);
|
|
118
|
+
await initializeDirectusApi(flags);
|
|
96
119
|
await this.extractTemplate(templateName, directory, flags);
|
|
97
120
|
}
|
|
98
121
|
/**
|
|
@@ -103,7 +126,7 @@ class ExtractCommand extends core_1.Command {
|
|
|
103
126
|
async runProgrammatic(flags) {
|
|
104
127
|
this.validateProgrammaticFlags(flags);
|
|
105
128
|
const { templateLocation, templateName } = flags;
|
|
106
|
-
await
|
|
129
|
+
await initializeDirectusApi(flags);
|
|
107
130
|
await this.extractTemplate(templateName, templateLocation, flags);
|
|
108
131
|
}
|
|
109
132
|
/**
|
|
@@ -113,27 +136,12 @@ class ExtractCommand extends core_1.Command {
|
|
|
113
136
|
* @returns {void}
|
|
114
137
|
*/
|
|
115
138
|
validateProgrammaticFlags(flags) {
|
|
116
|
-
|
|
139
|
+
validateAuthFlags(flags);
|
|
117
140
|
if (!flags.templateLocation) {
|
|
118
|
-
|
|
141
|
+
ux.error('Template location is required for programmatic mode.');
|
|
119
142
|
}
|
|
120
143
|
if (!flags.templateName) {
|
|
121
|
-
|
|
144
|
+
ux.error('Template name is required for programmatic mode.');
|
|
122
145
|
}
|
|
123
146
|
}
|
|
124
147
|
}
|
|
125
|
-
ExtractCommand.description = 'Extract a template from a Directus instance.';
|
|
126
|
-
ExtractCommand.examples = [
|
|
127
|
-
'$ directus-template-cli extract',
|
|
128
|
-
'$ directus-template-cli extract -p --templateName="My Template" --templateLocation="./my-template" --directusToken="admin-token-here" --directusUrl="http://localhost:8055"',
|
|
129
|
-
];
|
|
130
|
-
ExtractCommand.flags = {
|
|
131
|
-
directusToken: customFlags.directusToken,
|
|
132
|
-
directusUrl: customFlags.directusUrl,
|
|
133
|
-
programmatic: customFlags.programmatic,
|
|
134
|
-
templateLocation: customFlags.templateLocation,
|
|
135
|
-
templateName: customFlags.templateName,
|
|
136
|
-
userEmail: customFlags.userEmail,
|
|
137
|
-
userPassword: customFlags.userPassword,
|
|
138
|
-
};
|
|
139
|
-
exports.default = ExtractCommand;
|
package/dist/commands/init.d.ts
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
1
|
+
import { BaseCommand } from './base.js';
|
|
2
|
+
export interface InitFlags {
|
|
3
|
+
frontend?: string;
|
|
4
|
+
gitInit?: boolean;
|
|
5
|
+
installDeps?: boolean;
|
|
6
|
+
overrideDir?: boolean;
|
|
7
|
+
template?: string;
|
|
8
|
+
disableTelemetry?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface InitArgs {
|
|
11
|
+
directory: string;
|
|
12
|
+
}
|
|
13
|
+
export default class InitCommand extends BaseCommand {
|
|
3
14
|
static args: {
|
|
4
|
-
directory: import("@oclif/core/
|
|
15
|
+
directory: import("@oclif/core/interfaces").Arg<string, {
|
|
5
16
|
exists?: boolean;
|
|
6
17
|
}>;
|
|
7
18
|
};
|
|
8
19
|
static description: string;
|
|
9
20
|
static examples: string[];
|
|
10
21
|
static flags: {
|
|
11
|
-
frontend: import("@oclif/core/
|
|
12
|
-
gitInit: import("@oclif/core/
|
|
13
|
-
installDeps: import("@oclif/core/
|
|
14
|
-
overrideDir: import("@oclif/core/
|
|
15
|
-
|
|
16
|
-
|
|
22
|
+
frontend: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
23
|
+
gitInit: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
24
|
+
installDeps: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
25
|
+
overrideDir: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
26
|
+
template: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
27
|
+
disableTelemetry: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
17
28
|
};
|
|
18
29
|
private targetDir;
|
|
19
30
|
/**
|
|
@@ -24,13 +35,8 @@ export default class InitCommand extends Command {
|
|
|
24
35
|
/**
|
|
25
36
|
* Interactive mode: prompts the user for each piece of info, with added template checks.
|
|
26
37
|
* @param flags - The flags passed to the command.
|
|
38
|
+
* @param args - The arguments passed to the command.
|
|
27
39
|
* @returns void
|
|
28
40
|
*/
|
|
29
41
|
private runInteractive;
|
|
30
|
-
/**
|
|
31
|
-
* Programmatic mode: relies on flags only, with checks for template existence and valid frontend.
|
|
32
|
-
* @param flags - The flags passed to the command.
|
|
33
|
-
* @returns void
|
|
34
|
-
*/
|
|
35
|
-
private runProgrammatic;
|
|
36
42
|
}
|