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.
Files changed (106) hide show
  1. package/dist/commands/apply.d.ts +1 -1
  2. package/dist/commands/apply.js +48 -50
  3. package/dist/commands/extract.d.ts +1 -2
  4. package/dist/commands/extract.js +13 -18
  5. package/dist/lib/extract/extract-assets.d.ts +182 -2
  6. package/dist/lib/extract/extract-assets.js +25 -32
  7. package/dist/lib/extract/extract-collections.d.ts +4 -0
  8. package/dist/lib/extract/extract-collections.js +24 -0
  9. package/dist/lib/extract/extract-content.d.ts +1 -1
  10. package/dist/lib/extract/extract-content.js +18 -18
  11. package/dist/lib/extract/extract-dashboards.d.ts +8 -0
  12. package/dist/lib/extract/extract-dashboards.js +42 -0
  13. package/dist/lib/extract/extract-fields.d.ts +4 -0
  14. package/dist/lib/extract/extract-fields.js +30 -0
  15. package/dist/lib/extract/extract-files.js +11 -34
  16. package/dist/lib/extract/extract-flows.d.ts +8 -0
  17. package/dist/lib/extract/extract-flows.js +42 -0
  18. package/dist/lib/extract/extract-folders.d.ts +1 -1
  19. package/dist/lib/extract/extract-folders.js +12 -13
  20. package/dist/lib/extract/extract-permissions.d.ts +1 -1
  21. package/dist/lib/extract/extract-permissions.js +13 -13
  22. package/dist/lib/extract/extract-presets.js +15 -11
  23. package/dist/lib/extract/extract-relations.d.ts +4 -0
  24. package/dist/lib/extract/extract-relations.js +33 -0
  25. package/dist/lib/extract/extract-roles.js +11 -22
  26. package/dist/lib/extract/extract-schema.js +9 -9
  27. package/dist/lib/extract/extract-settings.d.ts +4 -0
  28. package/dist/lib/extract/extract-settings.js +22 -0
  29. package/dist/lib/extract/extract-translations.d.ts +4 -0
  30. package/dist/lib/extract/extract-translations.js +24 -0
  31. package/dist/lib/extract/extract-users.d.ts +1 -1
  32. package/dist/lib/extract/extract-users.js +14 -36
  33. package/dist/lib/extract/index.d.ts +1 -1
  34. package/dist/lib/extract/index.js +27 -32
  35. package/dist/lib/interfaces.d.ts +1 -1
  36. package/dist/lib/load/index.d.ts +1 -1
  37. package/dist/lib/load/index.js +32 -44
  38. package/dist/lib/load/load-collections.d.ts +4 -0
  39. package/dist/lib/load/load-collections.js +66 -0
  40. package/dist/lib/load/load-dashboards.d.ts +2 -1
  41. package/dist/lib/load/load-dashboards.js +33 -3
  42. package/dist/lib/load/load-data.d.ts +1 -1
  43. package/dist/lib/load/load-data.js +87 -60
  44. package/dist/lib/load/load-files.d.ts +1 -1
  45. package/dist/lib/load/load-files.js +23 -20
  46. package/dist/lib/load/load-flows.d.ts +2 -2
  47. package/dist/lib/load/load-flows.js +43 -9
  48. package/dist/lib/load/load-folders.js +15 -11
  49. package/dist/lib/load/load-permissions.d.ts +1 -1
  50. package/dist/lib/load/load-permissions.js +22 -21
  51. package/dist/lib/load/load-presets.d.ts +1 -2
  52. package/dist/lib/load/load-presets.js +16 -19
  53. package/dist/lib/load/load-relations.d.ts +4 -0
  54. package/dist/lib/load/load-relations.js +33 -0
  55. package/dist/lib/load/load-roles.d.ts +1 -1
  56. package/dist/lib/load/load-roles.js +20 -10
  57. package/dist/lib/load/load-schema.js +12 -7
  58. package/dist/lib/load/load-settings.d.ts +1 -1
  59. package/dist/lib/load/load-settings.js +10 -4
  60. package/dist/lib/load/load-translations.d.ts +1 -0
  61. package/dist/lib/load/load-translations.js +21 -0
  62. package/dist/lib/load/load-users.d.ts +1 -2
  63. package/dist/lib/load/load-users.js +19 -8
  64. package/dist/lib/sdk.d.ts +13 -0
  65. package/dist/lib/sdk.js +26 -0
  66. package/dist/lib/utils/auth.d.ts +2 -2
  67. package/dist/lib/utils/auth.js +12 -11
  68. package/dist/lib/utils/check-template.d.ts +4 -0
  69. package/dist/lib/utils/check-template.js +34 -0
  70. package/dist/lib/utils/filter-fields.js +5 -5
  71. package/dist/lib/utils/get-role-ids.d.ts +55 -0
  72. package/dist/lib/utils/get-role-ids.js +14 -0
  73. package/dist/lib/utils/log-error.d.ts +14 -0
  74. package/dist/lib/utils/log-error.js +25 -0
  75. package/dist/lib/utils/read-templates.js +2 -2
  76. package/dist/lib/utils/system-fields.d.ts +20 -0
  77. package/dist/lib/utils/system-fields.js +159 -0
  78. package/dist/lib/utils/template-defaults.js +8 -10
  79. package/dist/lib/utils/transform-github-url.d.ts +1 -0
  80. package/dist/lib/utils/transform-github-url.js +15 -0
  81. package/dist/lib/utils/validate-url.js +1 -1
  82. package/dist/lib/utils/write-to-file.js +4 -4
  83. package/oclif.manifest.json +34 -16
  84. package/package.json +23 -22
  85. package/templates/agencyos/package.json +6 -6
  86. package/templates/agencyos/src/collections.json +0 -459
  87. package/templates/agencyos/src/dashboards.json +3 -35
  88. package/templates/agencyos/src/fields.json +34588 -0
  89. package/templates/agencyos/src/flows.json +13 -62
  90. package/templates/agencyos/src/permissions.json +2 -8
  91. package/templates/agencyos/src/relations.json +4585 -0
  92. package/templates/agencyos/src/schema/snapshot.json +1 -39415
  93. package/templates/agencyos/src/translations.json +1 -0
  94. package/templates/agencyos/src/users.json +8 -8
  95. package/dist/lib/api.d.ts +0 -15
  96. package/dist/lib/api.js +0 -37
  97. package/dist/lib/extract/extract-from-endpoint.d.ts +0 -4
  98. package/dist/lib/extract/extract-from-endpoint.js +0 -23
  99. package/dist/lib/load/load-operations.d.ts +0 -1
  100. package/dist/lib/load/load-operations.js +0 -29
  101. package/dist/lib/load/load-panels.d.ts +0 -0
  102. package/dist/lib/load/load-panels.js +0 -0
  103. package/dist/lib/utils/delete-items.d.ts +0 -1
  104. package/dist/lib/utils/delete-items.js +0 -15
  105. package/dist/lib/utils/load-to-destination.d.ts +0 -1
  106. package/dist/lib/utils/load-to-destination.js +0 -14
