Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const main = async (pattern: string, options: MainOptions) => {
// When the provided pattern is a directory construct the proper glob to find
// all .scss files within that directory. Also, add the directory to the
// included paths so any imported with a path relative to the root of the
// project still works as expected without adding many include paths.
if (fs.existsSync(pattern) && fs.lstatSync(pattern).isDirectory()) {
if (Array.isArray(options.includePaths)) {
options.includePaths.push(pattern);
} else {
options.includePaths = [pattern];
}
// When the pattern provide is a directory, assume all .scss files within.
pattern = slash(path.resolve(pattern, "**/*.scss"));
}
if (options.listDifferent) {
listDifferent(pattern, options);
return;
}
if (options.watch) {
watch(pattern, options);
} else {
await generate(pattern, options);
}
};
if (!util.isCompilableExtension(relative, cliOptions.extensions)) {
return false;
}
// remove extension and then append back on .js
relative = util.adjustRelative(relative, cliOptions.keepFileExtension);
const dest = getDest(relative, base);
try {
const res = await util.compile(
src,
defaults(
{
sourceFileName: slash(path.relative(dest + "/..", src)),
},
babelOptions,
),
);
if (!res) return false;
// we've requested explicit sourcemaps to be written to disk
if (
res.map &&
babelOptions.sourceMaps &&
babelOptions.sourceMaps !== "inline"
) {
const mapLoc = dest + ".map";
res.code = util.addSourceMappingUrl(res.code, mapLoc);
res.map.file = path.basename(relative);
export default function isAllowed(fileName) {
if (typeof fileName !== 'string') {
return false;
}
const normalizedFileName = slash(fileName);
if (
(new RegExp('/components/(.*)/style.js')).test(normalizedFileName)
|| (
(new RegExp('/components/(.*)/style.css')).test(normalizedFileName)
&& !(new RegExp('/components/(.*)/src/(.*)style.css')).test(normalizedFileName)
)
) {
return false;
}
const ext = path.extname(normalizedFileName);
switch (ext) {
case '.js':
case '.jsx':
const moduleRes = `${slash(filePath)}`.match(moduleExp);
if (Array.isArray(moduleRes)) {
const fragments = `${slash(context)}`.split(`${moduleRes[1]}/install/js/${moduleRes[2]}/`);
return `${moduleRes[2]}.${fragments[fragments.length - 1].replace(/\/$/, '').split('/').join('.')}`;
}
const localExp = new RegExp('/local/js/(.[a-z0-9_-]+)/(.[a-z0-9_-]+)/');
const localRes = `${slash(filePath)}`.match(localExp);
if (!Array.isArray(localRes))
{
return path.basename(context);
}
const fragments = `${slash(context)}`.split(`/local/js/${localRes[1]}/`);
return `${localRes[1]}.${fragments[fragments.length - 1].replace(/\/$/, '').split('/').join('.')}`;
}
export default function buildComponentName(filePath) {
const normalizedPath = `${slash(filePath)}`;
const regExp = new RegExp('/(.[a-z0-9]+)/install/components/(.[a-z0-9]+)/');
const res = normalizedPath.match(regExp);
if (res)
{
return `${res[2]}:${normalizedPath.split(res[0])[1].split('/')[0]}`;
}
const localExp = new RegExp('/local/components/(.[a-z0-9]+)/');
const localRes = normalizedPath.match(localExp);
return `${localRes[1]}:${normalizedPath.split(localRes[0])[1].split('/')[0]}`;
}
export default function parseSiteTemplatePath(sourcePath: string = ''): ?Result {
const preparedPath = slash(sourcePath);
const installTemplatesExp = new RegExp('/(.[a-z0-9_-]+)/modules/.[a-z0-9_-]+/install/templates/(.[a-z0-9_-]+)/');
const productTemplatesExp = new RegExp('/(local|bitrix)/templates/((.[a-z0-9-_]+))/');
const templateResult = (
preparedPath.match(installTemplatesExp)
|| preparedPath.match(productTemplatesExp)
);
if (
!!templateResult
&& !!templateResult[1]
&& !!templateResult[2]
) {
const [templatePath, rootDirname, template] = templateResult;
const root = ['bitrix', 'local'].includes(rootDirname) ? rootDirname : 'bitrix';
const [, filePath] = preparedPath.split(path.join(templatePath));
private getRelativeUnixPath = mem((absPath: string) => slash(relative(this.appRoot, absPath)))
(
acc,
{
package: pack,
path: packPath = COMPONENTS_DIRNAME,
transform,
fileName
}
) => {
let peerComponent = getPeerFilename(component, {
transform,
template: fileName
})
let peerPath = slash(path.join(pack, packPath, peerComponent))
pushPart(acc, { path: peerPath })
return acc
},
{
function generateConfigPhp(config) {
if (!!config && typeof config !== 'object') {
throw new Error('Invalid config');
}
const templatePath = path.resolve(appRoot, 'src/templates/config.php');
const template = fs.readFileSync(templatePath, 'utf-8');
const outputPath = path.resolve(slash(config.context), slash(config.output.js));
const data = {
cssPath: slash(path.relative(slash(config.context), buildConfigBundlePath(outputPath, 'css'))),
jsPath: slash(path.relative(slash(config.context), buildConfigBundlePath(outputPath, 'js'))),
rel: renderRel(config.rel),
};
return mustache.render(template, data);
}
const onFileChange = async (eventType, filePath0) => {
const filePath = slash(filePath0);
if (eventType === 'unlink') {
onSrcFileDeleted(filePath, { save: true });
} else if (eventType === 'add') {
onSrcFileAdded(filePath, { save: true });
} else if (eventType === 'change') {
await onSrcFileDeleted(filePath, { save: false });
onSrcFileAdded(filePath, { save: true, forceSave: true });
}
};