GeezerVison is showing github.com — :construction: better terminal logs · nullstack/nullstack@c90ce81
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +43Lines changed: 43 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | + | | 2 | +const clocks = ['🕛', '🕐', '🕑', '🕒', '🕓', '🕔', '🕕', '🕖', '🕗', '🕘', '🕙', '🕚'] | | 3 | + | | 4 | +function logger(bundle, mode) { | | 5 | + let cindex = 0 | | 6 | + let timer = null | | 7 | + let stoped = false | | 8 | + | | 9 | + function dots() { | | 10 | + return Array((cindex % 3) + 1).fill('.').join('') | | 11 | + } | | 12 | + | | 13 | + function reset() { | | 14 | + if (process.stdout.clearLine) { | | 15 | + process.stdout.clearLine() | | 16 | + process.stdout.cursorTo(0) | | 17 | + } | | 18 | + } | | 19 | + | | 20 | + function start() { | | 21 | + reset() | | 22 | + if (cindex >= clocks.length) { | | 23 | + cindex = 0 | | 24 | + } | | 25 | + let symbol = clocks[cindex] | | 26 | + process.stdout.write(` ${symbol} Building your ${bundle} in ${mode} mode ${dots()}`) | | 27 | + cindex++; | | 28 | + timer = setTimeout(start, 200) | | 29 | + } | | 30 | + start() | | 31 | + | | 32 | + function stop() { | | 33 | + if (stoped) return | | 34 | + clearTimeout(timer) | | 35 | + reset() | | 36 | + process.stdout.write(` ✅ Starting your ${bundle} in ${mode} mode\n`) | | 37 | + stoped = true | | 38 | + } | | 39 | + | | 40 | + return { stop } | | 41 | +} | | 42 | + | | 43 | +module.exports = logger |
Collapse file Copy file name to clipboardExpand all lines: builders/spa.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,7 +34,7 @@ module.exports = async function spa({ output, cache, environment }) { | 34 | 34 | await copy('/robots.txt') | 35 | 35 | console.info() | 36 | 36 |
| 37 | | - console.info('\x1b[36m%s\x1b[0m', ` ✅️ ${projectName} is ready at ${folder}\n`) | | 37 | + console.info('\x1b[36m%s\x1b[0m', ` 🚀 ${projectName} is ready at ${folder}\n`) | 38 | 38 |
| 39 | 39 | if (cache) { | 40 | 40 | console.info('Storing cache...') | |
Collapse file Copy file name to clipboardExpand all lines: builders/ssg.js +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -79,9 +79,8 @@ module.exports = async function ssg({ output, cache, environment }) { | 79 | 79 | const urls = Object.keys(pages).map((p) => { | 80 | 80 | const page = pages[p] | 81 | 81 | const canonical = `https://${application.project.domain}${p}` | 82 | | - return `<url><loc>${canonical}</loc><lastmod>${timestamp}</lastmod>${ | 83 | | - page.changes ? `<changefreq>${page.changes}</changefreq>` : '' | 84 | | - }${page.priority ? `<priority>${page.priority.toFixed(1)}</priority>` : ''}</url>` | | 82 | + return `<url><loc>${canonical}</loc><lastmod>${timestamp}</lastmod>${page.changes ? `<changefreq>${page.changes}</changefreq>` : '' | | 83 | + }${page.priority ? `<priority>${page.priority.toFixed(1)}</priority>` : ''}</url>` | 85 | 84 | }) | 86 | 85 | const xml = `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${urls.join( | 87 | 86 | '', | @@ -111,7 +110,7 @@ module.exports = async function ssg({ output, cache, environment }) { | 111 | 110 | await createSitemap() | 112 | 111 | console.info() | 113 | 112 |
| 114 | | - console.info('\x1b[36m%s\x1b[0m', ` ✅️ ${projectName} is ready at ${folder}\n`) | | 113 | + console.info('\x1b[36m%s\x1b[0m', ` 🚀 ${projectName} is ready at ${folder}\n`) | 115 | 114 |
| 116 | 115 | if (cache) { | 117 | 116 | console.info('Storing cache...') | |
Collapse file Copy file name to clipboardExpand all lines: builders/ssr.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,7 +3,7 @@ module.exports = async function ssr({ cache }) { | 3 | 3 | const application = require(`${dir}/.production/server`).default | 4 | 4 | const projectName = application.project.name || 'The Nullstack application' | 5 | 5 |
| 6 | | - console.info('\x1b[36m%s\x1b[0m', `\n ✅️ ${projectName} is ready for production\n`) | | 6 | + console.info('\x1b[36m%s\x1b[0m', `\n 🚀 ${projectName} is ready for production\n`) | 7 | 7 |
| 8 | 8 | if (cache) { | 9 | 9 | console.info('Storing cache...') | |
Collapse file Copy file name to clipboardExpand all lines: scripts/index.js +5-3Lines changed: 5 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -38,12 +38,12 @@ function clearDir() { | 38 | 38 | } | 39 | 39 |
| 40 | 40 | async function start({ port, name, disk, skipCache, trace }) { | | 41 | + process.env.__NULLSTACK_TRACE = (!!trace).toString() | | 42 | + const progress = require('../builders/logger')('server', 'development') | 41 | 43 | loadEnv(name) | 42 | | - console.info(` 🚀️ Building your application in development mode...`) | 43 | 44 | const environment = 'development' | 44 | 45 | process.env.NULLSTACK_ENVIRONMENT_MODE = 'spa' | 45 | 46 | process.env.NULLSTACK_ENVIRONMENT_DISK = (!!disk).toString() | 46 | | - process.env.__NULLSTACK_TRACE = (!!trace).toString() | 47 | 47 | process.env.__NULLSTACK_CLI_ENVIRONMENT = environment | 48 | 48 | if (name) { | 49 | 49 | process.env.NULLSTACK_ENVIRONMENT_NAME = name | @@ -57,6 +57,7 @@ async function start({ port, name, disk, skipCache, trace }) { | 57 | 57 | const compiler = webpack(settings) | 58 | 58 | clearDir() | 59 | 59 | compiler.watch({ aggregateTimeout: 200, hot: true, ignored: /node_modules/ }, (error, stats) => { | | 60 | + progress.stop() | 60 | 61 | if (error) { | 61 | 62 | console.error(error.stack || error) | 62 | 63 | if (error.details) { | @@ -70,11 +71,11 @@ async function start({ port, name, disk, skipCache, trace }) { | 70 | 71 |
| 71 | 72 | function build({ mode = 'ssr', output, name, skipCache }) { | 72 | 73 | const environment = 'production' | | 74 | + const progress = require('../builders/logger')('application', environment) | 73 | 75 | const compiler = getCompiler({ environment, skipCache, name }) | 74 | 76 | if (name) { | 75 | 77 | process.env.NULLSTACK_ENVIRONMENT_NAME = name | 76 | 78 | } | 77 | | - console.info(` 🚀️ Building your application in ${mode} mode...`) | 78 | 79 | compiler.run((error, stats) => { | 79 | 80 | if (error) { | 80 | 81 | console.error(error.stack || error) | @@ -86,6 +87,7 @@ function build({ mode = 'ssr', output, name, skipCache }) { | 86 | 87 | process.exit(1) | 87 | 88 | } | 88 | 89 | if (stats.hasErrors()) process.exit(1) | | 90 | + progress.stop() | 89 | 91 | require(`../builders/${mode}`)({ output, environment }) | 90 | 92 | }) | 91 | 93 | } | |
Collapse file Copy file name to clipboardExpand all lines: server/hmr.js +6-16Lines changed: 6 additions & 16 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | /* eslint-disable nullstack/no-undef */ | 2 | 2 | import { existsSync, open } from 'fs' | 3 | 3 | import path from 'path' | | 4 | +import logger from '../builders/logger' | 4 | 5 |
| 5 | 6 | function waitCompiler(next) { | 6 | 7 | open(path.join(__dirname, '.compiling'), (error, exists) => { | @@ -15,6 +16,8 @@ function waitCompiler(next) { | 15 | 16 | } | 16 | 17 |
| 17 | 18 | export default function hmr(server) { | | 19 | + const progress = logger('client', 'development') | | 20 | + | 18 | 21 | if (module.hot) { | 19 | 22 | const customConfig = path.resolve(process.cwd(), 'webpack.config.js') | 20 | 23 | const webpackConfigs = existsSync(customConfig) | @@ -45,30 +48,17 @@ export default function hmr(server) { | 45 | 48 | writeToDisk: disk, | 46 | 49 | } | 47 | 50 |
| 48 | | - server.use(async (request, _response, next) => { | 49 | | - if ( | 50 | | - request.originalUrl.indexOf('/nullstack/hmr') === -1 && | 51 | | - request.originalUrl.indexOf('/nullstack-client-update') === -1 && | 52 | | - request.originalUrl.indexOf('/nullstack-server-update') === -1 && | 53 | | - (request.originalUrl.split('?')[0].indexOf('.json') > -1 || | 54 | | - request.originalUrl.split('?')[0].indexOf('.') === -1) | 55 | | - ) { | 56 | | - if (request.originalUrl.startsWith('/nullstack/')) { | 57 | | - console.info(` ⚙️ [${request.method}] ${request.originalUrl}`) | 58 | | - } else { | 59 | | - console.info(` 🕸️ [${request.method}] ${request.originalUrl}`) | 60 | | - } | 61 | | - } | | 51 | + server.use(async (_request, _response, next) => { | 62 | 52 | waitCompiler(next) | 63 | 53 | }) | 64 | 54 |
| 65 | 55 | const instance = webpackDevMiddleware(compiler, webpackDevMiddlewareOptions) | 66 | 56 |
| 67 | 57 | instance.waitUntilValid(() => { | | 58 | + progress.stop() | 68 | 59 | console.info( | 69 | 60 | '\x1b[36m%s\x1b[0m', | 70 | | - ` ✅️ Your application is ready at http://${process.env.NULLSTACK_PROJECT_DOMAIN}:${process.env.NULLSTACK_SERVER_PORT || process.env.PORT || 3000 | 71 | | - }\n`, | | 61 | + `\n 🚀 Your application is ready at http://${process.env.NULLSTACK_PROJECT_DOMAIN}:${process.env.NULLSTACK_SERVER_PORT || process.env.PORT || 3000}\n`, | 72 | 62 | ) | 73 | 63 | }) | 74 | 64 |
| |
Collapse file Copy file name to clipboardExpand all lines: server/server.js +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -152,13 +152,18 @@ server.start = function () { | 152 | 152 | } | 153 | 153 | }) | 154 | 154 |
| 155 | | - if (environment.development) { | | 155 | + if (module.hot) { | 156 | 156 | server.all(`/${prefix}/:version/:hash/:methodName.json`, async (request, response) => { | 157 | 157 | const payload = request.method === 'GET' ? request.query.payload : request.body | 158 | 158 | reqres.set(request, response) | 159 | 159 | const args = deserialize(payload) | 160 | 160 | const { version, hash, methodName } = request.params | 161 | 161 | const [invokerHash, boundHash] = hash.split('-') | | 162 | + let [filePath, klassName] = (invokerHash || boundHash).split("___") | | 163 | + const file = path.resolve('..', filePath.replaceAll('__', '/')) | | 164 | + console.info('\x1b[1;37m%s\x1b[0m', ` [${request.method}] ${request.path}`) | | 165 | + console.info('\x1b[2;37m%s\x1b[0m', ` - ${file}`) | | 166 | + console.info('\x1b[2;37m%s\x1b[0m', ` - ${klassName}.${methodName}(${JSON.stringify(args)})\n`) | 162 | 167 | const key = `${invokerHash}.${methodName}` | 163 | 168 | let invokerKlass; | 164 | 169 | await load(boundHash || invokerHash) | |
|