@@ -1,4 +1,4 @@
1
- import { Command } from "@oclif/core";
1
+ import { Command } from '@oclif/core';
2
2
  export default class ApplyCommand extends Command {
3
3
  static description: string;
4
4
  static examples: string[];
@@ -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 core_2 = require("@oclif/core");
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 separator = "------------------";
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: "Official templates",
28
- value: "official",
18
+ name: 'Official templates',
19
+ value: 'official',
20
+ },
21
+ {
22
+ name: 'From a local directory',
23
+ value: 'local',
29
24
  },
30
25
  {
31
- name: "From a local directory",
32
- value: "local",
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 === "official") {
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 === "local") {
53
- const localTemplateDir = await core_2.ux.prompt("What is the local template directory?");
54
- if (!node_fs_1.default.existsSync(localTemplateDir)) {
55
- core_2.ux.error("Directory does not exist.");
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
- template = { template: await (0, read_templates_1.readTemplate)(localTemplateDir) };
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
- api_1.api.setBaseUrl(directusUrl);
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
- core_2.ux.action.start(`Applying template - ${chosenTemplate.template.templateName}`);
85
- await (0, load_1.default)(chosenTemplate.template.directoryPath, this);
86
- core_2.ux.action.stop();
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("Template applied successfully.");
86
+ this.log('Template applied successfully.');
89
87
  this.exit(0);
90
88
  }
91
89
  }
