mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[dev] share sass build with script (#34323)
This commit is contained in:
parent
8290b56f70
commit
6703848f92
6 changed files with 154 additions and 27 deletions
21
scripts/build_sass.js
Normal file
21
scripts/build_sass.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
require('../src/setup_node_env');
|
||||
require('../src/dev/sass/run_build_sass_cli');
|
|
@ -17,34 +17,14 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { toArray } from 'rxjs/operators';
|
||||
import { buildAll } from '../../../legacy/server/sass/build_all';
|
||||
import { findPluginSpecs } from '../../../legacy/plugin_discovery/find_plugin_specs';
|
||||
import { collectUiExports } from '../../../legacy/ui/ui_exports/collect_ui_exports';
|
||||
import { buildSass } from '../../sass';
|
||||
|
||||
export const TranspileScssTask = {
|
||||
description: 'Transpiling SCSS to CSS',
|
||||
|
||||
async run(config, log, build) {
|
||||
const scanDirs = [ build.resolvePath('src/legacy/core_plugins') ];
|
||||
const paths = [ build.resolvePath('node_modules/x-pack') ];
|
||||
|
||||
const { spec$ } = findPluginSpecs({ plugins: { scanDirs, paths } });
|
||||
const enabledPlugins = await spec$.pipe(toArray()).toPromise();
|
||||
const uiExports = collectUiExports(enabledPlugins);
|
||||
|
||||
try {
|
||||
const bundles = await buildAll({
|
||||
styleSheets: uiExports.styleSheetPaths,
|
||||
log,
|
||||
buildDir: build.resolvePath('built_assets/css'),
|
||||
outputStyle: 'compressed',
|
||||
sourceMap: false
|
||||
});
|
||||
bundles.forEach(bundle => log.info(`Compiled SCSS: ${bundle.sourcePath} (theme=${bundle.theme})`));
|
||||
} catch (error) {
|
||||
const { message, line, file } = error;
|
||||
throw new Error(`${message} on line ${line} of ${file}`);
|
||||
}
|
||||
await buildSass({
|
||||
log,
|
||||
kibanaDir: build.resolvePath('.')
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -97,6 +97,5 @@ export function getHelp(options: Options) {
|
|||
.join('\n ')}
|
||||
|
||||
Options:
|
||||
${optionHelp}
|
||||
`;
|
||||
${optionHelp + '\n\n'}`;
|
||||
}
|
||||
|
|
67
src/dev/sass/build_sass.js
Normal file
67
src/dev/sass/build_sass.js
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* 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 { resolve } from 'path';
|
||||
|
||||
import { toArray } from 'rxjs/operators';
|
||||
|
||||
import { createFailError } from '../run';
|
||||
import { findPluginSpecs } from '../../legacy/plugin_discovery';
|
||||
import { collectUiExports } from '../../legacy/ui';
|
||||
import { buildAll } from '../../legacy/server/sass/build_all';
|
||||
|
||||
export async function buildSass({ log, kibanaDir }) {
|
||||
log.info('running plugin discovery in', kibanaDir);
|
||||
|
||||
const scanDirs = [
|
||||
resolve(kibanaDir, 'src/legacy/core_plugins')
|
||||
];
|
||||
|
||||
const paths = [
|
||||
resolve(kibanaDir, 'x-pack'),
|
||||
resolve(kibanaDir, 'node_modules/x-pack')
|
||||
];
|
||||
|
||||
const { spec$ } = findPluginSpecs({ plugins: { scanDirs, paths } });
|
||||
const enabledPlugins = await spec$.pipe(toArray()).toPromise();
|
||||
const uiExports = collectUiExports(enabledPlugins);
|
||||
log.info('found %d styleSheetPaths', uiExports.styleSheetPaths.length);
|
||||
log.verbose(uiExports.styleSheetPaths);
|
||||
|
||||
let bundleCount = 0;
|
||||
try {
|
||||
const bundles = await buildAll({
|
||||
styleSheets: uiExports.styleSheetPaths,
|
||||
log,
|
||||
buildDir: resolve(kibanaDir, 'built_assets/css'),
|
||||
sourceMap: true
|
||||
});
|
||||
|
||||
bundles.forEach(bundle => {
|
||||
log.debug(`Compiled SCSS: ${bundle.sourcePath} (theme=${bundle.theme})`);
|
||||
});
|
||||
|
||||
bundleCount = bundles.length;
|
||||
} catch (error) {
|
||||
const { message, line, file } = error;
|
||||
throw createFailError(`${message} on line ${line} of ${file}`);
|
||||
}
|
||||
|
||||
log.success('%d scss bundles created', bundleCount);
|
||||
}
|
20
src/dev/sass/index.js
Normal file
20
src/dev/sass/index.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export { buildSass } from './build_sass';
|
40
src/dev/sass/run_build_sass_cli.js
Normal file
40
src/dev/sass/run_build_sass_cli.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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 { run } from '../run';
|
||||
import { REPO_ROOT } from '../constants';
|
||||
import { buildSass } from './build_sass';
|
||||
|
||||
run(async ({ log, flags: { kibanaDir } }) => {
|
||||
await buildSass({
|
||||
log,
|
||||
kibanaDir
|
||||
});
|
||||
}, {
|
||||
description: 'Simple CLI, useful for building scss files outside of the server',
|
||||
flags: {
|
||||
default: {
|
||||
kibanaDir: REPO_ROOT
|
||||
},
|
||||
string: ['kibanaDir'],
|
||||
help: `
|
||||
--kibanaDir The root of the Kibana directory to build sass files in.
|
||||
`
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue