directus-template-cli 0.3.5 → 0.4.0-beta.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/dist/commands/apply.d.ts +1 -1
- package/dist/commands/apply.js +48 -50
- package/dist/commands/extract.d.ts +1 -2
- package/dist/commands/extract.js +13 -18
- package/dist/lib/extract/extract-assets.d.ts +182 -2
- package/dist/lib/extract/extract-assets.js +25 -32
- package/dist/lib/extract/extract-collections.d.ts +4 -0
- package/dist/lib/extract/extract-collections.js +24 -0
- package/dist/lib/extract/extract-content.d.ts +1 -1
- package/dist/lib/extract/extract-content.js +18 -18
- package/dist/lib/extract/extract-dashboards.d.ts +8 -0
- package/dist/lib/extract/extract-dashboards.js +42 -0
- package/dist/lib/extract/extract-fields.d.ts +4 -0
- package/dist/lib/extract/extract-fields.js +30 -0
- package/dist/lib/extract/extract-files.js +11 -34
- package/dist/lib/extract/extract-flows.d.ts +8 -0
- package/dist/lib/extract/extract-flows.js +42 -0
- package/dist/lib/extract/extract-folders.d.ts +1 -1
- package/dist/lib/extract/extract-folders.js +12 -13
- package/dist/lib/extract/extract-permissions.d.ts +1 -1
- package/dist/lib/extract/extract-permissions.js +13 -13
- package/dist/lib/extract/extract-presets.js +15 -11
- package/dist/lib/extract/extract-relations.d.ts +4 -0
- package/dist/lib/extract/extract-relations.js +33 -0
- package/dist/lib/extract/extract-roles.js +11 -22
- package/dist/lib/extract/extract-schema.js +9 -9
- package/dist/lib/extract/extract-settings.d.ts +4 -0
- package/dist/lib/extract/extract-settings.js +22 -0
- package/dist/lib/extract/extract-translations.d.ts +4 -0
- package/dist/lib/extract/extract-translations.js +24 -0
- package/dist/lib/extract/extract-users.d.ts +1 -1
- package/dist/lib/extract/extract-users.js +14 -36
- package/dist/lib/extract/index.d.ts +1 -1
- package/dist/lib/extract/index.js +27 -32
- package/dist/lib/interfaces.d.ts +1 -1
- package/dist/lib/load/index.d.ts +1 -1
- package/dist/lib/load/index.js +32 -44
- package/dist/lib/load/load-collections.d.ts +4 -0
- package/dist/lib/load/load-collections.js +66 -0
- package/dist/lib/load/load-dashboards.d.ts +2 -1
- package/dist/lib/load/load-dashboards.js +33 -3
- package/dist/lib/load/load-data.d.ts +1 -1
- package/dist/lib/load/load-data.js +87 -60
- package/dist/lib/load/load-files.d.ts +1 -1
- package/dist/lib/load/load-files.js +23 -20
- package/dist/lib/load/load-flows.d.ts +2 -2
- package/dist/lib/load/load-flows.js +43 -9
- package/dist/lib/load/load-folders.js +15 -11
- package/dist/lib/load/load-permissions.d.ts +1 -1
- package/dist/lib/load/load-permissions.js +22 -21
- package/dist/lib/load/load-presets.d.ts +1 -2
- package/dist/lib/load/load-presets.js +16 -19
- package/dist/lib/load/load-relations.d.ts +4 -0
- package/dist/lib/load/load-relations.js +33 -0
- package/dist/lib/load/load-roles.d.ts +1 -1
- package/dist/lib/load/load-roles.js +20 -10
- package/dist/lib/load/load-schema.js +12 -7
- package/dist/lib/load/load-settings.d.ts +1 -1
- package/dist/lib/load/load-settings.js +10 -4
- package/dist/lib/load/load-translations.d.ts +1 -0
- package/dist/lib/load/load-translations.js +21 -0
- package/dist/lib/load/load-users.d.ts +1 -2
- package/dist/lib/load/load-users.js +19 -8
- package/dist/lib/sdk.d.ts +13 -0
- package/dist/lib/sdk.js +26 -0
- package/dist/lib/utils/auth.d.ts +2 -2
- package/dist/lib/utils/auth.js +12 -11
- package/dist/lib/utils/check-template.d.ts +4 -0
- package/dist/lib/utils/check-template.js +34 -0
- package/dist/lib/utils/filter-fields.js +5 -5
- package/dist/lib/utils/get-role-ids.d.ts +55 -0
- package/dist/lib/utils/get-role-ids.js +14 -0
- package/dist/lib/utils/log-error.d.ts +14 -0
- package/dist/lib/utils/log-error.js +25 -0
- package/dist/lib/utils/read-templates.js +2 -2
- package/dist/lib/utils/system-fields.d.ts +20 -0
- package/dist/lib/utils/system-fields.js +159 -0
- package/dist/lib/utils/template-defaults.js +8 -10
- package/dist/lib/utils/transform-github-url.d.ts +1 -0
- package/dist/lib/utils/transform-github-url.js +15 -0
- package/dist/lib/utils/validate-url.js +1 -1
- package/dist/lib/utils/write-to-file.js +4 -4
- package/oclif.manifest.json +34 -16
- package/package.json +23 -22
- package/templates/agencyos/package.json +6 -6
- package/templates/agencyos/src/collections.json +0 -459
- package/templates/agencyos/src/dashboards.json +3 -35
- package/templates/agencyos/src/fields.json +34588 -0
- package/templates/agencyos/src/flows.json +13 -62
- package/templates/agencyos/src/permissions.json +2 -8
- package/templates/agencyos/src/relations.json +4585 -0
- package/templates/agencyos/src/schema/snapshot.json +1 -39415
- package/templates/agencyos/src/translations.json +1 -0
- package/templates/agencyos/src/users.json +8 -8
- package/dist/lib/api.d.ts +0 -15
- package/dist/lib/api.js +0 -37
- package/dist/lib/extract/extract-from-endpoint.d.ts +0 -4
- package/dist/lib/extract/extract-from-endpoint.js +0 -23
- package/dist/lib/load/load-operations.d.ts +0 -1
- package/dist/lib/load/load-operations.js +0 -29
- package/dist/lib/load/load-panels.d.ts +0 -0
- package/dist/lib/load/load-panels.js +0 -0
- package/dist/lib/utils/delete-items.d.ts +0 -1
- package/dist/lib/utils/delete-items.js +0 -15
- package/dist/lib/utils/load-to-destination.d.ts +0 -1
- package/dist/lib/utils/load-to-destination.js +0 -14
package/dist/commands/apply.d.ts
CHANGED
package/dist/commands/apply.js
CHANGED
|
@@ -2,94 +2,92 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const core_1 = require("@oclif/core");
|
|
5
|
-
const
|
|
5
|
+
const giget_1 = require("giget");
|
|
6
6
|
const inquirer = tslib_1.__importStar(require("inquirer"));
|
|
7
7
|
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
8
|
-
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
9
|
-
const read_templates_1 = require("../lib/utils/read-templates");
|
|
10
|
-
const api_1 = require("../lib/api");
|
|
11
8
|
const load_1 = tslib_1.__importDefault(require("../lib/load/"));
|
|
12
9
|
const auth_1 = require("../lib/utils/auth");
|
|
13
|
-
const
|
|
10
|
+
const read_templates_1 = require("../lib/utils/read-templates");
|
|
11
|
+
const transform_github_url_1 = require("../lib/utils/transform-github-url");
|
|
12
|
+
const separator = '------------------';
|
|
14
13
|
async function getTemplate() {
|
|
15
|
-
const TEMPLATE_DIR = node_path_1.default.join(__dirname, "..", "..", "templates");
|
|
16
|
-
const templates = await (0, read_templates_1.readAllTemplates)(TEMPLATE_DIR);
|
|
17
|
-
const officialTemplateChoices = templates.map((template) => {
|
|
18
|
-
return { name: template.templateName, value: template };
|
|
19
|
-
});
|
|
20
14
|
const templateType = await inquirer.prompt([
|
|
21
15
|
{
|
|
22
|
-
name: "templateType",
|
|
23
|
-
message: "What type of template would you like to apply?",
|
|
24
|
-
type: "list",
|
|
25
16
|
choices: [
|
|
26
17
|
{
|
|
27
|
-
name:
|
|
28
|
-
value:
|
|
18
|
+
name: 'Official templates',
|
|
19
|
+
value: 'official',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: 'From a local directory',
|
|
23
|
+
value: 'local',
|
|
29
24
|
},
|
|
30
25
|
{
|
|
31
|
-
name:
|
|
32
|
-
value:
|
|
26
|
+
name: 'From a GitHub repository',
|
|
27
|
+
value: 'github',
|
|
33
28
|
},
|
|
34
|
-
// {
|
|
35
|
-
// name: "From a git repository",
|
|
36
|
-
// value: "git",
|
|
37
|
-
// },
|
|
38
29
|
],
|
|
30
|
+
message: 'What type of template would you like to apply?',
|
|
31
|
+
name: 'templateType',
|
|
32
|
+
type: 'list',
|
|
39
33
|
},
|
|
40
34
|
]);
|
|
41
35
|
let template;
|
|
42
|
-
if (templateType.templateType ===
|
|
36
|
+
if (templateType.templateType === 'official') {
|
|
37
|
+
// Get official templates
|
|
38
|
+
const { dir } = await (0, giget_1.downloadTemplate)('github:directus-community/directus-template-cli/templates', {
|
|
39
|
+
dir: 'downloads/',
|
|
40
|
+
force: true,
|
|
41
|
+
preferOffline: true,
|
|
42
|
+
});
|
|
43
|
+
const templates = await (0, read_templates_1.readAllTemplates)(dir);
|
|
44
|
+
const officialTemplateChoices = templates.map((template) => ({ name: template.templateName, value: template }));
|
|
43
45
|
template = await inquirer.prompt([
|
|
44
46
|
{
|
|
45
|
-
name: "template",
|
|
46
|
-
message: "Select a template.",
|
|
47
|
-
type: "list",
|
|
48
47
|
choices: officialTemplateChoices,
|
|
48
|
+
message: 'Select a template.',
|
|
49
|
+
name: 'template',
|
|
50
|
+
type: 'list',
|
|
49
51
|
},
|
|
50
52
|
]);
|
|
51
53
|
}
|
|
52
|
-
if (templateType.templateType ===
|
|
53
|
-
const localTemplateDir = await
|
|
54
|
-
if (
|
|
55
|
-
|
|
54
|
+
if (templateType.templateType === 'local') {
|
|
55
|
+
const localTemplateDir = await core_1.ux.prompt('What is the local template directory?');
|
|
56
|
+
if (node_fs_1.default.existsSync(localTemplateDir)) {
|
|
57
|
+
template = { template: await (0, read_templates_1.readTemplate)(localTemplateDir) };
|
|
56
58
|
}
|
|
57
59
|
else {
|
|
58
|
-
|
|
60
|
+
core_1.ux.error('Directory does not exist.');
|
|
59
61
|
}
|
|
60
62
|
}
|
|
63
|
+
if (templateType.templateType === 'github') {
|
|
64
|
+
const ghTemplateUrl = await core_1.ux.prompt('What is the GitHub repository URL?');
|
|
65
|
+
const ghString = await (0, transform_github_url_1.transformGitHubUrl)(ghTemplateUrl);
|
|
66
|
+
const { dir } = await (0, giget_1.downloadTemplate)(ghString, {
|
|
67
|
+
dir: 'downloads/github',
|
|
68
|
+
});
|
|
69
|
+
template = { template: await (0, read_templates_1.readTemplate)(dir) };
|
|
70
|
+
}
|
|
61
71
|
return template;
|
|
62
72
|
}
|
|
63
73
|
class ApplyCommand extends core_1.Command {
|
|
64
74
|
async run() {
|
|
65
|
-
const { flags } = await this.parse(ApplyCommand);
|
|
66
75
|
const chosenTemplate = await getTemplate();
|
|
67
76
|
this.log(`You selected ${chosenTemplate.template.templateName}`);
|
|
68
77
|
this.log(separator);
|
|
69
78
|
const directusUrl = await (0, auth_1.getDirectusUrl)();
|
|
70
|
-
|
|
71
|
-
const directusToken = await (0, auth_1.getDirectusToken)(directusUrl);
|
|
72
|
-
api_1.api.setAuthToken(directusToken);
|
|
79
|
+
await (0, auth_1.getDirectusToken)(directusUrl);
|
|
73
80
|
this.log(separator);
|
|
74
|
-
// Check if Directus instance is empty, if not, throw error
|
|
75
|
-
const { data } = await api_1.api.get("/collections");
|
|
76
|
-
// Look for collections that don't start with directus_
|
|
77
|
-
const collections = data.data.filter((collection) => {
|
|
78
|
-
return !collection.collection.startsWith("directus_");
|
|
79
|
-
});
|
|
80
|
-
if (collections.length > 0) {
|
|
81
|
-
core_2.ux.error("Directus instance is not empty. Please use a blank instance. Copying a template into an existing instance is not supported at this time.");
|
|
82
|
-
}
|
|
83
81
|
// Run load script
|
|
84
|
-
|
|
85
|
-
await (0, load_1.default)(chosenTemplate.template.directoryPath
|
|
86
|
-
|
|
82
|
+
core_1.ux.action.start(`Applying template - ${chosenTemplate.template.templateName} to ${directusUrl}`);
|
|
83
|
+
await (0, load_1.default)(chosenTemplate.template.directoryPath.toString());
|
|
84
|
+
core_1.ux.action.stop();
|
|
87
85
|
this.log(separator);
|
|
88
|
-
this.log(
|
|
86
|
+
this.log('Template applied successfully.');
|
|
89
87
|
this.exit(0);
|
|
90
88
|
}
|
|
91
89
|
}
|
|
92
|
-
|
|
93
|
-
ApplyCommand.
|
|
94
|
-
ApplyCommand.examples = ["$ directus-template-cli apply"];
|
|
90
|
+
ApplyCommand.description = 'Apply a template to a blank Directus instance.';
|
|
91
|
+
ApplyCommand.examples = ['$ directus-template-cli apply'];
|
|
95
92
|
ApplyCommand.flags = {};
|
|
93
|
+
exports.default = ApplyCommand;
|
package/dist/commands/extract.js
CHANGED
|
@@ -2,19 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const core_1 = require("@oclif/core");
|
|
5
|
-
const core_2 = require("@oclif/core");
|
|
6
5
|
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
7
6
|
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
8
|
-
const
|
|
7
|
+
const slugify_1 = tslib_1.__importDefault(require("slugify"));
|
|
9
8
|
const extract_1 = tslib_1.__importDefault(require("../lib/extract/"));
|
|
10
9
|
const auth_1 = require("../lib/utils/auth");
|
|
11
10
|
const template_defaults_1 = require("../lib/utils/template-defaults");
|
|
12
|
-
const separator =
|
|
11
|
+
const separator = '------------------';
|
|
13
12
|
class ExtractCommand extends core_1.Command {
|
|
14
13
|
async run() {
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const directory = await core_2.ux.prompt("What directory would you like to extract the template to? If it doesn't exist, it will be created.");
|
|
14
|
+
const templateName = await core_1.ux.prompt('What is the name of the template?.');
|
|
15
|
+
const directory = await core_1.ux.prompt("What directory would you like to extract the template to? If it doesn't exist, it will be created.", { default: `templates/${(0, slugify_1.default)(templateName, { lower: true, strict: true })}` });
|
|
18
16
|
this.log(`You selected ${directory}`);
|
|
19
17
|
try {
|
|
20
18
|
// Check if directory exists, if not, then create it.
|
|
@@ -25,8 +23,8 @@ class ExtractCommand extends core_1.Command {
|
|
|
25
23
|
const packageJSONContent = (0, template_defaults_1.generatePackageJsonContent)(templateName);
|
|
26
24
|
const readmeContent = (0, template_defaults_1.generateReadmeContent)(templateName);
|
|
27
25
|
// Write the content to the specified directory
|
|
28
|
-
const packageJSONPath = node_path_1.default.join(directory,
|
|
29
|
-
const readmePath = node_path_1.default.join(directory,
|
|
26
|
+
const packageJSONPath = node_path_1.default.join(directory, 'package.json');
|
|
27
|
+
const readmePath = node_path_1.default.join(directory, 'README.md');
|
|
30
28
|
node_fs_1.default.writeFileSync(packageJSONPath, packageJSONContent);
|
|
31
29
|
node_fs_1.default.writeFileSync(readmePath, readmeContent);
|
|
32
30
|
}
|
|
@@ -35,20 +33,17 @@ class ExtractCommand extends core_1.Command {
|
|
|
35
33
|
}
|
|
36
34
|
this.log(separator);
|
|
37
35
|
const directusUrl = await (0, auth_1.getDirectusUrl)();
|
|
38
|
-
|
|
39
|
-
const directusToken = await (0, auth_1.getDirectusToken)(directusUrl);
|
|
40
|
-
api_1.api.setAuthToken(directusToken);
|
|
36
|
+
await (0, auth_1.getDirectusToken)(directusUrl);
|
|
41
37
|
this.log(separator);
|
|
42
38
|
// Run the extract script
|
|
43
|
-
|
|
44
|
-
await (0, extract_1.default)(directory
|
|
45
|
-
|
|
39
|
+
core_1.ux.action.start(`Extracting template - from ${directusUrl} to ${directory}`);
|
|
40
|
+
await (0, extract_1.default)(directory);
|
|
41
|
+
core_1.ux.action.stop();
|
|
46
42
|
this.log(separator);
|
|
47
|
-
this.log(
|
|
43
|
+
this.log('Template extracted successfully.');
|
|
48
44
|
this.exit(0);
|
|
49
45
|
}
|
|
50
46
|
}
|
|
47
|
+
ExtractCommand.description = 'Extract a template from a Directus instance.';
|
|
48
|
+
ExtractCommand.examples = ['$ directus-template-cli extract'];
|
|
51
49
|
exports.default = ExtractCommand;
|
|
52
|
-
ExtractCommand.description = "Extract a template from a Directus instance.";
|
|
53
|
-
ExtractCommand.examples = ["$ directus-template-cli extract"];
|
|
54
|
-
ExtractCommand.flags = {};
|
|
@@ -1,3 +1,183 @@
|
|
|
1
|
-
export declare function getAssetList(): Promise<
|
|
2
|
-
|
|
1
|
+
export declare function getAssetList(): Promise<import("@directus/sdk/dist/types-ZBNrmR-A").ax<import("@directus/sdk/dist/types-ZBNrmR-A").a8<{
|
|
2
|
+
id: string;
|
|
3
|
+
storage: string;
|
|
4
|
+
filename_disk: string;
|
|
5
|
+
filename_download: string;
|
|
6
|
+
title: string;
|
|
7
|
+
type: string;
|
|
8
|
+
folder: string | {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
parent: any;
|
|
12
|
+
};
|
|
13
|
+
uploaded_by: string | {
|
|
14
|
+
id: string;
|
|
15
|
+
first_name: string;
|
|
16
|
+
last_name: string;
|
|
17
|
+
email: string;
|
|
18
|
+
password: string;
|
|
19
|
+
location: string;
|
|
20
|
+
title: string;
|
|
21
|
+
description: string;
|
|
22
|
+
tags: string[];
|
|
23
|
+
avatar: any;
|
|
24
|
+
language: string;
|
|
25
|
+
theme: string;
|
|
26
|
+
tfa_secret: string;
|
|
27
|
+
status: string;
|
|
28
|
+
role: string | {
|
|
29
|
+
id: string;
|
|
30
|
+
name: string;
|
|
31
|
+
icon: string;
|
|
32
|
+
description: string;
|
|
33
|
+
ip_access: string;
|
|
34
|
+
enforce_tfa: boolean;
|
|
35
|
+
admin_access: boolean;
|
|
36
|
+
app_access: boolean;
|
|
37
|
+
};
|
|
38
|
+
token: string;
|
|
39
|
+
last_access: "datetime";
|
|
40
|
+
last_page: string;
|
|
41
|
+
provider: string;
|
|
42
|
+
external_identifier: string;
|
|
43
|
+
auth_data: Record<string, any>;
|
|
44
|
+
email_notifications: boolean;
|
|
45
|
+
};
|
|
46
|
+
uploaded_on: "datetime";
|
|
47
|
+
modified_by: string | {
|
|
48
|
+
id: string;
|
|
49
|
+
first_name: string;
|
|
50
|
+
last_name: string;
|
|
51
|
+
email: string;
|
|
52
|
+
password: string;
|
|
53
|
+
location: string;
|
|
54
|
+
title: string;
|
|
55
|
+
description: string;
|
|
56
|
+
tags: string[];
|
|
57
|
+
avatar: any;
|
|
58
|
+
language: string;
|
|
59
|
+
theme: string;
|
|
60
|
+
tfa_secret: string;
|
|
61
|
+
status: string;
|
|
62
|
+
role: string | {
|
|
63
|
+
id: string;
|
|
64
|
+
name: string;
|
|
65
|
+
icon: string;
|
|
66
|
+
description: string;
|
|
67
|
+
ip_access: string;
|
|
68
|
+
enforce_tfa: boolean;
|
|
69
|
+
admin_access: boolean;
|
|
70
|
+
app_access: boolean;
|
|
71
|
+
};
|
|
72
|
+
token: string;
|
|
73
|
+
last_access: "datetime";
|
|
74
|
+
last_page: string;
|
|
75
|
+
provider: string;
|
|
76
|
+
external_identifier: string;
|
|
77
|
+
auth_data: Record<string, any>;
|
|
78
|
+
email_notifications: boolean;
|
|
79
|
+
};
|
|
80
|
+
modified_on: "datetime";
|
|
81
|
+
charset: string;
|
|
82
|
+
filesize: string;
|
|
83
|
+
width: number;
|
|
84
|
+
height: number;
|
|
85
|
+
duration: number;
|
|
86
|
+
embed: unknown;
|
|
87
|
+
description: string;
|
|
88
|
+
location: string;
|
|
89
|
+
tags: string[];
|
|
90
|
+
metadata: Record<string, any>;
|
|
91
|
+
}, "embed" | "type" | "location" | "description" | "id" | "duration" | "title" | "tags" | "storage" | "filename_disk" | "filename_download" | "folder" | "uploaded_by" | "uploaded_on" | "modified_by" | "modified_on" | "charset" | "filesize" | "width" | "height" | "metadata", import("@directus/sdk/dist/types-ZBNrmR-A").aI<import("../sdk").Schema, {
|
|
92
|
+
id: string;
|
|
93
|
+
storage: string;
|
|
94
|
+
filename_disk: string;
|
|
95
|
+
filename_download: string;
|
|
96
|
+
title: string;
|
|
97
|
+
type: string;
|
|
98
|
+
folder: string | {
|
|
99
|
+
id: string;
|
|
100
|
+
name: string;
|
|
101
|
+
parent: any;
|
|
102
|
+
};
|
|
103
|
+
uploaded_by: string | {
|
|
104
|
+
id: string;
|
|
105
|
+
first_name: string;
|
|
106
|
+
last_name: string;
|
|
107
|
+
email: string;
|
|
108
|
+
password: string;
|
|
109
|
+
location: string;
|
|
110
|
+
title: string;
|
|
111
|
+
description: string;
|
|
112
|
+
tags: string[];
|
|
113
|
+
avatar: any;
|
|
114
|
+
language: string;
|
|
115
|
+
theme: string;
|
|
116
|
+
tfa_secret: string;
|
|
117
|
+
status: string;
|
|
118
|
+
role: string | {
|
|
119
|
+
id: string;
|
|
120
|
+
name: string;
|
|
121
|
+
icon: string;
|
|
122
|
+
description: string;
|
|
123
|
+
ip_access: string;
|
|
124
|
+
enforce_tfa: boolean;
|
|
125
|
+
admin_access: boolean;
|
|
126
|
+
app_access: boolean;
|
|
127
|
+
};
|
|
128
|
+
token: string;
|
|
129
|
+
last_access: "datetime";
|
|
130
|
+
last_page: string;
|
|
131
|
+
provider: string;
|
|
132
|
+
external_identifier: string;
|
|
133
|
+
auth_data: Record<string, any>;
|
|
134
|
+
email_notifications: boolean;
|
|
135
|
+
};
|
|
136
|
+
uploaded_on: "datetime";
|
|
137
|
+
modified_by: string | {
|
|
138
|
+
id: string;
|
|
139
|
+
first_name: string;
|
|
140
|
+
last_name: string;
|
|
141
|
+
email: string;
|
|
142
|
+
password: string;
|
|
143
|
+
location: string;
|
|
144
|
+
title: string;
|
|
145
|
+
description: string;
|
|
146
|
+
tags: string[];
|
|
147
|
+
avatar: any;
|
|
148
|
+
language: string;
|
|
149
|
+
theme: string;
|
|
150
|
+
tfa_secret: string;
|
|
151
|
+
status: string;
|
|
152
|
+
role: string | {
|
|
153
|
+
id: string;
|
|
154
|
+
name: string;
|
|
155
|
+
icon: string;
|
|
156
|
+
description: string;
|
|
157
|
+
ip_access: string;
|
|
158
|
+
enforce_tfa: boolean;
|
|
159
|
+
admin_access: boolean;
|
|
160
|
+
app_access: boolean;
|
|
161
|
+
};
|
|
162
|
+
token: string;
|
|
163
|
+
last_access: "datetime";
|
|
164
|
+
last_page: string;
|
|
165
|
+
provider: string;
|
|
166
|
+
external_identifier: string;
|
|
167
|
+
auth_data: Record<string, any>;
|
|
168
|
+
email_notifications: boolean;
|
|
169
|
+
};
|
|
170
|
+
modified_on: "datetime";
|
|
171
|
+
charset: string;
|
|
172
|
+
filesize: string;
|
|
173
|
+
width: number;
|
|
174
|
+
height: number;
|
|
175
|
+
duration: number;
|
|
176
|
+
embed: unknown;
|
|
177
|
+
description: string;
|
|
178
|
+
location: string;
|
|
179
|
+
tags: string[];
|
|
180
|
+
metadata: Record<string, any>;
|
|
181
|
+
}>>, {}>[]>;
|
|
182
|
+
export declare function downloadFile(file: any, dir: string): Promise<void>;
|
|
3
183
|
export declare function downloadAllFiles(dir: string): Promise<void>;
|
|
@@ -2,48 +2,41 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.downloadAllFiles = exports.downloadFile = exports.getAssetList = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const sdk_1 = require("@directus/sdk");
|
|
6
|
+
const core_1 = require("@oclif/core");
|
|
5
7
|
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
8
|
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
7
|
-
const
|
|
9
|
+
const promises_1 = require("node:stream/promises");
|
|
10
|
+
const sdk_2 = require("../sdk");
|
|
8
11
|
async function getAssetList() {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
limit: "-1",
|
|
12
|
-
},
|
|
13
|
-
});
|
|
14
|
-
return data.data;
|
|
12
|
+
const response = await sdk_2.api.client.request((0, sdk_1.readFiles)({ limit: -1 }));
|
|
13
|
+
return response;
|
|
15
14
|
}
|
|
16
15
|
exports.getAssetList = getAssetList;
|
|
17
16
|
async function downloadFile(file, dir) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
// Returned as ReadableStream<Uint8Array>
|
|
18
|
+
const response = await sdk_2.api.client.request((0, sdk_1.readAssetRaw)(file.id));
|
|
19
|
+
// Write the file to disk
|
|
20
|
+
const fullPath = node_path_1.default.join(dir, 'assets', file.filename_disk);
|
|
21
|
+
await (0, promises_1.pipeline)(
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
response, node_fs_1.default.createWriteStream(fullPath));
|
|
24
|
+
}
|
|
25
|
+
exports.downloadFile = downloadFile;
|
|
26
|
+
async function downloadAllFiles(dir) {
|
|
21
27
|
// Create assets folder if it doesn't exist
|
|
22
|
-
const fullPath = node_path_1.default.join(dir,
|
|
28
|
+
const fullPath = node_path_1.default.join(dir, 'assets');
|
|
23
29
|
if (node_path_1.default && !node_fs_1.default.existsSync(fullPath)) {
|
|
24
30
|
node_fs_1.default.mkdirSync(fullPath, { recursive: true });
|
|
25
31
|
}
|
|
26
|
-
|
|
27
|
-
const writer = node_fs_1.default.createWriteStream(writePath);
|
|
28
|
-
response.data.pipe(writer);
|
|
29
|
-
return new Promise((resolve, reject) => {
|
|
30
|
-
writer.on("finish", () => {
|
|
31
|
-
// console.log(`Wrote ${file.filename_disk}`);
|
|
32
|
-
resolve(null);
|
|
33
|
-
});
|
|
34
|
-
writer.on("error", reject);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
exports.downloadFile = downloadFile;
|
|
38
|
-
async function downloadAllFiles(dir) {
|
|
32
|
+
// Get the list of files
|
|
39
33
|
const fileList = await getAssetList();
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
34
|
+
// Download all files
|
|
35
|
+
await Promise.all(fileList.map(file => downloadFile(file, dir).catch(error => {
|
|
36
|
+
core_1.ux.warn(`Error downloading ${file.filename_disk}`);
|
|
37
|
+
core_1.ux.warn(error.message);
|
|
38
|
+
})));
|
|
39
|
+
// Log message after all files have been downloaded
|
|
40
|
+
core_1.ux.log('All files have been downloaded.');
|
|
48
41
|
}
|
|
49
42
|
exports.downloadAllFiles = downloadAllFiles;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const sdk_1 = require("@directus/sdk");
|
|
5
|
+
const core_1 = require("@oclif/core");
|
|
6
|
+
const sdk_2 = require("../sdk");
|
|
7
|
+
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
8
|
+
/**
|
|
9
|
+
* Extract collections from the Directus instance
|
|
10
|
+
*/
|
|
11
|
+
async function extractCollections(dir) {
|
|
12
|
+
try {
|
|
13
|
+
const response = await sdk_2.api.client.request((0, sdk_1.readCollections)());
|
|
14
|
+
// Filter out system collections
|
|
15
|
+
const collections = response.filter(collection => !collection.collection.startsWith('directus_'));
|
|
16
|
+
await (0, write_to_file_1.default)('collections', collections, dir);
|
|
17
|
+
core_1.ux.log('Extracted collections');
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
core_1.ux.warn('Error extracting Collections:');
|
|
21
|
+
core_1.ux.warn(error.message);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.default = extractCollections;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function getCollections(): Promise<
|
|
1
|
+
export declare function getCollections(): Promise<string[]>;
|
|
2
2
|
export declare function getDataFromCollection(collection: string, dir: string): Promise<void>;
|
|
3
3
|
export declare function extractContent(dir: string): Promise<void>;
|
|
@@ -2,36 +2,36 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extractContent = exports.getDataFromCollection = exports.getCollections = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const sdk_1 = require("@directus/sdk");
|
|
6
|
+
const core_1 = require("@oclif/core");
|
|
7
|
+
const sdk_2 = require("../sdk");
|
|
6
8
|
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
7
9
|
async function getCollections() {
|
|
8
|
-
const
|
|
9
|
-
const collections =
|
|
10
|
-
.filter(
|
|
11
|
-
.filter(
|
|
12
|
-
.map(
|
|
10
|
+
const response = await sdk_2.api.client.request((0, sdk_1.readCollections)());
|
|
11
|
+
const collections = response
|
|
12
|
+
.filter(item => !item.collection.startsWith('directus_', 0))
|
|
13
|
+
.filter(item => item.schema != null)
|
|
14
|
+
.map(i => i.collection);
|
|
13
15
|
return collections;
|
|
14
16
|
}
|
|
15
17
|
exports.getCollections = getCollections;
|
|
16
18
|
async function getDataFromCollection(collection, dir) {
|
|
17
19
|
try {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
(
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
const response = await sdk_2.api.client.request((0, sdk_1.readItems)(collection, {
|
|
22
|
+
limit: -1,
|
|
23
|
+
}));
|
|
24
|
+
(0, write_to_file_1.default)(`${collection}`, response, `${dir}/content/`);
|
|
25
|
+
core_1.ux.log('Extracted items from collection: ' + collection);
|
|
24
26
|
}
|
|
25
|
-
catch {
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
catch (error) {
|
|
28
|
+
core_1.ux.warn(`Error extracting items from: ${collection}`);
|
|
29
|
+
core_1.ux.warn(error.message);
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
32
|
exports.getDataFromCollection = getDataFromCollection;
|
|
31
33
|
async function extractContent(dir) {
|
|
32
34
|
const collections = await getCollections();
|
|
33
|
-
|
|
34
|
-
await getDataFromCollection(collection, dir);
|
|
35
|
-
}
|
|
35
|
+
await Promise.all(collections.map(collection => getDataFromCollection(collection, dir)));
|
|
36
36
|
}
|
|
37
37
|
exports.extractContent = extractContent;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractPanels = exports.extractDashboards = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const sdk_1 = require("@directus/sdk");
|
|
6
|
+
const core_1 = require("@oclif/core");
|
|
7
|
+
const sdk_2 = require("../sdk");
|
|
8
|
+
const filter_fields_1 = tslib_1.__importDefault(require("../utils/filter-fields"));
|
|
9
|
+
const system_fields_1 = require("../utils/system-fields");
|
|
10
|
+
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
11
|
+
/**
|
|
12
|
+
* Extract dashboards from the Directus instance
|
|
13
|
+
*/
|
|
14
|
+
async function extractDashboards(dir) {
|
|
15
|
+
try {
|
|
16
|
+
const response = await sdk_2.api.client.request((0, sdk_1.readDashboards)({ limit: -1 }));
|
|
17
|
+
const dashboards = (0, filter_fields_1.default)(response, system_fields_1.directusDashboardFields);
|
|
18
|
+
await (0, write_to_file_1.default)('dashboards', dashboards, dir);
|
|
19
|
+
core_1.ux.log('Extracted dashboards');
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
core_1.ux.warn('Error extracting Dashboards:');
|
|
23
|
+
core_1.ux.warn(error.message);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.extractDashboards = extractDashboards;
|
|
27
|
+
/**
|
|
28
|
+
* Extract panels from the Directus instance
|
|
29
|
+
*/
|
|
30
|
+
async function extractPanels(dir) {
|
|
31
|
+
try {
|
|
32
|
+
const response = await sdk_2.api.client.request((0, sdk_1.readPanels)({ limit: -1 }));
|
|
33
|
+
const panels = (0, filter_fields_1.default)(response, system_fields_1.directusPanelFields);
|
|
34
|
+
await (0, write_to_file_1.default)('panels', panels, dir);
|
|
35
|
+
core_1.ux.log('Extracted panels');
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
core_1.ux.warn('Error extracting Panels:');
|
|
39
|
+
core_1.ux.warn(error.message);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.extractPanels = extractPanels;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const sdk_1 = require("@directus/sdk");
|
|
5
|
+
const core_1 = require("@oclif/core");
|
|
6
|
+
const sdk_2 = require("../sdk");
|
|
7
|
+
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
8
|
+
/**
|
|
9
|
+
* Extract fields from the Directus instance
|
|
10
|
+
*/
|
|
11
|
+
async function extractFields(dir) {
|
|
12
|
+
try {
|
|
13
|
+
const response = await sdk_2.api.client.request((0, sdk_1.readFields)());
|
|
14
|
+
const fields = response
|
|
15
|
+
.filter(
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
(i) => !i.meta.system)
|
|
18
|
+
.map(i => {
|
|
19
|
+
delete i.meta.id;
|
|
20
|
+
return i;
|
|
21
|
+
});
|
|
22
|
+
await (0, write_to_file_1.default)('fields', fields, dir);
|
|
23
|
+
core_1.ux.log('Extracted fields');
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
core_1.ux.warn('Error extracting Fields:');
|
|
27
|
+
core_1.ux.warn(error.message);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.default = extractFields;
|