Skip to content

Commit d31c67c

Browse files
Spencerspalger
andauthored
[7.x] [kbn/plugin-helpers/build] copy the public assets of a plugin (#83458) (#83493)
Co-authored-by: spalger <[email protected]> Co-authored-by: spalger <[email protected]>
1 parent f6f1d49 commit d31c67c

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

packages/kbn-plugin-helpers/src/cli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export function runCli() {
9090

9191
await Tasks.initTargets(context);
9292
await Tasks.optimize(context);
93+
await Tasks.writePublicAssets(context);
9394
await Tasks.writeServerFiles(context);
9495
await Tasks.yarnInstall(context);
9596

packages/kbn-plugin-helpers/src/integration_tests/build.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ it('builds a generated plugin into a viable archive', async () => {
7777
│ info initialized, 0 bundles cached
7878
│ info starting worker [1 bundle]
7979
│ succ 1 bundles compiled successfully after <time>
80-
info copying source into the build and converting with babel
80+
info copying assets from \`public/assets\` to build
81+
info copying server source into the build and converting with babel
8182
info running yarn to install dependencies
8283
info compressing plugin into [fooTestPlugin-7.5.0.zip]"
8384
`);

packages/kbn-plugin-helpers/src/tasks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
export * from './clean';
2121
export * from './create_archive';
2222
export * from './optimize';
23+
export * from './write_public_assets';
2324
export * from './write_server_files';
2425
export * from './yarn_install';
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { pipeline } from 'stream';
21+
import { promisify } from 'util';
22+
23+
import vfs from 'vinyl-fs';
24+
25+
import { BuildContext } from '../build_context';
26+
27+
const asyncPipeline = promisify(pipeline);
28+
29+
export async function writePublicAssets({ log, plugin, sourceDir, buildDir }: BuildContext) {
30+
if (!plugin.manifest.ui) {
31+
return;
32+
}
33+
34+
log.info('copying assets from `public/assets` to build');
35+
36+
await asyncPipeline(
37+
vfs.src(['public/assets/**/*'], {
38+
cwd: sourceDir,
39+
base: sourceDir,
40+
buffer: true,
41+
allowEmpty: true,
42+
}),
43+
vfs.dest(buildDir)
44+
);
45+
}

packages/kbn-plugin-helpers/src/tasks/write_server_files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function writeServerFiles({
3535
buildDir,
3636
kibanaVersion,
3737
}: BuildContext) {
38-
log.info('copying source into the build and converting with babel');
38+
log.info('copying server source into the build and converting with babel');
3939

4040
// copy source files and apply some babel transformations in the process
4141
await asyncPipeline(

0 commit comments

Comments
 (0)