Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
subBlocks.map((block: string) => {
const subBlockPath = join(ctx.templateTmpDirPath, block);
debug(`subBlockPath: ${subBlockPath}`);
return new BlockGenerator(args._.slice(2), {
sourcePath: subBlockPath,
path: isPageBlock ? generator.path : join(generator.path, generator.blockFolderName),
// eslint-disable-next-line
blockName: getNameFromPkg(require(join(subBlockPath, 'package.json'))),
isPageBlock: false,
dryRun,
env: {
cwd: api.cwd,
},
routes: api.config.routes,
resolved: winPath(__dirname),
}).run();
}),
);
.map((fileName: string) => {
const status = fs.statSync(join(path, fileName));
// 是文件夹 并且不已 . 开头, 且最深三层
if (status.isDirectory() && fileName.indexOf('.') !== 0 && depth < 3) {
const absPath = winPath(join(path, fileName));
const absPagePath = winPath(join(parentPath, fileName));
const children = getFolderTreeData(absPath, absPagePath, depth + 1);
if (children && children.length > 0) {
return {
key: absPagePath,
title: fileName,
value: absPagePath,
children,
};
}
return { title: fileName, value: absPagePath, key: absPagePath };
}
return undefined;
})
.filter(obj => obj);
export function getConfigFile(cwd) {
const files = process.env.UMI_CONFIG_FILE
? process.env.UMI_CONFIG_FILE.split(',').filter(v => v && v.trim())
: ['.umirc.ts', '.umirc.js', 'config/config.ts', 'config/config.js'];
const validFiles = files.filter(f => existsSync(join(cwd, f)));
assert(
validFiles.length <= 1,
`Multiple config files (${validFiles.join(', ')}) were detected, please keep only one.`,
);
if (validFiles[0]) {
return winPath(join(cwd, validFiles[0]));
}
}
paths.some(path => {
return winPath(file).indexOf(path) > -1;
})
) {
api.modifyRoutes(memo => {
const notFoundRoute = {
component: `
() => React.createElement(require('${winPath(
join(__dirname, 'NotFound.js'),
)}').default, { pagesPath: '${paths.pagesPath}', hasRoutesInConfig: ${!!config.routes} })
`.trim(),
};
const routes = cloneDeep(memo);
function addNotFound(_route) {
if (!_route.routes) {
return;
}
_route.routes.forEach(_r => addNotFound(_r));
_route.routes.push(notFoundRoute);
}
routes.forEach(r => addNotFound(r));
routes.push(notFoundRoute);
const arrayList = getLocaleFileList(absSrcPath, absPagesPath)[locale].map(({ path }) =>
winPath(path),
);
async function generatePublicFile(...arg){
const [ file, absSrcPath, support, collectData,spinner ] = arg;
let _tempData = collectData;
const { name, path } = file;
const dynamicName = getDynamicName(name);
const tempPublicPath = winPath(`${absSrcPath.replace(/src\//,'public/.lang')}`);
const tempFilePath = winPath(`${tempPublicPath}/${name}`);
const ext = getExt(path);
_tempData= {
[dynamicName]:{
...(collectData[dynamicName] || {}),
}
}
if(ext.match(/^(j|t)s$/i)){
await rimraf.sync(tempPublicPath);
const { code } = transformFileSync(path, getBabelConfig());
await writeFile(tempFilePath,code);
delete require.cache[tempFilePath]
const content = await require(tempFilePath).default;
await rimraf.sync(tempPublicPath);
const data = await transLatePublic(content,support,path,spinner);
_tempData[dynamicName] = deepmerge(data,_tempData[dynamicName])
export default function(cwd) {
const winCwd = winPath(cwd);
const absMockPath = winPath(join(winCwd, 'mock'));
const absConfigPath = winPath(join(winCwd, '.umirc.mock.js'));
const absConfigPathWithTS = winPath(join(winCwd, '.umirc.mock.ts'));
return {
absMockPath,
absConfigPath,
absConfigPathWithTS,
};
}
mockFiles = mockFiles.map(p => winPath(p));
importsAhead: importsToStr(
this.service.applyPlugins('addEntryImportAhead', {
initialValue: [],
}),
).join('\n'),
polyfillImports: importsToStr(
this.service.applyPlugins('addEntryPolyfillImports', {
initialValue: [],
}),
).join('\n'),
moduleBeforeRenderer,
render: initialRender,
plugins,
validKeys,
htmlTemplateMap: htmlTemplateMap.join('\n'),
findRoutePath: winPath(require.resolve('./findRoute')),
});
writeContent(paths.absLibraryJSPath, prettierFile(`${entryContent.trim()}\n`));
}