92
- exports.default = ApplyCommand;
93
- ApplyCommand.description = "Apply a template to a blank Directus instance.";
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;
@@ -1,7 +1,6 @@
1
- import { Command } from "@oclif/core";
1
+ import { Command } from '@oclif/core';
2
2
  export default class ExtractCommand extends Command {
3
3
  static description: string;
4
4
  static examples: string[];
5
- static flags: {};
6
5
  run(): Promise<void>;
7
6
  }
@@ -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 api_1 = require("../lib/api");
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 { flags } = await this.parse(ExtractCommand);
16
- const templateName = await core_2.ux.prompt("What is the name of the template?.");
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, "package.json");
29
- const readmePath = node_path_1.default.join(directory, "README.md");
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
- api_1.api.setBaseUrl(directusUrl);
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
- core_2.ux.action.start(`Extracting template - from ${directusUrl} to ${directory}`);
44
- await (0, extract_1.default)(directory, this);
45
- core_2.ux.action.stop();
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("Template extracted successfully.");
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<any>;
2
- export declare function downloadFile(file: any, dir: string): Promise<unknown>;
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 api_1 = require("../api");
9
+ const promises_1 = require("node:stream/promises");
10
+ const sdk_2 = require("../sdk");
8
11
  async function getAssetList() {
9
- const { data } = await api_1.api.get("/files", {
10
- params: {
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
- const response = await api_1.api.get(`assets/${file.id}`, {
19
- responseType: "stream",
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, "assets");
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
- const writePath = node_path_1.default.resolve(dir, "assets", file.filename_disk);
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
- for (const file of fileList) {
41
- try {
42
- await downloadFile(file, dir);
43
- }
44
- catch (error) {
45
- console.log(`Error downloading ${file.filename_disk}`, error);
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,4 @@
1
+ /**
2
+ * Extract collections from the Directus instance
3
+ */
4
+ export default function extractCollections(dir: string): Promise<void>;
@@ -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<any>;
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 api_1 = require("../api");
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 { data } = await api_1.api.get("/collections");
9
- const collections = data.data
10
- .filter((item) => !item.collection.startsWith("directus_", 0))
11
- .filter((item) => item.schema != null)
12
- .map((i) => i.collection);
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
- const { data } = await api_1.api.get(`items/${collection}`, {
19
- params: {
20
- limit: -1,
21
- },
22
- });
23
- (0, write_to_file_1.default)(`${collection}`, data.data, `${dir}/content/`);
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
- console.log(`error getting items from ${collection}`);
27
- // Errors are thrown for 'folder' collections
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
- for (const collection of collections) {
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,8 @@
1
+ /**
2
+ * Extract dashboards from the Directus instance
3
+ */
4
+ export declare function extractDashboards(dir: string): Promise<void>;
5
+ /**
6
+ * Extract panels from the Directus instance
7
+ */
8
+ export declare function extractPanels(dir: string): Promise<void>;
@@ -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,4 @@
1
+ /**
2
+ * Extract fields from the Directus instance
3
+ */
4
+ export default function extractFields(dir: string): Promise<void>;
@@ -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;