Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
const { ConsoleReporter } = require('@carbon/cli-reporter');
const { logger } = require('@carbon/cli-tools');
const packageJson = require('../package.json');
// Initialize our reporter for the console. Used for logging messages
const reporter = new ConsoleReporter();
/**
* @typedef Option
* @param {string} flags - specify the flags for the option
* @param {string} description - the description to show for the option
* @param {any} defaults - the default value for the option
*/
/**
* @typedef Command
* @param {string} name - the name of the command
* @param {string} description - the description to show for the command
* @param {Option[]} options - available options for the command
* @param {Function} action - the function to call when the command is run
*/
async function check(pattern, { ignore, cwd, list } = {}) {
reporter.info(`Running in: ${cwd}`);
reporter.info(`Checking pattern: '${pattern}', ignoring: '${ignore}'`);
// Assume globs are for checking scss files for now
const files = await glob(pattern, {
cwd,
ignore,
});
reporter.info(`Compiling ${files.length} files...`);
const results = await Promise.all(
compile(files.map(file => path.join(cwd, file)))
);
const errors = results.reduce((acc, result) => {
if (result.error) {
const error = result.error;
async function main() {
reporter.info('Building examples...');
await fs.remove(BUILD_DIR);
await fs.ensureDir(BUILD_DIR);
const packageNames = await fs.readdir(PACKAGES_DIR);
const packages = await Promise.all(
packageNames
.filter(name => PACKAGES_TO_BUILD.has(name))
.map(async name => {
// Verify that each file that we read from the packages directory is
// actually a folder. Typically used to catch `.DS_store` files that
// accidentally appear when opening with MacOS Finder
const filepath = path.join(PACKAGES_DIR, name);
const stat = await fs.lstat(filepath);
const descriptor = {
),
],
});
await Promise.all(
BUNDLE_FORMATS.map(({ directory, format }) => {
return bundle.write({
dir: directory,
format,
// We already specify `.js` in the `filepath` used in `input` above
entryFileNames: '[name]',
});
})
);
reporter.info('Building module entrypoints...');
let entrypoint = `/**
* Copyright IBM Corp. 2019, 2019
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
`;
for (const file of files) {
const { moduleName, descriptor } = file;
const value = JSON.stringify(descriptor);
entrypoint += `\nexport const ${moduleName} = ${value}`;
}
const entrypointBundle = await rollup({
async function build() {
reporter.log('Cleaning build dirs...');
try {
await clean();
await Promise.all([fs.mkdir(paths.STORIES), fs.mkdir(paths.TS)]);
} catch (err) {
reporter.error(err);
}
reporter.log('Generating source components...');
await generateComponents();
reporter.log('Compiling and generating modules...');
// run the angular compiler over everything
ngc.main(['-p', './config/tsconfig-aot.json']);
reporter.log('Bundling...');
await buildUMD();
// build the storybook examples
reporter.log('Generating storybook examples...');
buildExamples();
}
.replace('es', 'ts')
.replace('.js', '.ts');
// try to write out the component
try {
await fs.ensureDir(dirname(outputPath));
await fs.writeFile(
outputPath,
componentTemplate(
selectorName,
className,
rawSvg,
icon.descriptor.attrs
)
);
} catch (err) {
reporter.error(err);
}
}
}
async function build() {
reporter.log('Cleaning build dirs...');
try {
await clean();
await Promise.all([fs.mkdir(paths.STORIES), fs.mkdir(paths.TS)]);
} catch (err) {
reporter.error(err);
}
reporter.log('Generating source components...');
await generateComponents();
reporter.log('Compiling and generating modules...');
// run the angular compiler over everything
ngc.main(['-p', './config/tsconfig-aot.json']);
reporter.log('Bundling...');
await buildUMD();
// build the storybook examples
reporter.log('Generating storybook examples...');
buildExamples();
}
try {
await clean();
await Promise.all([fs.mkdir(paths.STORIES), fs.mkdir(paths.TS)]);
} catch (err) {
reporter.error(err);
}
reporter.log('Generating source components...');
await generateComponents();
reporter.log('Compiling and generating modules...');
// run the angular compiler over everything
ngc.main(['-p', './config/tsconfig-aot.json']);
reporter.log('Bundling...');
await buildUMD();
// build the storybook examples
reporter.log('Generating storybook examples...');
buildExamples();
}
async function build() {
reporter.log('Cleaning build dirs...');
try {
await clean();
await Promise.all([fs.mkdir(paths.STORIES), fs.mkdir(paths.TS)]);
} catch (err) {
reporter.error(err);
}
reporter.log('Generating source components...');
await generateComponents();
reporter.log('Compiling and generating modules...');
// run the angular compiler over everything
ngc.main(['-p', './config/tsconfig-aot.json']);
reporter.log('Bundling...');
await buildUMD();
// build the storybook examples
reporter.log('Generating storybook examples...');
buildExamples();
}
async function build() {
reporter.log('Cleaning build dirs...');
try {
await clean();
await Promise.all([fs.mkdir(paths.STORIES), fs.mkdir(paths.TS)]);
} catch (err) {
reporter.error(err);
}
reporter.log('Generating source components...');
await generateComponents();
reporter.log('Compiling and generating modules...');
// run the angular compiler over everything
ngc.main(['-p', './config/tsconfig-aot.json']);
reporter.log('Bundling...');
await buildUMD();
// build the storybook examples
reporter.log('Generating storybook examples...');
buildExamples();
}