Skip to content

Commit

Permalink
chore: fixes, simplifications, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nobkd committed Aug 20, 2024
1 parent 329a82a commit d24ac31
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 48 deletions.
3 changes: 1 addition & 2 deletions packages/nuekit/src/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
18 changes: 6 additions & 12 deletions packages/nuekit/src/init.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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()
}


Expand Down
2 changes: 1 addition & 1 deletion packages/nuekit/src/nuefs.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 1 addition & 5 deletions packages/nuekit/src/nuekit.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -16,13 +16,9 @@ import { init } from './init.js'
// the HTML5 doctype
const DOCTYPE = '<!doctype html>\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)

Expand Down
30 changes: 7 additions & 23 deletions packages/nuekit/src/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 }

}
2 changes: 1 addition & 1 deletion packages/nuekit/src/stats.js
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
1 change: 1 addition & 0 deletions packages/nuemark/src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
6 changes: 2 additions & 4 deletions packages/nuemark/src/render.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit d24ac31

Please sign in to comment.