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
package/dist/lib/init/index.js
CHANGED
|
@@ -1,71 +1,99 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
async function init(dir, flags) {
|
|
1
|
+
import { note, outro, spinner } from '@clack/prompts';
|
|
2
|
+
import { ux } from '@oclif/core';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { execa } from 'execa';
|
|
5
|
+
import { downloadTemplate } from 'giget';
|
|
6
|
+
import { glob } from 'glob';
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import { detectPackageManager, installDependencies } from 'nypm';
|
|
9
|
+
import path from 'pathe';
|
|
10
|
+
import dotenv from 'dotenv';
|
|
11
|
+
import ApplyCommand from '../../commands/apply.js';
|
|
12
|
+
import { createDocker } from '../../services/docker.js';
|
|
13
|
+
import catchError from '../utils/catch-error.js';
|
|
14
|
+
import { createGigetString, parseGitHubUrl } from '../utils/parse-github-url.js';
|
|
15
|
+
import { readTemplateConfig } from '../utils/template-config.js';
|
|
16
|
+
import { DOCKER_CONFIG } from './config.js';
|
|
17
|
+
export async function init({ dir, flags }) {
|
|
19
18
|
// Check target directory
|
|
20
19
|
const shouldForce = flags.overrideDir;
|
|
21
|
-
if (
|
|
20
|
+
if (fs.existsSync(dir) && !shouldForce) {
|
|
22
21
|
throw new Error('Directory already exists. Use --override-dir to override.');
|
|
23
22
|
}
|
|
24
|
-
|
|
25
|
-
const
|
|
23
|
+
// If template is a URL, we need to handle it differently
|
|
24
|
+
const isDirectUrl = flags.template?.startsWith('http');
|
|
25
|
+
const directusDir = path.join(dir, 'directus');
|
|
26
26
|
let template;
|
|
27
|
+
let packageManager = null;
|
|
27
28
|
try {
|
|
28
29
|
// Download the template from GitHub
|
|
29
|
-
const parsedUrl =
|
|
30
|
-
|
|
30
|
+
const parsedUrl = parseGitHubUrl(flags.template);
|
|
31
|
+
// If it's a direct URL, we download the entire repository
|
|
32
|
+
// Otherwise, we use the template from the starters repo
|
|
33
|
+
template = await downloadTemplate(createGigetString(parsedUrl), {
|
|
31
34
|
dir,
|
|
32
35
|
force: shouldForce,
|
|
33
36
|
});
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (!
|
|
38
|
-
|
|
37
|
+
// For direct URLs, we need to check if there's a directus directory
|
|
38
|
+
// If not, assume the entire repo is a directus template
|
|
39
|
+
if (isDirectUrl) {
|
|
40
|
+
if (!fs.existsSync(directusDir)) {
|
|
41
|
+
// Move all files to directus directory
|
|
42
|
+
fs.mkdirSync(directusDir, { recursive: true });
|
|
43
|
+
const files = fs.readdirSync(dir);
|
|
44
|
+
for (const file of files) {
|
|
45
|
+
if (file !== 'directus') {
|
|
46
|
+
fs.renameSync(path.join(dir, file), path.join(directusDir, file));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
39
49
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
}
|
|
51
|
+
// Read template configuration
|
|
52
|
+
const templateInfo = readTemplateConfig(dir);
|
|
53
|
+
let frontendDir;
|
|
54
|
+
// Handle frontends based on template configuration
|
|
55
|
+
if (flags.frontend && templateInfo) {
|
|
56
|
+
// Find the selected frontend in the configuration
|
|
57
|
+
const selectedFrontend = templateInfo.frontendOptions.find(f => f.id === flags.frontend);
|
|
58
|
+
if (!selectedFrontend) {
|
|
59
|
+
throw new Error(`Frontend "${flags.frontend}" not found in template configuration`);
|
|
44
60
|
}
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
for (const frontendPath of frontendPaths) {
|
|
53
|
-
const pathToRemove = node_path_1.default.join(dir, frontendPath);
|
|
54
|
-
if (node_fs_1.default.existsSync(pathToRemove)) {
|
|
55
|
-
node_fs_1.default.rmSync(pathToRemove, { recursive: true });
|
|
61
|
+
// Remove all frontend directories except the selected one
|
|
62
|
+
for (const frontend of templateInfo.frontendOptions) {
|
|
63
|
+
if (frontend.id !== flags.frontend) {
|
|
64
|
+
const pathToRemove = path.join(dir, frontend.path);
|
|
65
|
+
if (fs.existsSync(pathToRemove)) {
|
|
66
|
+
fs.rmSync(pathToRemove, { recursive: true });
|
|
67
|
+
}
|
|
56
68
|
}
|
|
57
69
|
}
|
|
70
|
+
// Move the selected frontend to the correct location if needed
|
|
71
|
+
frontendDir = path.join(dir, selectedFrontend.path);
|
|
72
|
+
if (frontendDir !== path.join(dir, flags.frontend)) {
|
|
73
|
+
fs.renameSync(frontendDir, path.join(dir, flags.frontend));
|
|
74
|
+
frontendDir = path.join(dir, flags.frontend);
|
|
75
|
+
}
|
|
58
76
|
}
|
|
77
|
+
const directusInfo = {
|
|
78
|
+
email: '',
|
|
79
|
+
password: '',
|
|
80
|
+
url: '',
|
|
81
|
+
};
|
|
59
82
|
// Find and copy all .env.example files
|
|
60
|
-
const envFiles =
|
|
83
|
+
const envFiles = glob.sync(path.join(dir, '**', '.env.example'));
|
|
61
84
|
for (const file of envFiles) {
|
|
62
85
|
const envFile = file.replace('.env.example', '.env');
|
|
63
|
-
|
|
86
|
+
fs.copyFileSync(file, envFile);
|
|
87
|
+
// Read default Directus login info from .env
|
|
88
|
+
const parsedEnv = dotenv.parse(fs.readFileSync(file, 'utf8'));
|
|
89
|
+
directusInfo.email = parsedEnv.ADMIN_EMAIL;
|
|
90
|
+
directusInfo.password = parsedEnv.ADMIN_PASSWORD;
|
|
91
|
+
directusInfo.url = parsedEnv.PUBLIC_URL;
|
|
64
92
|
}
|
|
65
93
|
// Start Directus and apply template only if directus directory exists
|
|
66
|
-
if (
|
|
94
|
+
if (fs.existsSync(directusDir)) {
|
|
67
95
|
// Initialize Docker service
|
|
68
|
-
const dockerService =
|
|
96
|
+
const dockerService = createDocker(DOCKER_CONFIG);
|
|
69
97
|
// Check if Docker is installed
|
|
70
98
|
const dockerStatus = await dockerService.checkDocker();
|
|
71
99
|
if (!dockerStatus.installed || !dockerStatus.running) {
|
|
@@ -73,66 +101,62 @@ async function init(dir, flags) {
|
|
|
73
101
|
}
|
|
74
102
|
try {
|
|
75
103
|
await dockerService.startContainers(directusDir);
|
|
76
|
-
const healthCheckUrl = `${
|
|
104
|
+
const healthCheckUrl = `${directusInfo.url}${DOCKER_CONFIG.healthCheckEndpoint}`;
|
|
77
105
|
await dockerService.waitForHealthy(healthCheckUrl);
|
|
78
|
-
const templatePath =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
// ux.log(`Attempting to apply template from: ${templatePath}`)
|
|
82
|
-
await apply_1.default.run([
|
|
106
|
+
const templatePath = path.join(directusDir, 'template');
|
|
107
|
+
ux.stdout(`Attempting to apply template from: ${templatePath}`);
|
|
108
|
+
await ApplyCommand.run([
|
|
83
109
|
'--directusUrl=http://localhost:8055',
|
|
84
110
|
'-p',
|
|
85
111
|
'--userEmail=admin@example.com',
|
|
86
112
|
'--userPassword=d1r3ctu5',
|
|
87
|
-
|
|
113
|
+
`--templateLocation=${templatePath}`,
|
|
88
114
|
]);
|
|
89
|
-
// s.stop('Template applied!')
|
|
90
115
|
}
|
|
91
116
|
catch (error) {
|
|
92
|
-
|
|
117
|
+
ux.error('Failed to start Directus containers or apply template');
|
|
93
118
|
throw error;
|
|
94
119
|
}
|
|
95
120
|
}
|
|
96
|
-
// Install dependencies
|
|
97
|
-
if (flags.installDeps
|
|
98
|
-
const s =
|
|
121
|
+
// Install dependencies if requested
|
|
122
|
+
if (flags.installDeps) {
|
|
123
|
+
const s = spinner();
|
|
99
124
|
s.start('Installing dependencies');
|
|
100
|
-
// ux.action.start('Installing dependencies')
|
|
101
125
|
try {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
126
|
+
if (fs.existsSync(frontendDir)) {
|
|
127
|
+
packageManager = await detectPackageManager(frontendDir);
|
|
128
|
+
await installDependencies({
|
|
129
|
+
cwd: frontendDir,
|
|
130
|
+
packageManager,
|
|
131
|
+
silent: true,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
108
134
|
}
|
|
109
135
|
catch (error) {
|
|
110
|
-
|
|
136
|
+
ux.warn('Failed to install dependencies');
|
|
111
137
|
throw error;
|
|
112
138
|
}
|
|
113
|
-
// ux.action.stop()
|
|
114
139
|
s.stop('Dependencies installed!');
|
|
115
140
|
}
|
|
116
141
|
// Initialize Git repo
|
|
117
142
|
if (flags.gitInit) {
|
|
118
|
-
const s =
|
|
143
|
+
const s = spinner();
|
|
119
144
|
s.start('Initializing git repository');
|
|
120
|
-
// ux.action.start('Initializing git repository')
|
|
121
145
|
await initGit(dir);
|
|
122
|
-
// ux.action.stop()
|
|
123
146
|
s.stop('Git repository initialized!');
|
|
124
147
|
}
|
|
125
148
|
// Finishing up
|
|
126
|
-
const relativeDir =
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
(
|
|
149
|
+
const relativeDir = path.relative(process.cwd(), dir);
|
|
150
|
+
const directusText = `- Directus is running on ${directusInfo.url ?? 'http://localhost:8055'}. You can login with the email: ${chalk.cyan(directusInfo.email)} and password: ${chalk.cyan(directusInfo.password)}. \n`;
|
|
151
|
+
const frontendText = flags.frontend ? `- To start the frontend, run ${chalk.cyan(`cd ${flags.frontend}`)} and then ${chalk.cyan(`${packageManager?.name} run dev`)}. \n` : '';
|
|
152
|
+
const projectText = `- Navigate to your project directory using ${chalk.cyan(`cd ${relativeDir}`)}. \n`;
|
|
153
|
+
const readmeText = '- Review the \`./README.md\` file for more information and next steps.';
|
|
154
|
+
const nextSteps = chalk.white(`${directusText}${projectText}${frontendText}${readmeText}`);
|
|
155
|
+
note(nextSteps, 'Next Steps');
|
|
156
|
+
outro(`Problems or questions? Hop into the community on Discord at ${chalk.underline(chalk.cyan('https://directus.chat'))}`);
|
|
133
157
|
}
|
|
134
158
|
catch (error) {
|
|
135
|
-
(
|
|
159
|
+
catchError(error, {
|
|
136
160
|
context: { dir, flags, function: 'init' },
|
|
137
161
|
fatal: true,
|
|
138
162
|
logToFile: true,
|
|
@@ -140,11 +164,10 @@ async function init(dir, flags) {
|
|
|
140
164
|
}
|
|
141
165
|
return {
|
|
142
166
|
directusDir,
|
|
143
|
-
frontendDir,
|
|
167
|
+
frontendDir: flags.frontend ? path.join(dir, flags.frontend) : undefined,
|
|
144
168
|
template,
|
|
145
169
|
};
|
|
146
170
|
}
|
|
147
|
-
exports.init = init;
|
|
148
171
|
/**
|
|
149
172
|
* Initialize a git repository
|
|
150
173
|
* @param targetDir - The directory to initialize the git repository in
|
|
@@ -152,13 +175,10 @@ exports.init = init;
|
|
|
152
175
|
*/
|
|
153
176
|
async function initGit(targetDir) {
|
|
154
177
|
try {
|
|
155
|
-
// ux.action.start('Initializing git repository')
|
|
156
|
-
const { execa } = await Promise.resolve().then(() => tslib_1.__importStar(require('execa')));
|
|
157
178
|
await execa('git', ['init'], { cwd: targetDir });
|
|
158
|
-
// ux.action.stop()
|
|
159
179
|
}
|
|
160
180
|
catch (error) {
|
|
161
|
-
(
|
|
181
|
+
catchError(error, {
|
|
162
182
|
context: { function: 'initGit', targetDir },
|
|
163
183
|
fatal: false,
|
|
164
184
|
logToFile: true,
|
package/dist/lib/init/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const core_1 = require("@oclif/core");
|
|
6
|
-
const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
|
|
7
|
-
exports.loadFlags = [
|
|
1
|
+
import { ux } from '@oclif/core';
|
|
2
|
+
import catchError from '../utils/catch-error.js';
|
|
3
|
+
export const loadFlags = [
|
|
8
4
|
'content',
|
|
9
5
|
'dashboards',
|
|
10
6
|
'extensions',
|
|
@@ -15,53 +11,51 @@ exports.loadFlags = [
|
|
|
15
11
|
'settings',
|
|
16
12
|
'users',
|
|
17
13
|
];
|
|
18
|
-
function validateProgrammaticFlags(flags) {
|
|
14
|
+
export function validateProgrammaticFlags(flags) {
|
|
19
15
|
const { directusToken, directusUrl, templateLocation, userEmail, userPassword } = flags;
|
|
20
16
|
if (!directusUrl)
|
|
21
|
-
|
|
17
|
+
ux.error('Directus URL is required for programmatic mode.');
|
|
22
18
|
if (!directusToken && (!userEmail || !userPassword))
|
|
23
|
-
|
|
19
|
+
ux.error('Either Directus token or email and password are required for programmatic mode.');
|
|
24
20
|
if (!templateLocation)
|
|
25
|
-
|
|
21
|
+
ux.error('Template location is required for programmatic mode.');
|
|
26
22
|
return flags.partial ? handlePartialFlags(flags) : setAllFlagsTrue(flags);
|
|
27
23
|
}
|
|
28
|
-
|
|
29
|
-
function validateInteractiveFlags(flags) {
|
|
24
|
+
export function validateInteractiveFlags(flags) {
|
|
30
25
|
return flags.partial ? handlePartialFlags(flags) : setAllFlagsTrue(flags);
|
|
31
26
|
}
|
|
32
|
-
exports.validateInteractiveFlags = validateInteractiveFlags;
|
|
33
27
|
function handlePartialFlags(flags) {
|
|
34
|
-
const enabledFlags =
|
|
35
|
-
const disabledFlags =
|
|
28
|
+
const enabledFlags = loadFlags.filter(flag => flags[flag] === true);
|
|
29
|
+
const disabledFlags = loadFlags.filter(flag => flags[flag] === false);
|
|
36
30
|
if (enabledFlags.length > 0) {
|
|
37
|
-
for (const flag of
|
|
31
|
+
for (const flag of loadFlags)
|
|
38
32
|
flags[flag] = enabledFlags.includes(flag);
|
|
39
33
|
}
|
|
40
34
|
else if (disabledFlags.length > 0) {
|
|
41
|
-
for (const flag of
|
|
35
|
+
for (const flag of loadFlags)
|
|
42
36
|
flags[flag] = !disabledFlags.includes(flag);
|
|
43
37
|
}
|
|
44
38
|
else {
|
|
45
39
|
setAllFlagsTrue(flags);
|
|
46
40
|
}
|
|
47
41
|
handleDependencies(flags);
|
|
48
|
-
if (!
|
|
49
|
-
(
|
|
42
|
+
if (!loadFlags.some(flag => flags[flag])) {
|
|
43
|
+
catchError(new Error('When using --partial, at least one component must be loaded.'), { fatal: true });
|
|
50
44
|
}
|
|
51
45
|
return flags;
|
|
52
46
|
}
|
|
53
47
|
function handleDependencies(flags) {
|
|
54
48
|
if (flags.content && (!flags.schema || !flags.files)) {
|
|
55
49
|
flags.schema = flags.files = true;
|
|
56
|
-
|
|
50
|
+
ux.warn('Content loading requires schema and files. Enabling schema and files flags.');
|
|
57
51
|
}
|
|
58
52
|
if (flags.users && !flags.permissions) {
|
|
59
53
|
flags.permissions = true;
|
|
60
|
-
|
|
54
|
+
ux.warn('User loading requires permissions. Enabling permissions flag.');
|
|
61
55
|
}
|
|
62
56
|
}
|
|
63
57
|
function setAllFlagsTrue(flags) {
|
|
64
|
-
for (const flag of
|
|
58
|
+
for (const flag of loadFlags)
|
|
65
59
|
flags[flag] = true;
|
|
66
60
|
return flags;
|
|
67
61
|
}
|
package/dist/lib/load/index.d.ts
CHANGED
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
content: boolean;
|
|
3
|
-
dashboards: boolean;
|
|
4
|
-
extensions: boolean;
|
|
5
|
-
files: boolean;
|
|
6
|
-
flows: boolean;
|
|
7
|
-
permissions: boolean;
|
|
8
|
-
schema: boolean;
|
|
9
|
-
settings: boolean;
|
|
10
|
-
users: boolean;
|
|
11
|
-
}
|
|
1
|
+
import type { ApplyFlags } from './apply-flags.js';
|
|
12
2
|
export default function apply(dir: string, flags: ApplyFlags): Promise<{}>;
|
|
13
|
-
export {};
|
package/dist/lib/load/index.js
CHANGED
|
@@ -1,68 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
async function apply(dir, flags) {
|
|
24
|
-
const source = dir + '/src';
|
|
25
|
-
const isTemplateOk = await (0, check_template_1.default)(source);
|
|
1
|
+
import { ux } from '@oclif/core';
|
|
2
|
+
import checkTemplate from '../utils/check-template.js';
|
|
3
|
+
import loadAccess from './load-access.js';
|
|
4
|
+
import loadCollections from './load-collections.js';
|
|
5
|
+
import loadDashboards from './load-dashboards.js';
|
|
6
|
+
import loadData from './load-data.js';
|
|
7
|
+
import loadExtensions from './load-extensions.js';
|
|
8
|
+
import loadFiles from './load-files.js';
|
|
9
|
+
import loadFlows from './load-flows.js';
|
|
10
|
+
import loadFolders from './load-folders.js';
|
|
11
|
+
import loadPermissions from './load-permissions.js';
|
|
12
|
+
import loadPolicies from './load-policies.js';
|
|
13
|
+
import loadPresets from './load-presets.js';
|
|
14
|
+
import loadRelations from './load-relations.js';
|
|
15
|
+
import loadRoles from './load-roles.js';
|
|
16
|
+
import loadSettings from './load-settings.js';
|
|
17
|
+
import loadTranslations from './load-translations.js';
|
|
18
|
+
import loadUsers from './load-users.js';
|
|
19
|
+
import updateRequiredFields from './update-required-fields.js';
|
|
20
|
+
export default async function apply(dir, flags) {
|
|
21
|
+
const source = `${dir}/src`;
|
|
22
|
+
const isTemplateOk = await checkTemplate(source);
|
|
26
23
|
if (!isTemplateOk) {
|
|
27
|
-
|
|
24
|
+
ux.error('The template is missing the collections, fields, or relations files. Older templates are not supported in v0.4 of directus-template-cli. Try using v0.3 to load older templates npx directus-template-cli@0.3 apply or extract the template using latest version before applying. Exiting...');
|
|
28
25
|
}
|
|
29
26
|
if (flags.schema) {
|
|
30
|
-
await (
|
|
31
|
-
await (
|
|
27
|
+
await loadCollections(source);
|
|
28
|
+
await loadRelations(source);
|
|
32
29
|
}
|
|
33
30
|
if (flags.permissions || flags.users) {
|
|
34
|
-
await (
|
|
35
|
-
await (
|
|
36
|
-
await (
|
|
31
|
+
await loadRoles(source);
|
|
32
|
+
await loadPolicies(source);
|
|
33
|
+
await loadPermissions(source);
|
|
37
34
|
if (flags.users) {
|
|
38
|
-
await (
|
|
35
|
+
await loadUsers(source);
|
|
39
36
|
}
|
|
40
|
-
await (
|
|
37
|
+
await loadAccess(source);
|
|
41
38
|
}
|
|
42
39
|
if (flags.files) {
|
|
43
|
-
await (
|
|
44
|
-
await (
|
|
40
|
+
await loadFolders(source);
|
|
41
|
+
await loadFiles(source);
|
|
45
42
|
}
|
|
46
43
|
if (flags.content) {
|
|
47
|
-
await (
|
|
44
|
+
await loadData(source);
|
|
48
45
|
}
|
|
49
46
|
if (flags.schema) {
|
|
50
|
-
await (
|
|
47
|
+
await updateRequiredFields(source);
|
|
51
48
|
}
|
|
52
49
|
if (flags.dashboards) {
|
|
53
|
-
await (
|
|
50
|
+
await loadDashboards(source);
|
|
54
51
|
}
|
|
55
52
|
if (flags.flows) {
|
|
56
|
-
await (
|
|
53
|
+
await loadFlows(source);
|
|
57
54
|
}
|
|
58
55
|
if (flags.settings) {
|
|
59
|
-
await (
|
|
60
|
-
await (
|
|
61
|
-
await (
|
|
56
|
+
await loadSettings(source);
|
|
57
|
+
await loadTranslations(source);
|
|
58
|
+
await loadPresets(source);
|
|
62
59
|
}
|
|
63
60
|
if (flags.extensions) {
|
|
64
|
-
await (
|
|
61
|
+
await loadExtensions(source);
|
|
65
62
|
}
|
|
66
63
|
return {};
|
|
67
64
|
}
|
|
68
|
-
exports.default = apply;
|
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
async function loadAccess(dir) {
|
|
11
|
-
const access = (0, read_file_1.default)('access', dir);
|
|
12
|
-
core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Loading ${access.length} accesses`));
|
|
1
|
+
import { ux } from '@oclif/core';
|
|
2
|
+
import { DIRECTUS_PINK } from '../constants.js';
|
|
3
|
+
import { api } from '../sdk.js';
|
|
4
|
+
import catchError from '../utils/catch-error.js';
|
|
5
|
+
import getRoleIds from '../utils/get-role-ids.js';
|
|
6
|
+
import readFile from '../utils/read-file.js';
|
|
7
|
+
export default async function loadAccess(dir) {
|
|
8
|
+
const access = readFile('access', dir);
|
|
9
|
+
ux.action.start(ux.colorize(DIRECTUS_PINK, `Loading ${access.length} accesses`));
|
|
13
10
|
if (access && access.length > 0) {
|
|
14
11
|
// Fetch existing accesses
|
|
15
|
-
const existingAccesses = await
|
|
12
|
+
const existingAccesses = await api.client.request(() => ({
|
|
16
13
|
method: 'GET',
|
|
17
14
|
params: {
|
|
18
15
|
limit: -1,
|
|
19
16
|
},
|
|
20
17
|
path: '/access',
|
|
21
18
|
}));
|
|
22
|
-
const { legacyAdminRoleId, newAdminRoleId } = await (
|
|
19
|
+
const { legacyAdminRoleId, newAdminRoleId } = await getRoleIds(dir);
|
|
23
20
|
const existingAccessById = new Map(existingAccesses.map(acc => [acc.id, acc]));
|
|
24
21
|
const existingAccessByCompositeKey = new Map(existingAccesses.map(acc => [getCompositeKey(acc), acc]));
|
|
25
22
|
for await (const acc of access) {
|
|
@@ -39,7 +36,7 @@ async function loadAccess(dir) {
|
|
|
39
36
|
if (acc.role === legacyAdminRoleId) {
|
|
40
37
|
acc.role = newAdminRoleId;
|
|
41
38
|
}
|
|
42
|
-
await
|
|
39
|
+
await api.client.request(() => ({
|
|
43
40
|
body: JSON.stringify(acc),
|
|
44
41
|
method: 'POST',
|
|
45
42
|
path: '/access',
|
|
@@ -49,7 +46,7 @@ async function loadAccess(dir) {
|
|
|
49
46
|
existingAccessByCompositeKey.set(compositeKey, acc);
|
|
50
47
|
}
|
|
51
48
|
catch (error) {
|
|
52
|
-
(
|
|
49
|
+
catchError(error, {
|
|
53
50
|
context: {
|
|
54
51
|
access: acc,
|
|
55
52
|
operation: 'createAccess',
|
|
@@ -58,11 +55,9 @@ async function loadAccess(dir) {
|
|
|
58
55
|
}
|
|
59
56
|
}
|
|
60
57
|
}
|
|
61
|
-
|
|
58
|
+
ux.action.stop();
|
|
62
59
|
}
|
|
63
|
-
exports.default = loadAccess;
|
|
64
60
|
// Helper function to generate a composite key for each access
|
|
65
61
|
function getCompositeKey(acc) {
|
|
66
|
-
|
|
67
|
-
return `${(_a = acc.role) !== null && _a !== void 0 ? _a : 'null'}-${(_b = acc.user) !== null && _b !== void 0 ? _b : 'null'}-${acc.policy}`;
|
|
62
|
+
return `${acc.role ?? 'null'}-${acc.user ?? 'null'}-${acc.policy}`;
|
|
68
63
|
}
|