Comparing version 0.1.3 to 0.1.4
{ | ||
"name": "nuekit", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
@@ -19,2 +19,3 @@ "description": "The Nue framework for building websites and webapps", | ||
}, | ||
"scripts": { | ||
@@ -24,3 +25,3 @@ "test": "cd test && bun test" | ||
"dependencies": { | ||
"nuejs-core": "^0.2.0", | ||
"nuejs-core": "^0.3.0", | ||
"diff-dom": "^5.0.6", | ||
@@ -27,0 +28,0 @@ "js-yaml": "^4.1.0", |
@@ -1,21 +0,10 @@ | ||
<div align="center"> | ||
<a href="https://nuejs.org"><img src="https://nuejs.org/logo.svg" width="80"></a> | ||
<h1 align="center" style="border:0">Nue</h1> | ||
<h3 align="center">Simple Next.js and Astro alternative with universal hot-reloading</h3> | ||
</div> | ||
<p align="center"> | ||
<a aria-label="NPM version" href="https://www.npmjs.com/package/nuekit"> | ||
<img alt="" src="https://img.shields.io/npm/v/nuekit.svg?style=for-the-badge&labelColor=000000"> | ||
</a> | ||
<a aria-label="License" href="https://github.com/nuejs/nue/blob/master/LICENSE"> | ||
<img alt="" src="https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge&labelColor=000000"> | ||
</a> | ||
<a aria-label="Join the community on GitHub" href="https://github.com/nuejs/nue/discussions"> | ||
<img alt="" src="https://img.shields.io/badge/Join%20the%20community-blueviolet.svg?style=for-the-badge&labelColor=000000&logoWidth=20"> | ||
</a> | ||
</p> | ||
<a href="https://nuejs.org"> | ||
<img src="https://nuejs.org/img/nue-banner-big.png"> | ||
</a> | ||
<br> | ||
# Nue | ||
Nue(kit) is a static website generator and web application builder. It's an amazingly simple and powerful alternative to **Next.js** and **Astro**: | ||
### Getting Started | ||
@@ -26,6 +15,22 @@ | ||
### Why Nue? | ||
- [Improved development experience](https://nuejs.org/docs/why-nue/developer-experience.html) | ||
- [Standards-based development model](https://nuejs.org/docs/why-nue/closer-to-standards.html) | ||
- [Improved website performance](https://nuejs.org/docs/why-nue/website-performance.html) | ||
#### Notable features | ||
- [Universal hot-reloading](https://nuejs.org/docs/concepts/universal-hot-reloading.html) | ||
- [Hybrid app routing and page routing](https://nuejs.org/docs/concepts/client-side-navigation.html) | ||
- [Modular layout components](https://nuejs.org/docs/concepts/layout-components.html) | ||
- [JS/TypeScript modules](https://nuejs.org/docs/concepts/js-modules.html) | ||
- [Content collections](https://nuejs.org/docs/concepts/content-collections.html) | ||
- [Reactive islands](https://nuejs.org/docs/concepts/reactive-islands.html) | ||
### Roadmap | ||
The ultimate goal of Nue is to create a simpler and more powerful alternative to **Vercel**, **Gatsby**, and **Netlify**. | ||
![Nue Roadmap](https://nuejs.org/img/roadmap2-big.png) | ||
![Nue Roadmap](https://nuejs.org/img/roadmap3-big.png) | ||
@@ -32,0 +37,0 @@ |
@@ -30,3 +30,3 @@ | ||
const { createApp } = await import('./js/nue.js') | ||
const { createApp } = await import('./nue.js') | ||
@@ -33,0 +33,0 @@ for (const node of [...els]) { |
import { extname } from 'node:path' | ||
import { join, extname } from 'node:path' | ||
export async function getBuilder(use_esbuild) { | ||
return process.isBun && !use_esbuild ? Bun : await import('esbuild') | ||
export async function getBuilder(is_esbuild) { | ||
try { | ||
return is_esbuild ? await import('esbuild') : Bun | ||
} catch { | ||
throw 'Bundler not found. Please use Bun or install esbuild' | ||
} | ||
} | ||
export async function buildJS(opts) { | ||
const { outdir, minify, bundle, esbuild } = opts | ||
const builder = await getBuilder(esbuild) | ||
let { path } = opts | ||
export async function buildJS(args) { | ||
const { outdir, toname, minify, bundle } = args | ||
const is_esbuild = args.esbuild || !process.isBun | ||
const builder = await getBuilder(is_esbuild) | ||
let ret | ||
if (path[0] != '/') path = './' + path | ||
const opts = { | ||
external: bundle ? ['../@nue/*', '/@nue/*'] : is_esbuild ? undefined : ['*'], | ||
entryPoints: [ args.path ], | ||
format: 'esm', | ||
outdir, | ||
bundle, | ||
minify, | ||
} | ||
if (args.silent) opts.logLevel = 'silent' | ||
if (toname) { | ||
if (is_esbuild) { | ||
delete opts.outdir | ||
opts.outfile = join(outdir, toname) | ||
} else { | ||
opts.naming = toname | ||
} | ||
} | ||
try { | ||
ret = await builder.build({ | ||
external: bundle ? ['../@nue/*', '/@nue/*'] : esbuild || !process.isBun ? undefined : ['*'], | ||
entryPoints: [ path ], | ||
outdir, bundle, minify, | ||
ret = await builder.build(opts) | ||
// esbuild | ||
logLevel: 'silent', | ||
format: 'esm', | ||
}) | ||
} catch (e) { ret = e } | ||
// console.info(ret) | ||
const error = parseError(ret) | ||
if (error) throw error | ||
// console.log('Built', path) | ||
} | ||
export async function minifyJS(path, outdir, bundle) { | ||
return await buildJS({ path, outdir, minify: true, bundle }) | ||
} | ||
export function parseError(buildResult) { | ||
@@ -39,0 +49,0 @@ const { logs=[], errors=[] } = buildResult |
@@ -21,3 +21,3 @@ | ||
File matches | ||
Only build files that match the rhe rest of the arguments. For example: | ||
Only build files that match the rest of the arguments. For example: | ||
"nue build .ts .css" will build all TypeScript and CSS files | ||
@@ -24,0 +24,0 @@ |
110
src/init.js
import { getBuilder, minifyJS } from './builder.js' | ||
import { compileFile as nueCompile} from 'nuejs-core/index.js' | ||
import { join, basename } from 'node:path' | ||
import { promises as fs } from 'node:fs' | ||
import { compileFile } from 'nuejs-core' | ||
import { log } from './util.js' | ||
import { log, colors } from './util.js' | ||
import { buildJS } from './builder.js' | ||
export async function syncNueDir(dist, is_prod) { | ||
const root = new URL('.', import.meta.url).pathname | ||
const assets = join(root, 'browser') | ||
const nuedir = join(dist, '@nue') | ||
export async function init({ dist, is_dev, esbuild }) { | ||
// make sure JS minifier exist in production | ||
// directories | ||
const cwd = process.cwd() | ||
const srcdir = new URL('.', import.meta.url).pathname | ||
const fromdir = join(srcdir, 'browser') | ||
const outdir = join(cwd, dist, '@nue') | ||
const minify = !is_dev | ||
// init already done? | ||
try { | ||
if (is_prod) await getBuilder() | ||
} catch { | ||
throw 'Bundler not found. Use Bun or install esbuild' | ||
return await fs.stat(join(outdir, 'nue.js')) | ||
} catch {} | ||
// chdir hack (Bun does not support absWorkingDir) | ||
process.chdir(srcdir) | ||
// create outdir | ||
await fs.mkdir(outdir, { recursive: true }) | ||
function print(name) { | ||
console.log(' ', colors.gray(name)) | ||
} | ||
await fs.mkdir(nuedir, { recursive: true }) | ||
// file copy | ||
async function copy(base, todir) { | ||
await fs.copyFile(join(fromdir, base), join(todir, base)) | ||
print(base) | ||
} | ||
async function symlink(src, name) { | ||
const target = join(nuedir, name || basename(src)) | ||
try { | ||
await fs.symlink(src, target) | ||
log('Created symlink', target) | ||
} catch (e) { | ||
if (e.code != 'EEXIST') throw e | ||
else log('Exists', basename(src)) | ||
} | ||
// build/minify single file | ||
async function buildFile(name) { | ||
await buildJS({ path: join(fromdir, `${name}.js`), outdir, esbuild, minify }) | ||
print(`${name}.js`) | ||
} | ||
// nue JS | ||
const jsdir = join(nuedir, 'js') | ||
await fs.mkdir(jsdir, { recursive: true }) | ||
await fs.copyFile(join(assets, 'nue.js'), join(jsdir, 'nue.js')) | ||
// build package (from node_modules) | ||
async function buildPackage(name, toname) { | ||
await buildJS({ | ||
path: name, | ||
bundle: true, | ||
esbuild, | ||
minify, | ||
outdir, | ||
toname | ||
}) | ||
print(toname) | ||
} | ||
// production | ||
if (is_prod) { | ||
await minifyJS(join(assets, 'page-router.js'), nuedir) | ||
await minifyJS(join(assets, 'app-router.js'), nuedir) | ||
await minifyJS(join(assets, 'mount.js'), nuedir) | ||
// do this later | ||
// await minifyJS(join(root, '../../nuejs/src/browser/nue.js'), jsdir, true) | ||
// lets do it | ||
log(`Initialize ${dist}`) | ||
} else { | ||
// await symlink(join(root, 'src'), 'js') | ||
await buildPackage('nuejs-core', 'nue.js') | ||
await buildPackage('diff-dom', 'diffdom.js') | ||
await symlink(join(assets, 'page-router.js')) | ||
await symlink(join(assets, 'app-router.js')) | ||
await symlink(join(assets, 'hotreload.js')) | ||
await symlink(join(assets, 'mount.js')) | ||
await symlink(join(assets, 'diffdom.js')) | ||
await symlink(join(assets, 'error.css')) | ||
await compileFile(join(assets, 'error.nue'), join(nuedir, 'error.js')) | ||
await buildFile('page-router') | ||
await buildFile('app-router') | ||
await buildFile('mount') | ||
// dev only | ||
if (is_dev) { | ||
await buildFile('hotreload') | ||
await copy('error.css', outdir) | ||
await nueCompile(join(fromdir, 'error.nue'), join(outdir, 'error.js')) | ||
} | ||
// favicon | ||
const favicon = join(dist, 'favicon.ico') | ||
try { | ||
await fs.stat(favicon) | ||
await copy('favicon.ico', join(cwd, dist)) | ||
} catch { | ||
await fs.copyFile(join(assets, 'favicon.ico'), favicon) | ||
log('Added default /favicon.ico') | ||
} | ||
process.chdir(cwd) | ||
} |
import { parse as parseNue, compile as compileNue } from 'nuejs-core/index.js' | ||
import { log, colors, parseMarkdown, getAppDir, getParts } from './util.js' | ||
import { renderHead, getDefaultHTML, getDefaultSPA } from './layout.js' | ||
import { parse as parseNue, compile as compileNue } from 'nuejs-core' | ||
import { join, parse as parsePath, extname } from 'node:path' | ||
import { readStats, printTable, categorize } from './stats.js' | ||
import { minifyCSS, buildJS, minifyJS, } from './builder.js' | ||
import { createServer, send } from './nueserver.js' | ||
import { minifyCSS, buildJS } from './builder.js' | ||
import { promises as fs } from 'node:fs' | ||
import { createSite } from './site.js' | ||
import { syncNueDir } from './init.js' | ||
import { fswatch } from './nuefs.js' | ||
import { init } from './init.js' | ||
@@ -29,11 +29,7 @@ // the HTML5 doctype | ||
// make sure @nue dir has all the latest | ||
try { | ||
if (!args.dryrun) await fs.stat(join(dist, '@nue', 'app-router.js')) | ||
if (!args.dryrun) await init({ dist, is_dev }) | ||
} catch { | ||
await syncNueDir(dist, is_prod) | ||
} | ||
async function setupStyles(dir, data) { | ||
@@ -185,3 +181,3 @@ const paths = await site.getAssets(dir, ['style', 'css']) | ||
outdir: join(dist, file.dir), | ||
path: join(root, path), | ||
path: join('.', root, path), | ||
minify: is_prod, | ||
@@ -188,0 +184,0 @@ bundle |
import { log, parseMarkdown, getParts, getAppDir, getDirs, colors } from './util.js' | ||
import { join, extname, basename, sep, parse as parsePath } from 'node:path' | ||
import { parse as parseNue } from 'nuejs-core' | ||
import { parse as parseNue } from 'nuejs-core/index.js' | ||
import { promises as fs } from 'node:fs' | ||
@@ -6,0 +6,0 @@ import { fswalk } from './nuefs.js' |
@@ -6,5 +6,5 @@ | ||
import { createKit } from '../src/nuekit.js' | ||
import { syncNueDir } from '../src/init.js' | ||
import { promises as fs } from 'node:fs' | ||
import { join, parse } from 'node:path' | ||
import { init } from '../src/init.js' | ||
@@ -15,3 +15,3 @@ // temporary directory | ||
// setup and teardown | ||
beforeAll(async () => await fs.mkdir(root)) | ||
beforeAll(async () => await fs.mkdir(root, { recursive: true })) | ||
afterAll(async () => await fs.rm(root, { recursive: true, force: true })) | ||
@@ -170,6 +170,7 @@ | ||
test('@nue files', async () => { | ||
await syncNueDir(root) | ||
test('init dist/@nue dir', async () => { | ||
await init({ dist: root, is_dev: true, esbuild: false }) | ||
const names = await fs.readdir(join(root, '@nue')) | ||
expect(names.length).toBeGreaterThan(5) | ||
expect(names.length).toBeGreaterThan(7) | ||
}) | ||
@@ -233,3 +234,3 @@ | ||
// bun bundle | ||
const opts = { path: `${root}/b.ts`, outdir: root, bundle: true } | ||
const opts = { path: `./${root}/b.ts`, outdir: root, bundle: true } | ||
await buildJS(opts) | ||
@@ -246,3 +247,3 @@ expect(await read('b.js')).toInclude('var foo = 30') | ||
write('a.js', code) | ||
const opts = { path: `${root}/a.js`, outdir: root } | ||
const opts = { path: `./${root}/a.js`, outdir: root, silent: true } | ||
@@ -252,2 +253,3 @@ try { | ||
} catch (e) { | ||
console.info(e) | ||
expect(e.lineText).toBe(code) | ||
@@ -254,0 +256,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46
72574
23
1699
+ Addednuejs-core@0.3.4(transitive)
- Removednuejs-core@0.2.0(transitive)
Updatednuejs-core@^0.3.0