mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add directus-extension CLI to extension-sdk (#6548)
* Remove return from api cli entrypoint * Add directus-extension cli to extension-sdk The initial version only implements the "build" command. Executing "build" in the root of an extension package bundles the extension to a single distributable and loadable entrypoint. * Update extension docs to use directus-extension build
This commit is contained in:
committed by
GitHub
parent
043ae13e40
commit
7f60fb0fc1
2
packages/extension-sdk/cli.js
Executable file
2
packages/extension-sdk/cli.js
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env node
|
||||
require('./dist/cjs/cli/index.js');
|
||||
@@ -7,6 +7,9 @@
|
||||
"import": "./dist/esm/index.js",
|
||||
"require": "./dist/cjs/index.js"
|
||||
},
|
||||
"bin": {
|
||||
"directus-extension": "cli.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run cleanup && run-p build:*",
|
||||
"build:esm": "tsc --project ./tsconfig.json --module ES2015 --outDir ./dist/esm",
|
||||
@@ -18,7 +21,15 @@
|
||||
"author": "Nicola Krumschmidt",
|
||||
"gitHead": "24621f3934dc77eb23441331040ed13c676ceffd",
|
||||
"dependencies": {
|
||||
"@directus/shared": "9.0.0-rc.81"
|
||||
"@directus/shared": "9.0.0-rc.81",
|
||||
"@rollup/plugin-commonjs": "^19.0.0",
|
||||
"@rollup/plugin-node-resolve": "^13.0.0",
|
||||
"@vue/compiler-sfc": "^3.1.1",
|
||||
"commander": "^8.0.0",
|
||||
"ora": "^5.4.0",
|
||||
"rollup": "^2.51.2",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"rollup-plugin-vue": "^6.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"npm-run-all": "4.1.5",
|
||||
|
||||
28
packages/extension-sdk/src/cli/commands/build.ts
Normal file
28
packages/extension-sdk/src/cli/commands/build.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
/* eslint-disable no-console */
|
||||
|
||||
import ora from 'ora';
|
||||
import { rollup } from 'rollup';
|
||||
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
import { terser } from 'rollup-plugin-terser';
|
||||
import vue from 'rollup-plugin-vue';
|
||||
import { SHARED_DEPS } from '@directus/shared/constants';
|
||||
|
||||
export default async function build(options: { input: string; output: string }): Promise<void> {
|
||||
const spinner = ora('Building Directus extension...').start();
|
||||
|
||||
const bundle = await rollup({
|
||||
input: options.input,
|
||||
external: SHARED_DEPS,
|
||||
plugins: [vue(), nodeResolve(), commonjs(), terser()],
|
||||
});
|
||||
|
||||
await bundle.write({
|
||||
format: 'es',
|
||||
file: options.output,
|
||||
});
|
||||
|
||||
await bundle.close();
|
||||
|
||||
spinner.succeed('Done');
|
||||
}
|
||||
18
packages/extension-sdk/src/cli/index.ts
Normal file
18
packages/extension-sdk/src/cli/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Command } from 'commander';
|
||||
import build from './commands/build';
|
||||
|
||||
const pkg = require('../../../package.json');
|
||||
|
||||
const program = new Command();
|
||||
|
||||
program.name('directus-extension').usage('[command] [options]');
|
||||
program.version(pkg.version, '-v, --version');
|
||||
|
||||
program
|
||||
.command('build')
|
||||
.description('Bundle a Directus extension to a single entrypoint')
|
||||
.option('-i, --input <file>', 'change the default entrypoint', 'src/index.js')
|
||||
.option('-o, --output <file>', 'change the default output file', 'dist/index.js')
|
||||
.action(build);
|
||||
|
||||
program.parse(process.argv);
|
||||
Reference in New Issue
Block a user