MCPcopy
hub / github.com/directus/directus / add

Function add

packages/extensions-sdk/src/cli/commands/add.ts:27–309  ·  view source on GitHub ↗
(options: AddOptions)

Source from the content-addressed store, hash-verified

25type AddOptions = { install?: boolean };
26
27export default async function add(options: AddOptions): Promise<void> {
28 const install = options.install ?? true;
29 const extensionPath = process.cwd();
30 const packagePath = path.resolve('package.json');
31
32 if (!(await fse.pathExists(packagePath))) {
33 log(`Current directory is not a valid Directus extension:`, 'error');
34 log(`Missing "package.json" file.`, 'error');
35 process.exit(1);
36 }
37
38 let extensionManifestFile: string;
39
40 try {
41 extensionManifestFile = (await fse.readFile(packagePath, 'utf8')) as string;
42 } catch {
43 log(`Failed to read "package.json" file from current directory.`, 'error');
44 process.exit(1);
45 }
46
47 let extensionManifest: TExtensionManifest;
48
49 try {
50 extensionManifest = JSON.parse(extensionManifestFile);
51 ExtensionManifest.parse(extensionManifest);
52 } catch {
53 log(`Current directory is not a valid Directus extension:`, 'error');
54 log(`Invalid "package.json" file.`, 'error');
55
56 process.exit(1);
57 }
58
59 const indent = detectJsonIndent(extensionManifestFile);
60
61 const extensionOptions = extensionManifest[EXTENSION_PKG_KEY];
62
63 const sourceExists = await fse.pathExists(path.resolve('src'));
64
65 if (extensionOptions.type === 'bundle') {
66 const { type, name, language, alternativeSource } = await inquirer.prompt<{
67 type: NestedExtensionType;
68 name: string;
69 language: Language;
70 alternativeSource?: string;
71 }>([
72 {
73 type: 'list',
74 name: 'type',
75 message: 'Choose the extension type',
76 choices: () => EXTENSION_TYPES.filter((e) => e !== 'bundle'),
77 },
78 {
79 type: 'input',
80 name: 'name',
81 message: 'Choose a name for the entry',
82 validate: (name: string) => (name.length === 0 ? 'Entry name can not be empty.' : true),
83 },
84 {

Callers

nothing calls this directly

Calls 15

isInFunction · 0.90
pathToRelativeUrlFunction · 0.90
isTypeInFunction · 0.90
detectJsonIndentFunction · 0.85
copyTemplateFunction · 0.85
languageToShortFunction · 0.85
getExtensionDevDepsFunction · 0.85
getLanguageFromEntriesFunction · 0.85
getPackageManagerFunction · 0.85
toConvertSourceUrlFunction · 0.85
resolveMethod · 0.80
ensureDirMethod · 0.80

Tested by

no test coverage detected