directus-template-cli 0.7.0-beta.5 → 0.7.0-beta.7
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 +3 -0
- package/dist/commands/apply.js +9 -6
- package/dist/commands/base.d.ts +15 -0
- package/dist/commands/base.js +45 -0
- package/dist/commands/extract.d.ts +9 -6
- package/dist/commands/extract.js +4 -13
- package/dist/commands/init.d.ts +14 -9
- package/dist/commands/init.js +140 -75
- package/dist/flags/common.d.ts +1 -0
- package/dist/flags/common.js +5 -0
- package/dist/lib/constants.d.ts +3 -5
- package/dist/lib/constants.js +3 -5
- package/dist/lib/init/config.js +1 -1
- package/dist/lib/init/index.d.ts +5 -9
- package/dist/lib/init/index.js +71 -46
- package/dist/lib/load/index.d.ts +1 -12
- package/dist/lib/types.d.ts +18 -0
- package/dist/lib/types.js +1 -0
- package/dist/lib/utils/auth.d.ts +10 -8
- package/dist/lib/utils/auth.js +17 -7
- package/dist/lib/utils/parse-github-url.d.ts +10 -5
- package/dist/lib/utils/parse-github-url.js +80 -40
- package/dist/lib/utils/sanitize-flags.d.ts +3 -0
- package/dist/lib/utils/sanitize-flags.js +4 -0
- package/dist/lib/utils/template-config.d.ts +16 -0
- package/dist/lib/utils/template-config.js +34 -0
- package/dist/services/docker.js +58 -3
- package/dist/services/github.js +45 -10
- package/dist/services/posthog.d.ts +37 -0
- package/dist/services/posthog.js +104 -0
- package/oclif.manifest.json +29 -10
- package/package.json +4 -3
- package/bin/dev +0 -16
- package/bin/run +0 -4
- package/dist/lib/init.d.ts +0 -1
- package/dist/lib/init.js +0 -2
package/dist/services/github.js
CHANGED
|
@@ -12,19 +12,50 @@ export function createGitHub(token) {
|
|
|
12
12
|
* @returns The directories for the template.
|
|
13
13
|
*/
|
|
14
14
|
async function getTemplateDirectories(template, customUrl) {
|
|
15
|
+
// If template is a URL, parse it directly
|
|
16
|
+
if (template.startsWith('http')) {
|
|
17
|
+
const repo = parseGitHubUrl(template);
|
|
18
|
+
try {
|
|
19
|
+
const { data } = await octokit.rest.repos.getContent({
|
|
20
|
+
owner: repo.owner,
|
|
21
|
+
repo: repo.repo,
|
|
22
|
+
path: repo.path || '',
|
|
23
|
+
ref: repo.ref,
|
|
24
|
+
});
|
|
25
|
+
if (!Array.isArray(data))
|
|
26
|
+
return [];
|
|
27
|
+
// For direct URLs, we don't filter out the directus directory
|
|
28
|
+
// as the entire repo might be a directus template
|
|
29
|
+
return data
|
|
30
|
+
.filter(item => item.type === 'dir')
|
|
31
|
+
.map(item => item.name);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
// If we can't get contents, return empty array
|
|
35
|
+
// This indicates no frontends are available
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// Otherwise use default repo behavior
|
|
15
40
|
const repo = customUrl ? parseGitHubUrl(customUrl) : DEFAULT_REPO;
|
|
16
41
|
const templatePath = repo.path ? `${repo.path}/${template}` : template;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
42
|
+
try {
|
|
43
|
+
const { data } = await octokit.rest.repos.getContent({
|
|
44
|
+
owner: repo.owner,
|
|
45
|
+
path: templatePath,
|
|
46
|
+
ref: repo.ref,
|
|
47
|
+
repo: repo.repo,
|
|
48
|
+
});
|
|
49
|
+
if (!Array.isArray(data))
|
|
50
|
+
return [];
|
|
51
|
+
return data
|
|
52
|
+
.filter(item => item.type === 'dir' && item.name !== 'directus')
|
|
53
|
+
.map(item => item.name);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
// If we can't get contents, return empty array
|
|
24
57
|
return [];
|
|
25
|
-
|
|
26
|
-
.filter(item => item.type === 'dir' && item.name !== 'directus')
|
|
27
|
-
.map(item => item.name);
|
|
58
|
+
}
|
|
28
59
|
}
|
|
29
60
|
/**
|
|
30
61
|
* Get the templates for a repository.
|
|
@@ -32,6 +63,10 @@ export function createGitHub(token) {
|
|
|
32
63
|
* @returns The templates for the repository.
|
|
33
64
|
*/
|
|
34
65
|
async function getTemplates(customUrl) {
|
|
66
|
+
// If customUrl is provided and it's a full repository URL, return it as the only template
|
|
67
|
+
if (customUrl?.startsWith('http')) {
|
|
68
|
+
return [customUrl];
|
|
69
|
+
}
|
|
35
70
|
const repo = customUrl ? parseGitHubUrl(customUrl) : DEFAULT_REPO;
|
|
36
71
|
const { data } = await octokit.rest.repos.getContent({
|
|
37
72
|
owner: repo.owner,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Config } from '@oclif/core';
|
|
2
|
+
import { PostHog } from 'posthog-node';
|
|
3
|
+
/**
|
|
4
|
+
* Initialize and get the PostHog client
|
|
5
|
+
* @param debug Whether to log debug information
|
|
6
|
+
* @returns The PostHog client
|
|
7
|
+
*/
|
|
8
|
+
export declare function getClient(debug?: boolean): PostHog;
|
|
9
|
+
/**
|
|
10
|
+
* Shutdown the PostHog client
|
|
11
|
+
* @param debug Whether to log debug information
|
|
12
|
+
* @returns void
|
|
13
|
+
*/
|
|
14
|
+
export declare function shutdown(debug?: boolean): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Track an event in PostHog
|
|
17
|
+
* @param options The tracking options
|
|
18
|
+
* @param options.lifecycle The lifecycle event to track ('start', 'complete', 'error')
|
|
19
|
+
* @param options.distinctId The distinct ID for the user
|
|
20
|
+
* @param options.command Optional command name (for command tracking)
|
|
21
|
+
* @param options.flags Optional command flags
|
|
22
|
+
* @param options.runId Optional run ID
|
|
23
|
+
* @param options.config Optional config object
|
|
24
|
+
* @param options.properties Optional additional properties to track
|
|
25
|
+
* @param options.debug Whether to log debug information
|
|
26
|
+
*/
|
|
27
|
+
export declare function track({ lifecycle, distinctId, command, flags, runId, message, config, properties, debug }: {
|
|
28
|
+
lifecycle: 'start' | 'complete' | 'error';
|
|
29
|
+
message?: string;
|
|
30
|
+
distinctId: string;
|
|
31
|
+
command?: string;
|
|
32
|
+
flags?: Record<string, unknown>;
|
|
33
|
+
runId?: string;
|
|
34
|
+
config?: Config;
|
|
35
|
+
properties?: Record<string, unknown>;
|
|
36
|
+
debug?: boolean;
|
|
37
|
+
}): void;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { ux } from '@oclif/core';
|
|
2
|
+
import { PostHog } from 'posthog-node';
|
|
3
|
+
import { POSTHOG_PUBLIC_KEY, POSTHOG_HOST } from '../lib/constants.js';
|
|
4
|
+
import { sanitizeFlags } from '../lib/utils/sanitize-flags.js';
|
|
5
|
+
// Create a singleton client using module scope
|
|
6
|
+
let client = null;
|
|
7
|
+
/**
|
|
8
|
+
* Initialize and get the PostHog client
|
|
9
|
+
* @param debug Whether to log debug information
|
|
10
|
+
* @returns The PostHog client
|
|
11
|
+
*/
|
|
12
|
+
export function getClient(debug = false) {
|
|
13
|
+
if (debug)
|
|
14
|
+
ux.stdout('Initializing PostHog client...');
|
|
15
|
+
if (!client) {
|
|
16
|
+
client = new PostHog(POSTHOG_PUBLIC_KEY, {
|
|
17
|
+
host: POSTHOG_HOST,
|
|
18
|
+
disableGeoip: false,
|
|
19
|
+
});
|
|
20
|
+
// Add error handling
|
|
21
|
+
client.on('error', err => {
|
|
22
|
+
ux.warn(`PostHog Error: ${err}`);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (debug)
|
|
26
|
+
ux.stdout('PostHog client initialized successfully');
|
|
27
|
+
return client;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Shutdown the PostHog client
|
|
31
|
+
* @param debug Whether to log debug information
|
|
32
|
+
* @returns void
|
|
33
|
+
*/
|
|
34
|
+
export async function shutdown(debug = false) {
|
|
35
|
+
if (debug)
|
|
36
|
+
ux.stdout('Shutting down PostHog client...');
|
|
37
|
+
if (!client)
|
|
38
|
+
return;
|
|
39
|
+
try {
|
|
40
|
+
await client.shutdown();
|
|
41
|
+
client = null;
|
|
42
|
+
if (debug)
|
|
43
|
+
ux.stdout('PostHog client shut down successfully');
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
ux.warn(`Error shutting down PostHog client: ${error}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Track an event in PostHog
|
|
51
|
+
* @param options The tracking options
|
|
52
|
+
* @param options.lifecycle The lifecycle event to track ('start', 'complete', 'error')
|
|
53
|
+
* @param options.distinctId The distinct ID for the user
|
|
54
|
+
* @param options.command Optional command name (for command tracking)
|
|
55
|
+
* @param options.flags Optional command flags
|
|
56
|
+
* @param options.runId Optional run ID
|
|
57
|
+
* @param options.config Optional config object
|
|
58
|
+
* @param options.properties Optional additional properties to track
|
|
59
|
+
* @param options.debug Whether to log debug information
|
|
60
|
+
*/
|
|
61
|
+
export function track({ lifecycle, distinctId, command, flags, runId, message, config, properties = {}, debug = false }) {
|
|
62
|
+
if (debug)
|
|
63
|
+
ux.stdout('Tracking event...');
|
|
64
|
+
const phClient = getClient(debug);
|
|
65
|
+
const eventProperties = command
|
|
66
|
+
? {
|
|
67
|
+
runId,
|
|
68
|
+
message,
|
|
69
|
+
...properties,
|
|
70
|
+
...getEnvironmentInfo(config),
|
|
71
|
+
// Always sanitize sensitive flags
|
|
72
|
+
...sanitizeFlags(flags),
|
|
73
|
+
}
|
|
74
|
+
: properties;
|
|
75
|
+
if (debug) {
|
|
76
|
+
ux.stdout('Capturing event...');
|
|
77
|
+
ux.stdout(JSON.stringify(eventProperties));
|
|
78
|
+
}
|
|
79
|
+
phClient.capture({
|
|
80
|
+
distinctId,
|
|
81
|
+
event: `directus_template_cli.${command}.${lifecycle}`,
|
|
82
|
+
properties: eventProperties
|
|
83
|
+
});
|
|
84
|
+
if (debug)
|
|
85
|
+
ux.stdout('Event tracked successfully');
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get environment info
|
|
89
|
+
* @param config The config to get environment info from
|
|
90
|
+
* @returns The environment info
|
|
91
|
+
*/
|
|
92
|
+
function getEnvironmentInfo(config) {
|
|
93
|
+
return {
|
|
94
|
+
// PostHog properties
|
|
95
|
+
$os: process.platform,
|
|
96
|
+
$raw_user_agent: config?.userAgent || 'unknown',
|
|
97
|
+
// Custom properties
|
|
98
|
+
arch: process.arch || 'unknown',
|
|
99
|
+
nodeVersion: process.version,
|
|
100
|
+
platform: config?.platform || 'unknown',
|
|
101
|
+
shell: config?.shell || 'unknown',
|
|
102
|
+
version: config?.version || 'unknown',
|
|
103
|
+
};
|
|
104
|
+
}
|
package/oclif.manifest.json
CHANGED
|
@@ -176,6 +176,25 @@
|
|
|
176
176
|
"apply.js"
|
|
177
177
|
]
|
|
178
178
|
},
|
|
179
|
+
"base": {
|
|
180
|
+
"aliases": [],
|
|
181
|
+
"args": {},
|
|
182
|
+
"flags": {},
|
|
183
|
+
"hasDynamicHelp": false,
|
|
184
|
+
"hiddenAliases": [],
|
|
185
|
+
"id": "base",
|
|
186
|
+
"pluginAlias": "directus-template-cli",
|
|
187
|
+
"pluginName": "directus-template-cli",
|
|
188
|
+
"pluginType": "core",
|
|
189
|
+
"strict": true,
|
|
190
|
+
"enableJsonFlag": false,
|
|
191
|
+
"isESM": true,
|
|
192
|
+
"relativePath": [
|
|
193
|
+
"dist",
|
|
194
|
+
"commands",
|
|
195
|
+
"base.js"
|
|
196
|
+
]
|
|
197
|
+
},
|
|
179
198
|
"extract": {
|
|
180
199
|
"aliases": [],
|
|
181
200
|
"args": {},
|
|
@@ -293,8 +312,8 @@
|
|
|
293
312
|
"examples": [
|
|
294
313
|
"$ directus-template-cli init",
|
|
295
314
|
"$ directus-template-cli init my-project",
|
|
296
|
-
"$ directus-template-cli init --frontend=nextjs --template=simple-cms
|
|
297
|
-
"$ directus-template-cli init my-project --frontend=nextjs --template=simple-cms
|
|
315
|
+
"$ directus-template-cli init --frontend=nextjs --template=simple-cms",
|
|
316
|
+
"$ directus-template-cli init my-project --frontend=nextjs --template=simple-cms"
|
|
298
317
|
],
|
|
299
318
|
"flags": {
|
|
300
319
|
"frontend": {
|
|
@@ -328,19 +347,19 @@
|
|
|
328
347
|
"allowNo": false,
|
|
329
348
|
"type": "boolean"
|
|
330
349
|
},
|
|
331
|
-
"programmatic": {
|
|
332
|
-
"char": "p",
|
|
333
|
-
"description": "Run in programmatic mode (non-interactive)",
|
|
334
|
-
"name": "programmatic",
|
|
335
|
-
"allowNo": false,
|
|
336
|
-
"type": "boolean"
|
|
337
|
-
},
|
|
338
350
|
"template": {
|
|
339
351
|
"description": "Template name (e.g., simple-cms) or GitHub URL (e.g., https://github.com/directus-labs/starters/tree/main/simple-cms)",
|
|
340
352
|
"name": "template",
|
|
341
353
|
"hasDynamicHelp": false,
|
|
342
354
|
"multiple": false,
|
|
343
355
|
"type": "option"
|
|
356
|
+
},
|
|
357
|
+
"disableTelemetry": {
|
|
358
|
+
"description": "Disable telemetry",
|
|
359
|
+
"env": "DISABLE_TELEMETRY",
|
|
360
|
+
"name": "disableTelemetry",
|
|
361
|
+
"allowNo": false,
|
|
362
|
+
"type": "boolean"
|
|
344
363
|
}
|
|
345
364
|
},
|
|
346
365
|
"hasDynamicHelp": false,
|
|
@@ -359,5 +378,5 @@
|
|
|
359
378
|
]
|
|
360
379
|
}
|
|
361
380
|
},
|
|
362
|
-
"version": "0.7.0-beta.
|
|
381
|
+
"version": "0.7.0-beta.7"
|
|
363
382
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "directus-template-cli",
|
|
3
|
-
"version": "0.7.0-beta.
|
|
3
|
+
"version": "0.7.0-beta.7",
|
|
4
4
|
"description": "CLI Utility for applying templates to a Directus instance.",
|
|
5
5
|
"author": "bryantgillespie @bryantgillespie",
|
|
6
6
|
"type": "module",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"posthog-node": "^4.10.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@oclif/prettier-config": "^0.2.1",
|
|
45
44
|
"@directus/types": "^13.0.0",
|
|
45
|
+
"@oclif/prettier-config": "^0.2.1",
|
|
46
46
|
"@oclif/test": "^4",
|
|
47
47
|
"@types/chai": "^5.2.0",
|
|
48
48
|
"@types/mocha": "^10",
|
|
@@ -68,7 +68,8 @@
|
|
|
68
68
|
"@oclif/plugin-plugins"
|
|
69
69
|
],
|
|
70
70
|
"topicSeparator": " ",
|
|
71
|
-
"topics": {}
|
|
71
|
+
"topics": {},
|
|
72
|
+
"hooks": {}
|
|
72
73
|
},
|
|
73
74
|
"scripts": {
|
|
74
75
|
"build": "shx rm -rf dist && tsc -b",
|
package/bin/dev
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
const oclif = require('@oclif/core')
|
|
3
|
-
|
|
4
|
-
const path = require('node:path')
|
|
5
|
-
const project = path.join(__dirname, '..', 'tsconfig.json')
|
|
6
|
-
|
|
7
|
-
// In dev mode -> use ts-node and dev plugins
|
|
8
|
-
process.env.NODE_ENV = 'development'
|
|
9
|
-
|
|
10
|
-
require('ts-node').register({project})
|
|
11
|
-
|
|
12
|
-
// In dev mode, always show stack traces
|
|
13
|
-
oclif.settings.debug = true
|
|
14
|
-
|
|
15
|
-
// Start the CLI
|
|
16
|
-
oclif.run().then(oclif.flush).catch(oclif.Errors.handle)
|
package/bin/run
DELETED
package/dist/lib/init.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { init } from './init/index.js';
|
package/dist/lib/init.js
DELETED