Skip to content

Commit

Permalink
format source js
Browse files Browse the repository at this point in the history
  • Loading branch information
nobkd committed Feb 2, 2025
1 parent 99124d6 commit f7963f0
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 92 deletions.
4 changes: 2 additions & 2 deletions packages/glow/src/glow.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function getTags(lang) {
const tags = HTML_TAGS.filter(el => !el.lang || el.lang.includes(lang))

// custom keywords
if (!['yaml','html', 'json'].includes(lang)) {
if (!['yaml', 'html', 'json'].includes(lang)) {
const w = SPECIAL_WORDS[lang]
const words = (w ? w + '|' : '') + COMMON_WORDS
const re = new RegExp(`\\b(${words})\\b`, 'gi')
Expand Down Expand Up @@ -189,7 +189,7 @@ function renderString(str) {


// exported for testing purposes
export function renderRow(row, lang, mark=true) {
export function renderRow(row, lang, mark = true) {
if (!row) return ''

const els = parseRow(row, lang)
Expand Down
4 changes: 2 additions & 2 deletions packages/nuejs/src/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ function compileNode(root) {
attribs[name] = push(body, true)
}

// for expression
// for expression
} else if (key == ':for') {
attribs[key] = push(compileLoop(val, node))

// attributes
// attributes
} else if (':$'.includes(char) && val && key != ':is') {
const expr = has_expr ? arrwrap(parseExpr(val)) : setContext(val)
attribs[key] = push(expr)
Expand Down
6 changes: 3 additions & 3 deletions packages/nuejs/src/expr.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function parseExpr(str, is_style) {
ret.push(str.includes("'") ? JSON.stringify(str) : `'${str}'`)
}

// Object: { is-active: isActive() }
// Object: { is-active: isActive() }
} else if (isObject(str.trim())) {
const vals = parseClass(str)
ret.push(...vals)
Expand Down Expand Up @@ -104,12 +104,12 @@ export function parseFor(str) {
const keys = parseKeys(prefix)
return [keys.slice(0, 2), expr, keys[2] || '$index', true]

// Object deconstruction
// Object deconstruction
} else if (prefix[0] == '{') {
const { keys, index } = parseObjectKeys(prefix)
return [keys, expr, index || '$index']

// Normal loop variable
// Normal loop variable
} else {
const [key, index = '$index'] = prefix.split(/\s?,\s?/)
return [key, expr, index]
Expand Down
18 changes: 9 additions & 9 deletions packages/nuejs/src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function processIf(node, expr, data, deps) {

// for
function processFor(node, expr, data, deps) {
const [ $keys, for_expr, $index, is_object_loop ] = parseFor(expr)
const [$keys, for_expr, $index, is_object_loop] = parseFor(expr)

// syntax error
if (!for_expr) throw {
Expand All @@ -151,8 +151,8 @@ function processFor(node, expr, data, deps) {

return key === $keys ? (item == null ? data[key] : item) :
key == $index ? items.indexOf(item) :
$keys.includes(key) ? item[key] :
data[key]
$keys.includes(key) ? item[key] :
data[key]
}
})

Expand Down Expand Up @@ -207,11 +207,11 @@ function processNode(opts) {
delete attribs.client
// do nothing: pass content as is

// content
// content
} else if (type == 'text') {
setContent(node, data)

// element
// element
} else if (type == 'tag' || type == 'style' || type == 'script') {

// if
Expand Down Expand Up @@ -245,7 +245,7 @@ function processNode(opts) {
if (html && html != 'false') DOM.replaceElement(node, mkdom(html))
else removeNode(node)

// slot content provided as data
// slot content provided as data
} else if (data.innerHTML) {
DOM.replaceElement(node, mkdom(data.innerHTML))

Expand Down Expand Up @@ -295,17 +295,17 @@ function getJS(nodes) {
return js.join('\n')
}

function createComponent(node, global_js='', template) {
function createComponent(node, global_js = '', template) {
const name = getComponentName(node)

// javascript
const js = getJS(node.children)
const Impl = js[0] && exec(`class Impl { ${ js } }\n${global_js}`)
const Impl = js[0] && exec(`class Impl { ${js} }\n${global_js}`)

// must be after getJS()
const tmpl = getOuterHTML(node)

function create(data, deps=[], inner) {
function create(data, deps = [], inner) {
if (Impl) data = Object.assign(new Impl(data), data) // ...spread won't work
try {
return processNode({ root: mkdom(tmpl), data, deps, inner })
Expand Down
2 changes: 1 addition & 1 deletion packages/nuekit/src/browser/view-transitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export async function loadPage(path, replace_state) {
dispatchEvent(new Event('route'))

// route:app event
const [_, app ] = location.pathname.split('/')
const [_, app] = location.pathname.split('/')
dispatchEvent(new Event(`route:${app || 'home'}`))

setActive(path)
Expand Down
12 changes: 6 additions & 6 deletions packages/nuekit/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ export function getArgs(argv) {
// skip
if (arg.endsWith(sep + 'cli.js') || checkExecutable.test(arg) || arg == '--') {

// test suite
// test suite
} else if (arg.endsWith('.test.js')) {
args.test = true

// command
// command
} else if (commands.includes(arg)) {
args.cmd = arg

// options
// options
} else if (!opt && arg[0] == '-') {

// booleans
Expand Down Expand Up @@ -119,7 +119,7 @@ async function runCommand(args) {
const paths = await nue.build(args.paths)
if (!dryrun && deploy && paths[0]) await deployer({ paths, root: nue.dist, init })

// serve
// serve
} else {
await nue.serve()
}
Expand All @@ -134,11 +134,11 @@ if (esMain(import.meta)) {
if (args.help) {
await printHelp()

// version
// version
} else if (args.version) {
await printVersion()

// command
// command
} else if (!args.test) {
try {
await runCommand(args)
Expand Down
2 changes: 1 addition & 1 deletion packages/nuekit/src/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export async function create({ root, name = 'simple-blog', port }) {
const archive_name = join(root, `${name}-source.tar.gz`)
const archive_web = `https://${name}.nuejs.org/${debug ? 'test' : 'source'}.tar.gz`
const archive = await fetch(archive_web)

// catch download issues
if (archive.status != 200) return console.error(`Downloading template "${archive_web}" failed with "${archive.statusText}".`)
await fs.writeFile(archive_name, Buffer.from(await archive.arrayBuffer()))
Expand Down
2 changes: 1 addition & 1 deletion packages/nuekit/src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async function initDir({ dist, is_dev, esbuild, cwd, srcdir, outdir }) {


function resolvePath(npm_path) {
const [ npm_name, ...parts ] = npm_path.split('/')
const [npm_name, ...parts] = npm_path.split('/')
const module_path = dirname(fileURLToPath(resolve(npm_name, import.meta.url)))
return join(module_path, ...parts)
}
20 changes: 9 additions & 11 deletions packages/nuekit/src/layout/components.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { elem, parseSize, renderInline, renderIcon } from 'nuemark'

import { readFileSync } from 'node:fs'
import { join } from 'node:path'

export function renderPageList(data) {
const key = data.collection_name || data.content_collection
Expand All @@ -23,8 +21,8 @@ export function renderNavi(data) {
return Array.isArray(items)
? renderNav({ items, icon_dir })
: typeof items == 'object'
? renderMultiNav(items, data)
: ''
? renderMultiNav(items, data)
: ''
}

function renderTOC(data) {
Expand Down Expand Up @@ -67,15 +65,15 @@ export function renderPage(page) {

const body = !thumb
? time + elem('a', { href: url }, h2 + p)
: // figure
// figure
: elem(
'a',
{ href: url },
elem(
'a',
{ href: url },
elem(
'figure',
elem('img', { src: thumb, loading: 'lazy' }) + elem('figcaption', time + h2 + p)
)
'figure',
elem('img', { src: thumb, loading: 'lazy' }) + elem('figcaption', time + h2 + p)
)
)

return elem('li', { class: isNew(date) && 'is-new' }, body)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/nuekit/src/layout/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function renderHead(data) {
is_prod,
} = data

const { scripts=[], styles=[], inline_css=[], components=[] } = data.assets || {}
const { scripts = [], styles = [], inline_css = [], components = [] } = data.assets || {}

const head = [`<meta charset="${charset}">`]
if (title) head.push(elem('title', title_template.replace(/%s/gi, title)))
Expand Down Expand Up @@ -76,7 +76,7 @@ export function renderHead(data) {
const css = inline_css.map(el => el.css).join('')
head.push(elem('style', css))

// dev mode: keep path info for hot-reloading
// dev mode: keep path info for hot-reloading
} else {
inline_css.forEach(el => head.push(elem('style', { href: base + el.path }, el.css)))
}
Expand Down
12 changes: 6 additions & 6 deletions packages/nuekit/src/layout/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getLayoutComponents, renderPageList } from './components.js'

import { renderHead } from './head.js'


const SLOTS = 'head banner header subheader pagehead pagefoot aside beside footer bottom main'.split(' ')

const MAIN = parseNue(`
Expand Down Expand Up @@ -54,7 +55,7 @@ export function getSPALayout(body, data) {
return ltrim(`
<html lang="${language}" dir="${direction}">
<head>
${ renderHead(data) }
${renderHead(data)}
</head>
<body>
Expand Down Expand Up @@ -101,7 +102,7 @@ function convertToTags(components, data) {
const tags = {}

components.forEach(comp => {
const { name } = comp
const { name } = comp || {}

if (name && comp.render && !SLOTS.includes(name)) {
tags[name] = function(data) {
Expand All @@ -114,9 +115,8 @@ function convertToTags(components, data) {
return tags
}


export function renderPage(data, lib, custom_tags={}) {
const comps = [ ...lib, ...getLayoutComponents()]
export function renderPage(data, lib, custom_tags = {}) {
const comps = [...lib, ...getLayoutComponents()]
const { document } = data

const tags = {
Expand All @@ -127,7 +127,7 @@ export function renderPage(data, lib, custom_tags={}) {
}

// nuemark opts: { data, sections, heading_ids, links, tags }
const { heading_ids, sections, content_wrapper, links } = data
const { heading_ids, sections, content_wrapper, links } = data
const content = document.render({ data, heading_ids, sections, content_wrapper, links, tags })

const slots = renderSlots({ ...data, content }, comps)
Expand Down
6 changes: 3 additions & 3 deletions packages/nuekit/src/nuefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ export async function fswatch(root, callback, onremove) {
}


export async function fswalk(opts, _dir='', _ret=[]) {
export async function fswalk(opts, _dir = '', _ret = []) {
if (typeof opts == 'string') opts = { root: opts }
const { root, symdirs=true } = opts
const { root, symdirs = true } = opts


const files = await fs.readdir(join(root, _dir), { withFileTypes: true })
Expand All @@ -105,7 +105,7 @@ export async function fswalk(opts, _dir='', _ret=[]) {

const IGNORE = ['node_modules', 'functions', 'package.json', 'bun.lockb', 'pnpm-lock.yaml', 'README.md']

function ignore(name='') {
function ignore(name = '') {
return '._'.includes(name[0]) || IGNORE.includes(name)
}

Expand Down
14 changes: 7 additions & 7 deletions packages/nuekit/src/nuekit.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function createKit(args) {
const arr = []
for (const path of paths) {
if (!path.startsWith('/@nue')) {
const { css } = await processCSS({ path, ...parsePath(path)})
const { css } = await processCSS({ path, ...parsePath(path) })
arr.push({ path, css })
}
}
Expand Down Expand Up @@ -147,10 +147,10 @@ export async function createKit(args) {

if (html.includes('<html')) {
const lib = await site.getServerComponents(appdir, data)
const [ spa, ...spa_lib ] = parseNue(html)
const [spa, ...spa_lib] = parseNue(html)
return DOCTYPE + spa.render(data, [...lib, ...spa_lib])
}
const [ spa ] = parseNue(getSPALayout(html, data))
const [spa] = parseNue(getSPALayout(html, data))
return DOCTYPE + spa.render(data)
}

Expand All @@ -174,7 +174,7 @@ export async function createKit(args) {
return { bundle }
}

async function processCSS({ path, base, dir}) {
async function processCSS({ path, base, dir }) {
const data = await site.getData()
const css = data.lightning_css === false ?
await read(path) :
Expand Down Expand Up @@ -260,11 +260,11 @@ export async function createKit(args) {
islands: 'Transpiling components',
pages: 'Generating pages',
media: 'Copying static files',
spa: 'Single-page apps'
spa: 'Single-page apps'
}

// build all / given matches
async function build(matches=[]) {
async function build(matches = []) {
const begin = Date.now()
log('Building site to:', colors.cyan(dist))

Expand Down Expand Up @@ -334,7 +334,7 @@ export async function createKit(args) {
console.error(file.path, e)
}

// when a file/dir was removed
// when a file/dir was removed
}, async path => {
const dpath = join(dist, path)
await fs.rm(dpath, { recursive: true, force: true })
Expand Down
4 changes: 2 additions & 2 deletions packages/nuekit/src/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export async function createSite(args) {
}

async function getModel() {
const { src, namespace='app' } = site_data.server_model || {}
const { src, namespace = 'app' } = site_data.server_model || {}
if (src) {
const model = await loadExtension(src)
log('Loaded model from', src)
Expand Down Expand Up @@ -263,7 +263,7 @@ export async function createSite(args) {
self.getData = async function(pagedir) {
const data = { nuekit_version, ...site_data, is_prod }

for (const dir of [ ...self.globals, ...traverseDirsUp(pagedir)]) {
for (const dir of [...self.globals, ...traverseDirsUp(pagedir)]) {
extendData(data, await readDirData(dir))
}
return data
Expand Down
Loading

0 comments on commit f7963f0

Please sign in to comment.