directus-template-cli 0.3.0-beta.3 → 0.3.0-beta.4

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 CHANGED
@@ -7,6 +7,7 @@ A CLI tool to make applying or extracting Directus "templates" a little easier..
7
7
  - This is a pre-release. It is recommended for use on POC or demo projects only.
8
8
  - ⚠️ Known issues with using MySQL currently, please use ONLY PostgreSQL or SQLite for your database provider.
9
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 depedning 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
11
 
11
12
  ## Usage
12
13
 
@@ -15,7 +15,11 @@ async function getCollections() {
15
15
  exports.getCollections = getCollections;
16
16
  async function getDataFromCollection(collection, dir) {
17
17
  try {
18
- const { data } = await api_1.api.get(`items/${collection}`); // ADD limit = -1
18
+ const { data } = await api_1.api.get(`items/${collection}`, {
19
+ params: {
20
+ limit: -1,
21
+ },
22
+ });
19
23
  (0, write_to_file_1.default)(`${collection}`, data.data, `${dir}/content/`);
20
24
  }
21
25
  catch {
@@ -0,0 +1,2 @@
1
+ export declare function extractPublicPermissions(dir: string): Promise<void>;
2
+ export declare function extractPermissions(dir: string): Promise<void>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractPermissions = exports.extractPublicPermissions = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const api_1 = require("../api");
6
+ const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
7
+ async function extractPublicPermissions(dir) {
8
+ try {
9
+ const { data } = await api_1.api.get("permissions", {
10
+ params: {
11
+ limit: "-1",
12
+ "filter[role][_null]": true,
13
+ },
14
+ });
15
+ // Delete the id field from the permissions so we don't have to reset the autoincrement on the db
16
+ data.data.forEach((permission) => {
17
+ delete permission.id;
18
+ });
19
+ // Write the public permissions to the specified directory
20
+ await (0, write_to_file_1.default)("public-permissions", data.data, dir);
21
+ }
22
+ catch (error) {
23
+ console.log("Error fetching public permissions:", error);
24
+ }
25
+ }
26
+ exports.extractPublicPermissions = extractPublicPermissions;
27
+ async function extractPermissions(dir) {
28
+ try {
29
+ const { data } = await api_1.api.get("permissions", {
30
+ params: {
31
+ limit: "-1",
32
+ "filter[role][_null]": true,
33
+ },
34
+ });
35
+ // Delete the id field from the permissions so we don't have to reset the autoincrement on the db
36
+ data.data.forEach((permission) => {
37
+ delete permission.id;
38
+ });
39
+ // Write the public permissions to the specified directory
40
+ await (0, write_to_file_1.default)("permissions", data.data, dir);
41
+ }
42
+ catch (error) {
43
+ console.log("Error fetching permissions:", error);
44
+ }
45
+ }
46
+ exports.extractPermissions = extractPermissions;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Extract Presets from the API
3
+ */
4
+ export default function extractPresets(dir: string): Promise<void>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const api_1 = require("../api");
5
+ const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
6
+ /**
7
+ * Extract Presets from the API
8
+ */
9
+ async function extractPresets(dir) {
10
+ try {
11
+ const { data } = await api_1.api.get("/presets", {
12
+ params: {
13
+ limit: "-1",
14
+ // Only get the global presets
15
+ "filter[user][_null]": true,
16
+ },
17
+ });
18
+ // Remove the id field from the presets so we don't have to reset the autoincrement on the db
19
+ const filteredData = data.data.map((preset) => {
20
+ delete preset.id;
21
+ return preset;
22
+ });
23
+ await (0, write_to_file_1.default)("presets", filteredData, dir);
24
+ }
25
+ catch (error) {
26
+ console.log("Error extracting Users:", error.response.data.errors);
27
+ }
28
+ }
29
+ exports.default = extractPresets;
@@ -5,12 +5,13 @@ const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
5
5
  const extract_assets_1 = require("./extract-assets");
6
6
  const extract_schema_1 = tslib_1.__importDefault(require("./extract-schema"));
7
7
  const extract_from_endpoint_1 = tslib_1.__importDefault(require("./extract-from-endpoint"));
8
- const public_permissions_1 = tslib_1.__importDefault(require("./public-permissions"));
8
+ const extract_permissions_1 = require("./extract-permissions");
9
9
  const extract_content_1 = require("./extract-content");
10
10
  const extract_folders_1 = tslib_1.__importDefault(require("./extract-folders"));
11
11
  const extract_users_1 = tslib_1.__importDefault(require("./extract-users"));
12
12
  const extract_roles_1 = tslib_1.__importDefault(require("./extract-roles"));
13
13
  const extract_files_1 = tslib_1.__importDefault(require("./extract-files"));
14
+ const extract_presets_1 = tslib_1.__importDefault(require("./extract-presets"));
14
15
  const endpoints = [
15
16
  // "folders",
16
17
  // "fields",
@@ -18,12 +19,12 @@ const endpoints = [
18
19
  // "roles",
19
20
  // "files",
20
21
  "operations",
21
- "permissions",
22
+ // "permissions",
22
23
  "collections",
23
24
  "flows",
24
25
  "dashboards",
25
26
  "panels",
26
- "presets",
27
+ // "presets",
27
28
  "settings",
28
29
  ];
29
30
  async function extract(dir, cli) {
@@ -34,18 +35,20 @@ async function extract(dir, cli) {
34
35
  console.log(`Attempting to create directory at: ${destination}`);
35
36
  node_fs_1.default.mkdirSync(destination, { recursive: true });
36
37
  }
37
- // Extract the schema
38
38
  await (0, extract_schema_1.default)(destination);
39
39
  await (0, extract_folders_1.default)(destination);
40
40
  await (0, extract_users_1.default)(destination);
41
41
  await (0, extract_roles_1.default)(destination);
42
42
  await (0, extract_files_1.default)(destination);
43
+ await (0, extract_presets_1.default)(destination);
44
+ await (0, extract_permissions_1.extractPermissions)(destination);
45
+ await (0, extract_permissions_1.extractPermissions)(destination);
43
46
  // Iterate through the endpoints
44
47
  for (const endpoint of endpoints) {
45
48
  await (0, extract_from_endpoint_1.default)(endpoint, destination);
46
49
  }
47
50
  // Extract public permissions
48
- await (0, public_permissions_1.default)(destination);
51
+ await (0, extract_permissions_1.extractPublicPermissions)(destination);
49
52
  // Extract content
50
53
  await (0, extract_content_1.extractContent)(destination);
51
54
  // Extract assets
@@ -1 +1 @@
1
- export declare function loadPermissions(roles: any): Promise<void>;
1
+ export declare function loadPermissions(permissions: any): Promise<void>;
@@ -14,8 +14,8 @@ async function removeallPublicPermissions() {
14
14
  data: ids,
15
15
  });
16
16
  }
17
- async function loadPermissions(roles) {
17
+ async function loadPermissions(permissions) {
18
18
  await removeallPublicPermissions();
19
- await (0, load_to_destination_1.default)("permissions", roles);
19
+ await (0, load_to_destination_1.default)("permissions", permissions);
20
20
  }
21
21
  exports.loadPermissions = loadPermissions;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.3.0-beta.3",
2
+ "version": "0.3.0-beta.4",
3
3
  "commands": {
4
4
  "apply": {
5
5
  "id": "apply",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "directus-template-cli",
3
- "version": "0.3.0-beta.3",
3
+ "version": "0.3.0-beta.4",
4
4
  "description": "CLI Utility for applying templates to a Directus instance.",
5
5
  "author": "bryantgillespie @bryantgillespie",
6
6
  "bin": {
@@ -1 +0,0 @@
1
- export default function extractPublicPermissions(dir: string): Promise<void>;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const api_1 = require("../api");
5
- const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
6
- async function extractPublicPermissions(dir) {
7
- try {
8
- const { data } = await api_1.api.get("permissions", {
9
- params: {
10
- limit: "-1",
11
- "filter[role][_null]": true,
12
- },
13
- });
14
- // Write the public permissions to the specified directory
15
- await (0, write_to_file_1.default)("public-permissions", data.data, dir);
16
- }
17
- catch (error) {
18
- console.log("Error fetching public permissions:", error);
19
- }
20
- }
21
- exports.default = extractPublicPermissions;