Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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({
stdio: 'inherit',
};
const tasks = [
'yarn format:diff',
'yarn lint --quiet',
'yarn lint:docs',
`yarn bundler check --ignore '**/@(node_modules|examples|components|react|fixtures)/**' 'packages/**/*.scss'`,
`cross-env BABEL_ENV=test yarn test --ci --maxWorkers 2 --reporters=default --reporters=jest-junit`,
`cross-env BABEL_ENV=test yarn test:e2e --ci --maxWorkers 2 --reporters=default --reporters=jest-junit`,
];
try {
for (const task of tasks) {
const now = Date.now();
reporter.info(`Running: ${task}`);
await exec(task, options);
reporter.success(`Done in: ${Date.now() - now}ms`);
}
} catch (error) {
console.log(error.stdout);
console.log(error.stderr);
console.log(error);
process.exit(1);
}
}
}
return acc;
}, []);
if (errors.length > 0) {
errors.forEach(error => {
const { formatted, file } = error;
reporter.error(`Error compiling ${path.relative(cwd, file)}`);
console.log(chalk.gray(formatted));
});
process.exit(1);
return;
}
if (list) {
reporter.info('Compiled the following files:');
console.log(files);
}
reporter.success(`Successfully compiled ${files.length} files! 🎉`);
process.exit(0);
}
async function build({ cwd }) {
reporter.info(`Building components for ${meta.length} icons...`);
const ESM_DIR = path.join(cwd, 'es');
const BUNDLE_FORMATS = [
{
format: 'cjs',
directory: 'lib',
},
{
format: 'umd',
directory: 'umd',
},
];
reporter.info('Building ESM and bundle sources...');
await Promise.all(
meta.map(async info => {
const source = createModuleFromInfo(info);
};
if (format === 'umd') {
outputOptions.name = info.moduleName;
outputOptions.globals = {
'@carbon/icon-helpers': 'CarbonIconHelpers',
'prop-types': 'PropTypes',
react: 'React',
};
}
await bundle.write(outputOptions);
})
);
})
);
reporter.info('Generating Storybook stories...');
await fs.remove(STORYBOOK_DIR);
await fs.ensureDir(STORYBOOK_DIR);
await Promise.all(
meta.map(info => {
const { moduleName } = info;
const outputPath = path.join(STORYBOOK_DIR, `${moduleName}-story.js`);
return fs.writeFile(outputPath, createIconStory(info));
})
);
reporter.success('Done! 🎉');
}
async function build() {
reporter.info('Building scss files for themes...');
const METADATA_FILE = path.resolve(__dirname, '../metadata.yml');
const metadata = transformMetadata(
yaml.safeLoad(fs.readFileSync(METADATA_FILE, 'utf8'))
);
const SCSS_DIR = path.resolve(__dirname, '../scss/generated');
const files = [
{
filepath: path.join(SCSS_DIR, '_tokens.scss'),
builder() {
return buildTokensFile(tokens, metadata, themes[defaultTheme]);
},
},
{
filepath: path.join(SCSS_DIR, '_themes.scss'),
format,
file: jsFilepath.replace(/\/es\//, `/${directory}/`),
};
if (format === 'umd') {
outputOptions.name = info.moduleName;
outputOptions.globals = {
'@carbon/icon-helpers': 'CarbonIconHelpers',
};
}
await bundle.write(outputOptions);
})
);
})
);
reporter.info('Building ESM and bundle entrypoints...');
const entrypoint = `export const CarbonIconsVue = {
install(Vue, options) {
const { components } = options;
Object.keys(components).forEach(key => {
Vue.component(key, components[key]);
});
},
}`;
const entrypointPath = path.join(ESM_DIR, 'index.js');
await fs.ensureDir(ESM_DIR);
await fs.writeFile(entrypointPath, entrypoint);
await Promise.all(
BUNDLE_FORMATS.map(async ({ format, directory }) => {
const bundle = await rollup({
const BUNDLE_FORMATS = [
{
format: 'esm',
directory: 'es',
},
{
format: 'cjs',
directory: 'lib',
},
{
format: 'umd',
directory: 'umd',
},
];
reporter.info('Building ESM and bundle sources...');
await Promise.all(
meta.map(async info => {
const source = createModuleFromInfo(info);
const jsFilepath = path.join(cwd, info.outputOptions.file);
const bundle = await rollup({
input: '__entrypoint__',
external: ['@carbon/icon-helpers', 'prop-types', 'react'],
plugins: [
virtual({
__entrypoint__: source,
}),
],
});
await Promise.all(