directus-template-cli 0.7.0-beta.3 → 0.7.0-beta.5
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 +2 -3
- package/bin/dev.js +3 -0
- package/bin/run +0 -1
- package/bin/run.js +5 -0
- package/dist/commands/apply.d.ts +17 -17
- package/dist/commands/apply.js +160 -173
- package/dist/commands/extract.d.ts +13 -7
- package/dist/commands/extract.js +89 -73
- package/dist/commands/init.d.ts +7 -7
- package/dist/commands/init.js +78 -80
- package/dist/flags/common.d.ts +7 -7
- package/dist/flags/common.js +8 -11
- package/dist/index.js +1 -5
- package/dist/lib/constants.js +6 -9
- 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 +2 -5
- package/dist/lib/init/index.js +54 -59
- package/dist/lib/init/types.js +1 -2
- package/dist/lib/init.d.ts +1 -0
- package/dist/lib/init.js +2 -0
- package/dist/lib/load/apply-flags.js +17 -23
- 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/utils/animated-bunny.js +9 -14
- package/dist/lib/utils/auth.d.ts +2 -2
- package/dist/lib/utils/auth.js +32 -33
- 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.js +4 -9
- 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/system-fields.js +19 -22
- 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 +19 -24
- package/dist/services/github.d.ts +1 -1
- package/dist/services/github.js +8 -12
- package/oclif.manifest.json +4 -4
- package/package.json +36 -32
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const sdk_1 = require("../sdk");
|
|
5
|
-
const logger_1 = require("../utils/logger");
|
|
1
|
+
import { ux } from '@oclif/core';
|
|
2
|
+
import { DirectusError } from '../sdk.js';
|
|
3
|
+
import { logger } from '../utils/logger.js';
|
|
6
4
|
/**
|
|
7
5
|
* Handles errors by formatting them and optionally logging to console and file.
|
|
8
6
|
* @param error - The error to be handled.
|
|
9
7
|
* @param options - Configuration options for error handling.
|
|
10
8
|
* @returns void
|
|
11
9
|
*/
|
|
12
|
-
function catchError(error, options = {}) {
|
|
10
|
+
export default function catchError(error, options = {}) {
|
|
13
11
|
const { context = {}, fatal = false, logToFile = true } = options;
|
|
14
12
|
let errorMessage;
|
|
15
|
-
if (error instanceof
|
|
13
|
+
if (error instanceof DirectusError) {
|
|
16
14
|
errorMessage = error.message;
|
|
17
15
|
}
|
|
18
16
|
else if (error instanceof Error) {
|
|
@@ -29,13 +27,12 @@ function catchError(error, options = {}) {
|
|
|
29
27
|
// Log the error message to the console with the appropriate color
|
|
30
28
|
if (fatal) {
|
|
31
29
|
// ux.error exits the process with a non-zero code
|
|
32
|
-
|
|
30
|
+
ux.error(formattedMessage);
|
|
33
31
|
}
|
|
34
32
|
else {
|
|
35
|
-
|
|
33
|
+
ux.warn(formattedMessage);
|
|
36
34
|
}
|
|
37
35
|
if (logToFile) {
|
|
38
|
-
|
|
36
|
+
logger.log('error', errorMessage, context);
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
|
-
exports.default = catchError;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const read_file_1 = tslib_1.__importDefault(require("../utils/read-file"));
|
|
5
|
-
async function checkTemplate(dir) {
|
|
1
|
+
import readFile from '../utils/read-file.js';
|
|
2
|
+
export default async function checkTemplate(dir) {
|
|
6
3
|
// Check for the collections,fields, and relations files
|
|
7
4
|
try {
|
|
8
|
-
const collections = (
|
|
9
|
-
const fields = (
|
|
5
|
+
const collections = readFile('collections', dir);
|
|
6
|
+
const fields = readFile('fields', dir);
|
|
10
7
|
const isCollectionsOk = collections.length > 0 && fields.length > 0;
|
|
11
8
|
return isCollectionsOk;
|
|
12
9
|
}
|
|
@@ -14,4 +11,3 @@ async function checkTemplate(dir) {
|
|
|
14
11
|
console.error(error);
|
|
15
12
|
}
|
|
16
13
|
}
|
|
17
|
-
exports.default = checkTemplate;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.chunkArray = void 0;
|
|
4
|
-
function chunkArray(array, size) {
|
|
1
|
+
export function chunkArray(array, size) {
|
|
5
2
|
return Array.from({ length: Math.ceil(array.length / size) }, (_, index) => array.slice(index * size, (index + 1) * size));
|
|
6
3
|
}
|
|
7
|
-
exports.chunkArray = chunkArray;
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function ensureDir(dir) {
|
|
6
|
-
if (!(0, node_fs_1.existsSync)(dir)) {
|
|
7
|
-
(0, node_fs_1.mkdirSync)(dir, { recursive: true });
|
|
1
|
+
import { existsSync, mkdirSync } from 'node:fs';
|
|
2
|
+
export function ensureDir(dir) {
|
|
3
|
+
if (!existsSync(dir)) {
|
|
4
|
+
mkdirSync(dir, { recursive: true });
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
(0, node_fs_1.mkdirSync)(dir, { recursive: true });
|
|
7
|
+
export function ensureDirSync(dir) {
|
|
8
|
+
if (!existsSync(dir)) {
|
|
9
|
+
mkdirSync(dir, { recursive: true });
|
|
14
10
|
}
|
|
15
11
|
}
|
|
16
|
-
exports.ensureDirSync = ensureDirSync;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
// Utility function to remove relationship data (arrays of integers or UUIDs) from system collection data. Used for when custom fields are added to system collections. The relational data should be populated when the actual data is loaded.
|
|
4
|
-
function filterFields(dataArray, systemFields) {
|
|
2
|
+
export default function filterFields(dataArray, systemFields) {
|
|
5
3
|
return dataArray.map(item => {
|
|
6
4
|
for (const key of Object.keys(item)) {
|
|
7
5
|
if (!systemFields.includes(key)) {
|
|
@@ -19,4 +17,3 @@ function filterFields(dataArray, systemFields) {
|
|
|
19
17
|
return item;
|
|
20
18
|
});
|
|
21
19
|
}
|
|
22
|
-
exports.default = filterFields;
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const read_file_1 = tslib_1.__importDefault(require("./read-file"));
|
|
7
|
-
async function getRoleIds(dir) {
|
|
8
|
-
var _a;
|
|
9
|
-
const roles = (0, read_file_1.default)('roles', dir);
|
|
1
|
+
import { readMe } from '@directus/sdk';
|
|
2
|
+
import { api } from '../sdk.js';
|
|
3
|
+
import readFile from './read-file.js';
|
|
4
|
+
export default async function getRoleIds(dir) {
|
|
5
|
+
const roles = readFile('roles', dir);
|
|
10
6
|
// Legacy admin role may be undefined if the admin role was renamed in the source Directus project.
|
|
11
|
-
const legacyAdminRoleId =
|
|
12
|
-
const currentUser = await
|
|
7
|
+
const legacyAdminRoleId = roles.find(role => role.name === 'Administrator')?.id;
|
|
8
|
+
const currentUser = await api.client.request(readMe());
|
|
13
9
|
const newAdminRoleId = currentUser.role;
|
|
14
10
|
return { email: currentUser.email, legacyAdminRoleId, newAdminRoleId };
|
|
15
11
|
}
|
|
16
|
-
exports.default = getRoleIds;
|
|
@@ -1,49 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
async function getCommunityTemplates() {
|
|
13
|
-
const downloadDir = (
|
|
1
|
+
import { downloadTemplate } from 'giget';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import path, { dirname } from 'pathe';
|
|
5
|
+
import { COMMUNITY_TEMPLATE_REPO } from '../constants.js';
|
|
6
|
+
import resolvePathAndCheckExistence from './path.js';
|
|
7
|
+
import { readAllTemplates, readTemplate } from './read-templates.js';
|
|
8
|
+
import { transformGitHubUrl } from './transform-github-url.js';
|
|
9
|
+
// Create __dirname equivalent for ESM
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = dirname(__filename);
|
|
12
|
+
export async function getCommunityTemplates() {
|
|
13
|
+
const downloadDir = resolvePathAndCheckExistence(path.join(__dirname, '..', 'downloads', 'official'), false);
|
|
14
14
|
if (!downloadDir) {
|
|
15
|
-
throw new Error(`Invalid download directory: ${
|
|
15
|
+
throw new Error(`Invalid download directory: ${path.join(__dirname, '..', 'downloads', 'official')}`);
|
|
16
16
|
}
|
|
17
17
|
try {
|
|
18
|
-
const { dir } = await
|
|
18
|
+
const { dir } = await downloadTemplate(COMMUNITY_TEMPLATE_REPO.string, {
|
|
19
19
|
dir: downloadDir,
|
|
20
20
|
force: true,
|
|
21
21
|
});
|
|
22
|
-
return await
|
|
22
|
+
return await readAllTemplates(dir);
|
|
23
23
|
}
|
|
24
24
|
catch (error) {
|
|
25
25
|
throw new Error(`Failed to download community templates: ${error}`);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const resolvedDir = (0, path_1.default)(localTemplateDir);
|
|
28
|
+
export async function getLocalTemplate(localTemplateDir) {
|
|
29
|
+
const resolvedDir = resolvePathAndCheckExistence(localTemplateDir);
|
|
31
30
|
if (!resolvedDir) {
|
|
32
31
|
throw new Error('Directory does not exist.');
|
|
33
32
|
}
|
|
34
|
-
return
|
|
33
|
+
return readTemplate(resolvedDir);
|
|
35
34
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const resolvedDir = (0, path_1.default)(localTemplateDir);
|
|
35
|
+
export async function getInteractiveLocalTemplate(localTemplateDir) {
|
|
36
|
+
const resolvedDir = resolvePathAndCheckExistence(localTemplateDir);
|
|
39
37
|
if (!resolvedDir) {
|
|
40
38
|
throw new Error('Directory does not exist.');
|
|
41
39
|
}
|
|
42
|
-
const directTemplate = await
|
|
40
|
+
const directTemplate = await readTemplate(resolvedDir);
|
|
43
41
|
if (directTemplate) {
|
|
44
42
|
return [directTemplate];
|
|
45
43
|
}
|
|
46
|
-
const templates = await
|
|
44
|
+
const templates = await readAllTemplates(resolvedDir);
|
|
47
45
|
if (templates.length === 0) {
|
|
48
46
|
// If no templates found, search nested directories
|
|
49
47
|
const nestedTemplates = await findNestedTemplates(resolvedDir, 2);
|
|
@@ -54,16 +52,15 @@ async function getInteractiveLocalTemplate(localTemplateDir) {
|
|
|
54
52
|
}
|
|
55
53
|
return templates;
|
|
56
54
|
}
|
|
57
|
-
exports.getInteractiveLocalTemplate = getInteractiveLocalTemplate;
|
|
58
55
|
async function findNestedTemplates(dir, depth) {
|
|
59
56
|
if (depth === 0)
|
|
60
57
|
return [];
|
|
61
58
|
const templates = [];
|
|
62
|
-
const entries = await
|
|
59
|
+
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
63
60
|
for (const entry of entries) {
|
|
64
61
|
if (entry.isDirectory()) {
|
|
65
|
-
const fullPath =
|
|
66
|
-
const dirTemplates = await
|
|
62
|
+
const fullPath = path.join(dir, entry.name);
|
|
63
|
+
const dirTemplates = await readAllTemplates(fullPath);
|
|
67
64
|
templates.push(...dirTemplates);
|
|
68
65
|
if (dirTemplates.length === 0 && depth > 1) {
|
|
69
66
|
// If no templates found and we can go deeper, search subdirectories
|
|
@@ -74,26 +71,25 @@ async function findNestedTemplates(dir, depth) {
|
|
|
74
71
|
}
|
|
75
72
|
return templates;
|
|
76
73
|
}
|
|
77
|
-
async function getGithubTemplate(ghTemplateUrl) {
|
|
74
|
+
export async function getGithubTemplate(ghTemplateUrl) {
|
|
78
75
|
try {
|
|
79
|
-
const ghString = await
|
|
80
|
-
const downloadDir = (
|
|
76
|
+
const ghString = await transformGitHubUrl(ghTemplateUrl);
|
|
77
|
+
const downloadDir = resolvePathAndCheckExistence(path.join(__dirname, '..', 'downloads', 'github'), false);
|
|
81
78
|
if (!downloadDir) {
|
|
82
|
-
throw new Error(`Invalid download directory: ${
|
|
79
|
+
throw new Error(`Invalid download directory: ${path.join(__dirname, '..', 'downloads', 'github')}`);
|
|
83
80
|
}
|
|
84
|
-
const { dir } = await
|
|
81
|
+
const { dir } = await downloadTemplate(ghString, {
|
|
85
82
|
dir: downloadDir,
|
|
86
83
|
force: true,
|
|
87
84
|
forceClean: true,
|
|
88
85
|
});
|
|
89
|
-
const resolvedDir = (
|
|
86
|
+
const resolvedDir = resolvePathAndCheckExistence(dir);
|
|
90
87
|
if (!resolvedDir) {
|
|
91
88
|
throw new Error(`Downloaded template directory does not exist: ${dir}`);
|
|
92
89
|
}
|
|
93
|
-
return
|
|
90
|
+
return readTemplate(resolvedDir);
|
|
94
91
|
}
|
|
95
92
|
catch (error) {
|
|
96
93
|
throw new Error(`Failed to download GitHub template: ${error}`);
|
|
97
94
|
}
|
|
98
95
|
}
|
|
99
|
-
exports.getGithubTemplate = getGithubTemplate;
|
package/dist/lib/utils/logger.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.logger = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
|
-
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'pathe';
|
|
7
3
|
class Logger {
|
|
4
|
+
static instance;
|
|
5
|
+
logFilePath;
|
|
8
6
|
constructor() {
|
|
9
7
|
this.initializeLogFile();
|
|
10
8
|
}
|
|
@@ -21,13 +19,13 @@ class Logger {
|
|
|
21
19
|
this.writeToFile(logEntry);
|
|
22
20
|
}
|
|
23
21
|
initializeLogFile() {
|
|
24
|
-
// @ts-ignore
|
|
22
|
+
// @ts-ignore - ignore
|
|
25
23
|
const timestamp = new Date().toISOString().replaceAll(/[.:]/g, '-');
|
|
26
|
-
const logDir =
|
|
27
|
-
if (!
|
|
28
|
-
|
|
24
|
+
const logDir = path.join(process.cwd(), '.directus-template-cli', 'logs');
|
|
25
|
+
if (!fs.existsSync(logDir)) {
|
|
26
|
+
fs.mkdirSync(logDir, { recursive: true });
|
|
29
27
|
}
|
|
30
|
-
this.logFilePath =
|
|
28
|
+
this.logFilePath = path.join(logDir, `run-${timestamp}.log`);
|
|
31
29
|
// Write initial timestamp to the log file
|
|
32
30
|
this.writeToFile(`Log started at ${timestamp}\n`);
|
|
33
31
|
}
|
|
@@ -45,11 +43,11 @@ class Logger {
|
|
|
45
43
|
}
|
|
46
44
|
writeToFile(message) {
|
|
47
45
|
try {
|
|
48
|
-
|
|
46
|
+
fs.appendFileSync(this.logFilePath, message);
|
|
49
47
|
}
|
|
50
48
|
catch (error) {
|
|
51
49
|
console.error('Error writing to log file:', error);
|
|
52
50
|
}
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
|
-
|
|
53
|
+
export const logger = Logger.getInstance();
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const node_child_process_1 = require("node:child_process");
|
|
4
|
-
function openUrl(url) {
|
|
1
|
+
import { exec } from 'node:child_process';
|
|
2
|
+
export default function openUrl(url) {
|
|
5
3
|
switch (process.platform) {
|
|
6
4
|
case 'darwin': {
|
|
7
|
-
|
|
5
|
+
exec(`open ${url}`);
|
|
8
6
|
break;
|
|
9
7
|
}
|
|
10
8
|
case 'win32': {
|
|
11
|
-
|
|
9
|
+
exec(`start ${url}`);
|
|
12
10
|
break;
|
|
13
11
|
}
|
|
14
12
|
default: {
|
|
15
|
-
|
|
13
|
+
exec(`xdg-open ${url}`);
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
16
|
}
|
|
19
|
-
exports.default = openUrl;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createGigetString = exports.parseGitHubUrl = void 0;
|
|
4
|
-
const constants_1 = require("../constants");
|
|
1
|
+
import { DEFAULT_REPO } from '../constants.js';
|
|
5
2
|
/**
|
|
6
3
|
* Parse a GitHub URL into its components.
|
|
7
4
|
* @param url - The GitHub URL to parse.
|
|
8
5
|
* @returns The parsed GitHub URL components.
|
|
9
6
|
*/
|
|
10
|
-
function parseGitHubUrl(url) {
|
|
7
|
+
export function parseGitHubUrl(url) {
|
|
11
8
|
// Handle simple template names by using default repo
|
|
12
9
|
if (!url.includes('/')) {
|
|
13
|
-
return { ...
|
|
10
|
+
return { ...DEFAULT_REPO, path: url };
|
|
14
11
|
}
|
|
15
12
|
// Handle different GitHub URL formats:
|
|
16
13
|
// - https://github.com/owner/repo
|
|
@@ -42,8 +39,7 @@ function parseGitHubUrl(url) {
|
|
|
42
39
|
throw new Error(`Invalid GitHub URL format: ${url}`);
|
|
43
40
|
}
|
|
44
41
|
}
|
|
45
|
-
|
|
46
|
-
function createGigetString({ owner, path, ref, repo }) {
|
|
42
|
+
export function createGigetString({ owner, path, ref, repo }) {
|
|
47
43
|
let source = `github:${owner}/${repo}`;
|
|
48
44
|
if (path)
|
|
49
45
|
source += `/${path}`;
|
|
@@ -51,4 +47,3 @@ function createGigetString({ owner, path, ref, repo }) {
|
|
|
51
47
|
source += `#${ref}`;
|
|
52
48
|
return source;
|
|
53
49
|
}
|
|
54
|
-
exports.createGigetString = createGigetString;
|
package/dist/lib/utils/path.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
5
|
-
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
6
|
-
const node_process_1 = require("node:process");
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'pathe';
|
|
3
|
+
import { cwd } from 'node:process';
|
|
7
4
|
/**
|
|
8
5
|
* Resolves a given path to an absolute path and checks if it exists.
|
|
9
6
|
* @param inputPath The path to resolve.
|
|
10
7
|
* @param checkExistence Whether to check if the resolved path exists.
|
|
11
8
|
* @returns The resolved absolute path if it exists, or null if it doesn't.
|
|
12
9
|
*/
|
|
13
|
-
function resolvePathAndCheckExistence(inputPath, checkExistence = true) {
|
|
14
|
-
const resolvedPath =
|
|
15
|
-
if (!checkExistence ||
|
|
10
|
+
export default function resolvePathAndCheckExistence(inputPath, checkExistence = true) {
|
|
11
|
+
const resolvedPath = path.isAbsolute(inputPath) ? inputPath : path.resolve(cwd(), inputPath);
|
|
12
|
+
if (!checkExistence || fs.existsSync(resolvedPath)) {
|
|
16
13
|
return resolvedPath;
|
|
17
14
|
}
|
|
18
15
|
return null;
|
|
19
16
|
}
|
|
20
|
-
exports.default = resolvePathAndCheckExistence;
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const filePath = node_path_1.default.join(dir, `${file}.json`); // Use path.join for proper path resolution
|
|
9
|
-
if (!node_fs_1.default.existsSync(filePath)) {
|
|
10
|
-
(0, catch_error_1.default)(`File not found: ${filePath}`);
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'pathe';
|
|
3
|
+
import catchError from './catch-error.js';
|
|
4
|
+
export default function readFile(file, dir) {
|
|
5
|
+
const filePath = path.join(dir, `${file}.json`); // Use path.join for proper path resolution
|
|
6
|
+
if (!fs.existsSync(filePath)) {
|
|
7
|
+
catchError(`File not found: ${filePath}`);
|
|
11
8
|
}
|
|
12
|
-
const fileContents =
|
|
9
|
+
const fileContents = fs.readFileSync(filePath, 'utf8');
|
|
13
10
|
const obj = JSON.parse(fileContents);
|
|
14
11
|
return obj;
|
|
15
12
|
}
|
|
16
|
-
exports.default = readFile;
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
|
-
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
7
|
-
async function readTemplate(directoryPath) {
|
|
8
|
-
const packageFilePath = node_path_1.default.join(directoryPath, 'package.json');
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'pathe';
|
|
3
|
+
export async function readTemplate(directoryPath) {
|
|
4
|
+
const packageFilePath = path.join(directoryPath, 'package.json');
|
|
9
5
|
try {
|
|
10
|
-
const packageData = await
|
|
6
|
+
const packageData = await fs.promises.readFile(packageFilePath, 'utf8');
|
|
11
7
|
const packageJson = JSON.parse(packageData);
|
|
12
8
|
if (packageJson.templateName) {
|
|
13
9
|
return {
|
|
@@ -24,13 +20,12 @@ async function readTemplate(directoryPath) {
|
|
|
24
20
|
return null;
|
|
25
21
|
}
|
|
26
22
|
}
|
|
27
|
-
|
|
28
|
-
async function readAllTemplates(directoryPath) {
|
|
23
|
+
export async function readAllTemplates(directoryPath) {
|
|
29
24
|
const templates = [];
|
|
30
|
-
const files = await
|
|
25
|
+
const files = await fs.promises.readdir(directoryPath);
|
|
31
26
|
for (const file of files) {
|
|
32
|
-
const filePath =
|
|
33
|
-
const stats = await
|
|
27
|
+
const filePath = path.join(directoryPath, file);
|
|
28
|
+
const stats = await fs.promises.stat(filePath);
|
|
34
29
|
if (stats.isDirectory()) {
|
|
35
30
|
const template = await readTemplate(filePath);
|
|
36
31
|
if (template) {
|
|
@@ -40,4 +35,3 @@ async function readAllTemplates(directoryPath) {
|
|
|
40
35
|
}
|
|
41
36
|
return templates;
|
|
42
37
|
}
|
|
43
|
-
exports.readAllTemplates = readAllTemplates;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.systemFields = exports.directusSettingsFields = exports.directusPanelFields = exports.directusDashboardFields = exports.directusOperationFields = exports.directusFlowFields = exports.directusFolderFields = exports.directusFileFields = exports.directusRoleFields = exports.directusUserFields = void 0;
|
|
4
|
-
exports.directusUserFields = [
|
|
1
|
+
export const directusUserFields = [
|
|
5
2
|
'id',
|
|
6
3
|
'status',
|
|
7
4
|
'first_name',
|
|
@@ -25,7 +22,7 @@ exports.directusUserFields = [
|
|
|
25
22
|
'tags',
|
|
26
23
|
'email_notifications',
|
|
27
24
|
];
|
|
28
|
-
|
|
25
|
+
export const directusRoleFields = [
|
|
29
26
|
'id',
|
|
30
27
|
'name',
|
|
31
28
|
'description',
|
|
@@ -36,7 +33,7 @@ exports.directusRoleFields = [
|
|
|
36
33
|
'app_access',
|
|
37
34
|
'admin_access',
|
|
38
35
|
];
|
|
39
|
-
|
|
36
|
+
export const directusFileFields = [
|
|
40
37
|
'id',
|
|
41
38
|
'storage',
|
|
42
39
|
'filename_disk',
|
|
@@ -59,12 +56,12 @@ exports.directusFileFields = [
|
|
|
59
56
|
'tags',
|
|
60
57
|
'metadata',
|
|
61
58
|
];
|
|
62
|
-
|
|
59
|
+
export const directusFolderFields = [
|
|
63
60
|
'id',
|
|
64
61
|
'name',
|
|
65
62
|
'parent',
|
|
66
63
|
];
|
|
67
|
-
|
|
64
|
+
export const directusFlowFields = [
|
|
68
65
|
'id',
|
|
69
66
|
'name',
|
|
70
67
|
'icon',
|
|
@@ -78,7 +75,7 @@ exports.directusFlowFields = [
|
|
|
78
75
|
'date_created',
|
|
79
76
|
'user_created',
|
|
80
77
|
];
|
|
81
|
-
|
|
78
|
+
export const directusOperationFields = [
|
|
82
79
|
'id',
|
|
83
80
|
'name',
|
|
84
81
|
'key',
|
|
@@ -92,7 +89,7 @@ exports.directusOperationFields = [
|
|
|
92
89
|
'date_created',
|
|
93
90
|
'user_created',
|
|
94
91
|
];
|
|
95
|
-
|
|
92
|
+
export const directusDashboardFields = [
|
|
96
93
|
'id',
|
|
97
94
|
'name',
|
|
98
95
|
'icon',
|
|
@@ -101,7 +98,7 @@ exports.directusDashboardFields = [
|
|
|
101
98
|
'user_created',
|
|
102
99
|
'color',
|
|
103
100
|
];
|
|
104
|
-
|
|
101
|
+
export const directusPanelFields = [
|
|
105
102
|
'id',
|
|
106
103
|
'dashboard',
|
|
107
104
|
'name',
|
|
@@ -118,7 +115,7 @@ exports.directusPanelFields = [
|
|
|
118
115
|
'date_created',
|
|
119
116
|
'user_created',
|
|
120
117
|
];
|
|
121
|
-
|
|
118
|
+
export const directusSettingsFields = [
|
|
122
119
|
'id',
|
|
123
120
|
'project_name',
|
|
124
121
|
'project_url',
|
|
@@ -146,14 +143,14 @@ exports.directusSettingsFields = [
|
|
|
146
143
|
'default_theme_dark',
|
|
147
144
|
'theme_dark_overrides',
|
|
148
145
|
];
|
|
149
|
-
|
|
150
|
-
directus_dashboards:
|
|
151
|
-
directus_files:
|
|
152
|
-
directus_flows:
|
|
153
|
-
directus_folders:
|
|
154
|
-
directus_operations:
|
|
155
|
-
directus_panels:
|
|
156
|
-
directus_roles:
|
|
157
|
-
directus_settings:
|
|
158
|
-
directus_users:
|
|
146
|
+
export const systemFields = {
|
|
147
|
+
directus_dashboards: directusDashboardFields,
|
|
148
|
+
directus_files: directusFileFields,
|
|
149
|
+
directus_flows: directusFlowFields,
|
|
150
|
+
directus_folders: directusFolderFields,
|
|
151
|
+
directus_operations: directusOperationFields,
|
|
152
|
+
directus_panels: directusPanelFields,
|
|
153
|
+
directus_roles: directusRoleFields,
|
|
154
|
+
directus_settings: directusSettingsFields,
|
|
155
|
+
directus_users: directusUserFields,
|
|
159
156
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare function generatePackageJsonContent(templateName: string): string;
|
|
2
2
|
export declare const generateReadmeContent: (templateName: string) => string;
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const slugify_1 = tslib_1.__importDefault(require("slugify"));
|
|
6
|
-
const generatePackageJsonContent = (templateName) => {
|
|
7
|
-
const slugifiedName = (0, slugify_1.default)(templateName, {
|
|
8
|
-
lower: true, // Convert to lowercase
|
|
9
|
-
strict: true, // Remove special characters
|
|
10
|
-
});
|
|
1
|
+
import slugify from '@sindresorhus/slugify';
|
|
2
|
+
export function generatePackageJsonContent(templateName) {
|
|
3
|
+
const slugifiedName = slugify(templateName);
|
|
11
4
|
const packageName = `directus-template-${slugifiedName}`;
|
|
12
5
|
return JSON.stringify({
|
|
13
6
|
author: '',
|
|
@@ -18,9 +11,8 @@ const generatePackageJsonContent = (templateName) => {
|
|
|
18
11
|
templateName,
|
|
19
12
|
version: '1.0.0',
|
|
20
13
|
}, null, 2);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const generateReadmeContent = (templateName) => `# ${templateName} Template
|
|
14
|
+
}
|
|
15
|
+
export const generateReadmeContent = (templateName) => `# ${templateName} Template
|
|
24
16
|
|
|
25
17
|
This is a template for [Directus](https://directus.io/) - an open-source headless CMS and API. Use the template-cli to load / apply this template to a blank instance.
|
|
26
18
|
|
|
@@ -31,4 +23,3 @@ This is a template for [Directus](https://directus.io/) - an open-source headles
|
|
|
31
23
|
## License
|
|
32
24
|
|
|
33
25
|
`;
|
|
34
|
-
exports.generateReadmeContent = generateReadmeContent;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformGitHubUrl = void 0;
|
|
4
|
-
function transformGitHubUrl(url) {
|
|
1
|
+
export function transformGitHubUrl(url) {
|
|
5
2
|
// Regular expression to capture the repository name and any subsequent path after the 'tree'
|
|
6
3
|
const regex = /github\.com\/([^/]+\/[^/]+)(?:\/tree\/[^/]+\/(.*))?$/;
|
|
7
4
|
const match = url.match(regex);
|
|
@@ -12,4 +9,3 @@ function transformGitHubUrl(url) {
|
|
|
12
9
|
}
|
|
13
10
|
return 'Invalid URL';
|
|
14
11
|
}
|
|
15
|
-
exports.transformGitHubUrl = transformGitHubUrl;
|