Skip to content

Commit

Permalink
[kbn/plugin-helpers/build] copy the public assets of a plugin (#83458)
Browse files Browse the repository at this point in the history
Co-authored-by: spalger <[email protected]>
  • Loading branch information
Spencer and spalger authored Nov 16, 2020
1 parent 422dd2b commit 859ba3e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/kbn-plugin-helpers/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export function runCli() {

await Tasks.initTargets(context);
await Tasks.optimize(context);
await Tasks.writePublicAssets(context);
await Tasks.writeServerFiles(context);
await Tasks.yarnInstall(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ it('builds a generated plugin into a viable archive', async () => {
│ info initialized, 0 bundles cached
│ info starting worker [1 bundle]
│ succ 1 bundles compiled successfully after <time>
info copying source into the build and converting with babel
info copying assets from \`public/assets\` to build
info copying server source into the build and converting with babel
info running yarn to install dependencies
info compressing plugin into [fooTestPlugin-7.5.0.zip]"
`);
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-plugin-helpers/src/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
export * from './clean';
export * from './create_archive';
export * from './optimize';
export * from './write_public_assets';
export * from './write_server_files';
export * from './yarn_install';
45 changes: 45 additions & 0 deletions packages/kbn-plugin-helpers/src/tasks/write_public_assets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { pipeline } from 'stream';
import { promisify } from 'util';

import vfs from 'vinyl-fs';

import { BuildContext } from '../build_context';

const asyncPipeline = promisify(pipeline);

export async function writePublicAssets({ log, plugin, sourceDir, buildDir }: BuildContext) {
if (!plugin.manifest.ui) {
return;
}

log.info('copying assets from `public/assets` to build');

await asyncPipeline(
vfs.src(['public/assets/**/*'], {
cwd: sourceDir,
base: sourceDir,
buffer: true,
allowEmpty: true,
}),
vfs.dest(buildDir)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function writeServerFiles({
buildDir,
kibanaVersion,
}: BuildContext) {
log.info('copying source into the build and converting with babel');
log.info('copying server source into the build and converting with babel');

// copy source files and apply some babel transformations in the process
await asyncPipeline(
Expand Down

0 comments on commit 859ba3e

Please sign in to comment.