diff --git a/packages/nuekit/src/builder.js b/packages/nuekit/src/builder.js index 020ec146..ec27a7b1 100644 --- a/packages/nuekit/src/builder.js +++ b/packages/nuekit/src/builder.js @@ -7,9 +7,8 @@ import { resolve } from 'import-meta-resolve' export async function getBuilder(is_esbuild) { - const actual_cwd = process.env.ACTUAL_CWD || process.cwd() try { - return is_esbuild ? await import(resolve('esbuild', `file://${actual_cwd}/`)) : Bun + return is_esbuild ? await import(resolve('esbuild', import.meta.url)) : Bun } catch { throw 'Bundler not found. Please use Bun or install esbuild' } diff --git a/packages/nuekit/src/init.js b/packages/nuekit/src/init.js index 1e19c77b..d417b759 100644 --- a/packages/nuekit/src/init.js +++ b/packages/nuekit/src/init.js @@ -1,37 +1,31 @@ -import { compileFile as nueCompile} from 'nuejs-core' +import { compileFile as nueCompile } from 'nuejs-core' import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' -import { promises as fs } from 'node:fs' +import { promises as fs, existsSync } from 'node:fs' import { resolve } from 'import-meta-resolve' import { buildJS } from './builder.js' import { colors, srcdir } from './util.js' export async function init({ dist, is_dev, esbuild, force }) { - // directories const cwd = process.cwd() const outdir = join(cwd, dist, '@nue') // has all latest? const latest = join(outdir, '.05') - try { - if (force) throw new Error() - await fs.stat(latest) - return false - } catch { + if (force || !existsSync(latest)) { await fs.rm(outdir, { recursive: true, force: true }) await fs.mkdir(outdir, { recursive: true }) await fs.writeFile(latest, '') - } - await initDir({ dist, is_dev, esbuild, cwd, srcdir, outdir }) + await initDir({ dist, is_dev, esbuild, cwd, srcdir, outdir }) + } } async function initDir({ dist, is_dev, esbuild, cwd, srcdir, outdir }) { - const fromdir = join(srcdir, 'browser') const minify = !is_dev @@ -91,7 +85,7 @@ async function initDir({ dist, is_dev, esbuild, cwd, srcdir, outdir }) { await copy('favicon.ico', join(cwd, dist)) // new line - console.log('') + console.log() } diff --git a/packages/nuekit/src/nuefs.js b/packages/nuekit/src/nuefs.js index 1a2cee20..d6cc3b30 100644 --- a/packages/nuekit/src/nuefs.js +++ b/packages/nuekit/src/nuefs.js @@ -1,6 +1,6 @@ import { watch, promises as fs } from 'node:fs' -import { join, parse, sep } from 'node:path' +import { join, parse } from 'node:path' /* Super minimalistic file system watcher. diff --git a/packages/nuekit/src/nuekit.js b/packages/nuekit/src/nuekit.js index 13bf7277..fe394a43 100644 --- a/packages/nuekit/src/nuekit.js +++ b/packages/nuekit/src/nuekit.js @@ -1,7 +1,7 @@ import { log, colors, getAppDir, parsePathParts, extendData } from './util.js' -import { join, parse as parsePath, extname, basename } from 'node:path' +import { join, parse as parsePath } from 'node:path' import { renderPage, renderSinglePage } from './layout/page-layout.js' import { parse as parseNue, compile as compileNue } from 'nuejs-core' import { lightningCSS, buildJS } from './builder.js' @@ -16,13 +16,9 @@ import { init } from './init.js' // the HTML5 doctype const DOCTYPE = '\n\n' -// file not found error code -const NOT_FOUND = -2 - export async function createKit(args) { const { root, is_prod, esbuild } = args - // site: various file based functions const site = await createSite(args) diff --git a/packages/nuekit/src/site.js b/packages/nuekit/src/site.js index 66c11e7b..a42505a0 100644 --- a/packages/nuekit/src/site.js +++ b/packages/nuekit/src/site.js @@ -5,14 +5,13 @@ import { extendData, getAppDir, log, - colors, toPosix, sortCSS, joinRootPath } from './util.js' -import { join, extname, basename, sep, parse as parsePath } from 'node:path' +import { join, extname, parse as parsePath } from 'node:path' import { parse as parseNue } from 'nuejs-core' -import { promises as fs } from 'node:fs' +import { promises as fs, existsSync } from 'node:fs' import { fswalk } from './nuefs.js' import { nuemark } from 'nuemark' import yaml from 'js-yaml' @@ -30,13 +29,7 @@ export async function createSite(args) { const cache = {} // make sure root exists - try { - await fs.stat(root) - } catch (e) { - console.info(e) - throw `Root directory does not exist: ${root}` - } - + if (!existsSync(root)) throw `Root directory does not exist: ${root}` /* Bun.file()::text() has equal performance @@ -86,11 +79,7 @@ export async function createSite(args) { const dist = joinRootPath(root, rawDist || join('.dist', is_prod ? 'prod' : 'dev')) // flag if .dist is empty - try { - await fs.stat(dist) - } catch { - self.is_empty = true - } + if (!existsSync(dist)) self.is_empty = true async function write(content, dir, filename) { const todir = join(dist, dir) @@ -246,9 +235,7 @@ export async function createSite(args) { const arr = [] // make sure dir exists - try { - await fs.stat(join(root, dir)) - } catch (e) { + if (!existsSync(join(root, dir))) { console.error(`content collection: "${dir}" does not exist`) return arr } @@ -338,14 +325,11 @@ export async function createSite(args) { for (const [dir, name, ext] of try_files) { - try { - const src = join(dir, `${name}.${ext}`) - await fs.stat(join(root, src)) + const src = join(dir, `${name}.${ext}`) + if (existsSync(join(root, src))) return { src, path: join(dir, `${name}.html`), name } - } catch {} } } return { ...self, dist, port, read, write, copy } - } diff --git a/packages/nuekit/src/stats.js b/packages/nuekit/src/stats.js index e2a180c1..759efb80 100644 --- a/packages/nuekit/src/stats.js +++ b/packages/nuekit/src/stats.js @@ -1,6 +1,6 @@ import { join, extname, parse as parsePath } from 'node:path' -import { log, colors, getAppDir, sortCSS } from './util.js' +import { colors, sortCSS } from './util.js' import { promises as fs } from 'node:fs' import { fswalk } from './nuefs.js' diff --git a/packages/nuemark/src/parse.js b/packages/nuemark/src/parse.js index 6c1b065e..5e889e1a 100644 --- a/packages/nuemark/src/parse.js +++ b/packages/nuemark/src/parse.js @@ -2,6 +2,7 @@ import { parseAttr, parseSpecs, parseComponent } from './component.js' import { loadAll, load as parseYAML } from 'js-yaml' import { marked } from 'marked' + const NL = '\n' // returns { meta, sections, headings, links } diff --git a/packages/nuemark/src/render.js b/packages/nuemark/src/render.js index 308f82d2..e664e75c 100644 --- a/packages/nuemark/src/render.js +++ b/packages/nuemark/src/render.js @@ -1,9 +1,7 @@ -import { tags, elem, join, concat } from './tags.js' +import { tags, elem, join } from './tags.js' import { parsePage, parseHeading } from './parse.js' -import { marked, parseInline } from 'marked' -import { parseAttr } from './component.js' - +import { marked } from 'marked' export function renderPage(page, opts) { const { lib=[] } = opts