directus-template-cli 0.7.0-beta.4 → 0.7.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/dev.js +6 -0
- package/bin/run.js +5 -0
- package/dist/commands/apply.d.ts +17 -17
- package/dist/commands/apply.js +163 -173
- package/dist/commands/base.d.ts +15 -0
- package/dist/commands/base.js +45 -0
- package/dist/commands/extract.d.ts +16 -7
- package/dist/commands/extract.js +80 -73
- package/dist/commands/init.d.ts +20 -15
- package/dist/commands/init.js +189 -126
- package/dist/flags/common.d.ts +8 -7
- package/dist/flags/common.js +13 -11
- package/dist/index.js +1 -5
- package/dist/lib/constants.d.ts +3 -5
- package/dist/lib/constants.js +8 -13
- 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 +3 -6
- package/dist/lib/init/index.d.ts +5 -9
- package/dist/lib/init/index.js +105 -85
- package/dist/lib/init/types.js +1 -2
- package/dist/lib/load/apply-flags.js +17 -23
- package/dist/lib/load/index.d.ts +1 -12
- package/dist/lib/load/index.js +40 -44
- package/dist/lib/load/load-access.js +15 -20
- package/dist/lib/load/load-collections.js +27 -32
- package/dist/lib/load/load-dashboards.js +19 -25
- package/dist/lib/load/load-data.js +43 -49
- package/dist/lib/load/load-extensions.js +30 -38
- package/dist/lib/load/load-files.js +20 -24
- package/dist/lib/load/load-flows.js +23 -29
- package/dist/lib/load/load-folders.js +16 -20
- package/dist/lib/load/load-permissions.js +13 -17
- package/dist/lib/load/load-policies.js +14 -18
- package/dist/lib/load/load-presets.js +14 -18
- package/dist/lib/load/load-relations.d.ts +2 -0
- package/dist/lib/load/load-relations.js +16 -18
- package/dist/lib/load/load-roles.js +19 -23
- package/dist/lib/load/load-settings.js +18 -21
- package/dist/lib/load/load-translations.js +14 -18
- package/dist/lib/load/load-users.js +21 -25
- package/dist/lib/load/update-required-fields.js +13 -17
- package/dist/lib/sdk.d.ts +1 -2
- package/dist/lib/sdk.js +27 -27
- package/dist/lib/types/extension.js +1 -2
- package/dist/lib/types.d.ts +18 -0
- package/dist/lib/types.js +1 -0
- package/dist/lib/utils/animated-bunny.js +9 -14
- package/dist/lib/utils/auth.d.ts +8 -6
- package/dist/lib/utils/auth.js +48 -39
- package/dist/lib/utils/catch-error.js +8 -11
- package/dist/lib/utils/check-template.js +4 -8
- package/dist/lib/utils/chunk-array.js +1 -5
- package/dist/lib/utils/ensure-dir.js +7 -12
- package/dist/lib/utils/filter-fields.js +1 -4
- package/dist/lib/utils/get-role-ids.d.ts +1 -1
- package/dist/lib/utils/get-role-ids.js +7 -12
- package/dist/lib/utils/get-template.js +33 -37
- package/dist/lib/utils/logger.js +11 -13
- package/dist/lib/utils/open-url.js +5 -8
- package/dist/lib/utils/parse-github-url.d.ts +10 -5
- package/dist/lib/utils/parse-github-url.js +80 -45
- package/dist/lib/utils/path.js +6 -10
- package/dist/lib/utils/protected-domains.js +1 -4
- package/dist/lib/utils/read-file.js +8 -12
- package/dist/lib/utils/read-templates.js +9 -15
- package/dist/lib/utils/sanitize-flags.d.ts +3 -0
- package/dist/lib/utils/sanitize-flags.js +4 -0
- package/dist/lib/utils/system-fields.js +19 -22
- package/dist/lib/utils/template-config.d.ts +16 -0
- package/dist/lib/utils/template-config.js +34 -0
- package/dist/lib/utils/template-defaults.d.ts +1 -1
- package/dist/lib/utils/template-defaults.js +5 -14
- package/dist/lib/utils/transform-github-url.js +1 -5
- package/dist/lib/utils/validate-url.js +3 -6
- package/dist/lib/utils/wait.js +1 -5
- package/dist/lib/utils/write-to-file.js +8 -11
- package/dist/services/docker.js +68 -21
- package/dist/services/github.d.ts +1 -1
- package/dist/services/github.js +53 -22
- package/dist/services/posthog.d.ts +37 -0
- package/dist/services/posthog.js +104 -0
- package/oclif.manifest.json +32 -13
- package/package.json +38 -33
- package/bin/dev +0 -17
- package/bin/run +0 -5
|
@@ -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;
|
|
@@ -5,10 +5,15 @@ interface GitHubUrlParts {
|
|
|
5
5
|
repo: string;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
* Parse a GitHub URL or path into its components
|
|
9
|
+
* @param url The URL or path to parse
|
|
10
|
+
* @returns The parsed components
|
|
11
|
+
*/
|
|
12
12
|
export declare function parseGitHubUrl(url: string): GitHubUrlParts;
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Creates a giget-compatible string from GitHub URL parts
|
|
15
|
+
* @param parts The parsed GitHub URL parts
|
|
16
|
+
* @returns A string in the format 'gh:owner/repo#ref[/path]'
|
|
17
|
+
*/
|
|
18
|
+
export declare function createGigetString(parts: GitHubUrlParts): string;
|
|
14
19
|
export {};
|
|
@@ -1,54 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createGigetString = exports.parseGitHubUrl = void 0;
|
|
4
|
-
const constants_1 = require("../constants");
|
|
1
|
+
import { DEFAULT_BRANCH, DEFAULT_REPO } from '../constants.js';
|
|
5
2
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// - https://github.com/owner/repo/tree/branch
|
|
18
|
-
// - https://github.com/owner/repo/tree/branch/path
|
|
19
|
-
// - owner/repo
|
|
20
|
-
// - owner/repo/path
|
|
3
|
+
* Clean and normalize a GitHub URL
|
|
4
|
+
* Handles various formats:
|
|
5
|
+
* - Full URLs with .git
|
|
6
|
+
* - URLs with query parameters
|
|
7
|
+
* - URLs with hash fragments
|
|
8
|
+
* - URLs with branches/refs
|
|
9
|
+
* - Repository paths
|
|
10
|
+
* @param url The URL or path to clean
|
|
11
|
+
* @returns Cleaned URL without .git, queries, or hashes
|
|
12
|
+
*/
|
|
13
|
+
function cleanGitHubUrl(url) {
|
|
21
14
|
try {
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
// If it's not a URL, return as is (might be a path)
|
|
16
|
+
if (!url.includes('://')) {
|
|
17
|
+
return url.replace(/\.git$/, '');
|
|
24
18
|
}
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
19
|
+
// Parse the URL
|
|
20
|
+
const parsed = new URL(url);
|
|
21
|
+
// Remove .git suffix from pathname
|
|
22
|
+
parsed.pathname = parsed.pathname.replace(/\.git$/, '');
|
|
23
|
+
// Remove search params and hash
|
|
24
|
+
parsed.search = '';
|
|
25
|
+
parsed.hash = '';
|
|
26
|
+
return parsed.toString();
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
// If URL parsing fails, just remove .git suffix
|
|
30
|
+
return url.replace(/\.git$/, '');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parse a GitHub URL or path into its components
|
|
35
|
+
* @param url The URL or path to parse
|
|
36
|
+
* @returns The parsed components
|
|
37
|
+
*/
|
|
38
|
+
export function parseGitHubUrl(url) {
|
|
39
|
+
if (!url) {
|
|
40
|
+
throw new Error('URL is required');
|
|
41
|
+
}
|
|
42
|
+
// Clean the URL first
|
|
43
|
+
const cleanedUrl = cleanGitHubUrl(url);
|
|
44
|
+
// Handle full GitHub URLs
|
|
45
|
+
if (cleanedUrl.includes('github.com')) {
|
|
46
|
+
try {
|
|
47
|
+
const parsed = new URL(cleanedUrl);
|
|
48
|
+
const parts = parsed.pathname.split('/').filter(Boolean);
|
|
49
|
+
if (parts.length < 2) {
|
|
50
|
+
throw new Error('Invalid GitHub URL format');
|
|
37
51
|
}
|
|
52
|
+
const [owner, repo, ...rest] = parts;
|
|
53
|
+
const path = rest.length > 0 ? rest.join('/') : undefined;
|
|
54
|
+
const ref = parsed.searchParams.get('ref') || DEFAULT_BRANCH;
|
|
55
|
+
return { owner, repo, path, ref };
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
throw new Error(`Invalid GitHub URL: ${url}`);
|
|
38
59
|
}
|
|
39
|
-
return { owner, path, ref, repo };
|
|
40
60
|
}
|
|
41
|
-
|
|
42
|
-
|
|
61
|
+
// Handle repository paths (owner/repo format)
|
|
62
|
+
const parts = cleanedUrl.split('/').filter(Boolean);
|
|
63
|
+
if (parts.length >= 2) {
|
|
64
|
+
const [owner, repo, ...rest] = parts;
|
|
65
|
+
const path = rest.length > 0 ? rest.join('/') : undefined;
|
|
66
|
+
return { owner, repo, path, ref: DEFAULT_BRANCH };
|
|
43
67
|
}
|
|
68
|
+
// Handle simple template names using DEFAULT_REPO
|
|
69
|
+
return {
|
|
70
|
+
...DEFAULT_REPO,
|
|
71
|
+
path: cleanedUrl // The template name becomes the subpath
|
|
72
|
+
};
|
|
44
73
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Creates a giget-compatible string from GitHub URL parts
|
|
76
|
+
* @param parts The parsed GitHub URL parts
|
|
77
|
+
* @returns A string in the format 'gh:owner/repo#ref[/path]'
|
|
78
|
+
*/
|
|
79
|
+
export function createGigetString(parts) {
|
|
80
|
+
// For the default repo case with a template name
|
|
81
|
+
if (parts.owner === DEFAULT_REPO.owner && parts.repo === DEFAULT_REPO.repo) {
|
|
82
|
+
return `gh:${parts.owner}/${parts.repo}/${parts.path}#${DEFAULT_REPO.ref}`;
|
|
83
|
+
}
|
|
84
|
+
// For other GitHub URLs
|
|
85
|
+
const base = `gh:${parts.owner}/${parts.repo}`;
|
|
86
|
+
const path = parts.path ? `/${parts.path}` : '';
|
|
87
|
+
const ref = parts.ref ? `#${parts.ref}` : '';
|
|
88
|
+
return `${base}${path}${ref}`;
|
|
53
89
|
}
|
|
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
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DirectusTemplateConfig } from '../types.js';
|
|
2
|
+
export interface TemplateInfo {
|
|
3
|
+
config: DirectusTemplateConfig;
|
|
4
|
+
frontendOptions: Array<{
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
path: string;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Read and validate the template configuration from a directory
|
|
12
|
+
* @param dir Directory containing the template
|
|
13
|
+
* @returns Template configuration and frontend options
|
|
14
|
+
* @throws Error if package.json is missing or invalid
|
|
15
|
+
*/
|
|
16
|
+
export declare function readTemplateConfig(dir: string): TemplateInfo | null;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'pathe';
|
|
3
|
+
/**
|
|
4
|
+
* Read and validate the template configuration from a directory
|
|
5
|
+
* @param dir Directory containing the template
|
|
6
|
+
* @returns Template configuration and frontend options
|
|
7
|
+
* @throws Error if package.json is missing or invalid
|
|
8
|
+
*/
|
|
9
|
+
export function readTemplateConfig(dir) {
|
|
10
|
+
try {
|
|
11
|
+
const packageJsonPath = path.join(dir, 'package.json');
|
|
12
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
16
|
+
const templateConfig = packageJson['directus:template'];
|
|
17
|
+
if (!templateConfig) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
// Convert frontends object to array of options
|
|
21
|
+
const frontendOptions = Object.entries(templateConfig.frontends || {}).map(([id, frontend]) => ({
|
|
22
|
+
id,
|
|
23
|
+
name: frontend.name,
|
|
24
|
+
path: frontend.path.replace(/^\.\//, ''), // Remove leading ./
|
|
25
|
+
}));
|
|
26
|
+
return {
|
|
27
|
+
config: templateConfig,
|
|
28
|
+
frontendOptions,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare function generatePackageJsonContent(templateName: string): string;
|
|
2
2
|
export declare const generateReadmeContent: (templateName: string) => string;
|