import { existsSync } from "fs"; import { resolve, join } from "path"; export const rootPath = resolve(process.cwd()); declare const __webpack_require__; declare const __non_webpack_require__; export const requireFx = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require; export const getPaths = (userPaths = {}) => ({ src: join(rootPath, "./src"), entry: { main: join(rootPath, "./src/index") }, outputFolder: join(rootPath, "./dist"), ...userPaths }); export const resolveHtmlTemplate = () => { const srcHtmlPath = resolve(rootPath, "./src/index.html"); const assetsHtmlPath = resolve(rootPath, "./assets/index.html"); const rootHtmlPath = resolve(rootPath, "./index.html"); if (existsSync(srcHtmlPath)) { return srcHtmlPath; } if (existsSync(assetsHtmlPath)) { return assetsHtmlPath; } if (existsSync(rootHtmlPath)) { return rootHtmlPath; } }; export const makeDevEntry = (entry, port) => { return [ require.resolve("webpack-dev-server/client") + `?http://localhost:${port}`, require.resolve("webpack/hot/dev-server"), entry ]; }; export const makeDevEntries = (entries, port) => { Object.keys(entries).forEach(entryKey => { const entry = entries[entryKey]; entries[entryKey] = makeDevEntry(entry, port); }); return entries; }; export const isBackEndConfig = mode => mode === "node"; export const resolveLocal = (...args) => { return join(__dirname, "../../", ...args); }; export const resolveContext = (context, path) => { return resolve(context, path); }; export const getFile = relativePath => { const filepath = join(rootPath, relativePath); if (existsSync(filepath)) { return requireFx(filepath); } }; export const getUserConfig = () => { const userConfigPath = join(rootPath, "./typepack.ts"); if (existsSync(userConfigPath)) { return requireFx(userConfigPath); } return {}; };