Skip to content

Commit

Permalink
Merge pull request #232 from nobkd/fix/add-cwd-to-root-pth
Browse files Browse the repository at this point in the history
fix: use `cwd` + `nue root` as base for relative file output path
  • Loading branch information
tipiirai committed Mar 25, 2024
2 parents 93ef108 + aff75df commit 850e85f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/nuekit/src/site.js
@@ -1,5 +1,5 @@

import { log, getParts, getAppDir, getDirs, colors, toPosix, sortCSS } from './util.js'
import { log, getParts, getAppDir, getDirs, colors, toPosix, sortCSS, joinRootPath } from './util.js'
import { join, extname, basename, sep, parse as parsePath } from 'node:path'
import { parse as parseNue } from 'nuejs-core'
import { promises as fs } from 'node:fs'
Expand Down Expand Up @@ -68,11 +68,12 @@ export async function createSite(args) {
}

const {
dist = `${root}/.dist/${is_prod ? 'prod' : 'dev'}`,
dist: rawDist,
port = is_prod ? 8081 : 8080

} = site_data

const dist = joinRootPath(root, rawDist || join('.dist', is_prod ? 'prod' : 'dev'))

// flag if .dist is empty
try {
await fs.stat(dist)
Expand Down
6 changes: 5 additions & 1 deletion packages/nuekit/src/util.js
@@ -1,6 +1,6 @@

/* misc stuff. think shame.css */
import { sep, parse, normalize } from 'node:path'
import { sep, parse, normalize, join, isAbsolute } from 'node:path'


export function log(msg, extra='') {
Expand Down Expand Up @@ -28,6 +28,10 @@ export const colors = getColorFunctions()

/* path parts */

export function joinRootPath(root, path, abs = false) {
return join(abs ? process.cwd() : '', isAbsolute(path) ? '' : root, path)
}

export function getParts(path) {
path = normalize(path)
const { dir, name, base } = parse(path)
Expand Down
4 changes: 2 additions & 2 deletions packages/nuekit/test/nuekit.test.js
Expand Up @@ -71,7 +71,7 @@ test('site.yaml', async () => {
const site = await getSite()

expect(site.globals).toEqual(['global'])
expect(site.dist).toBe('.mydist')
expect(site.dist).toBe('_test/.mydist')
expect(site.port).toBe(1500)

// teardown
Expand All @@ -83,7 +83,7 @@ test('environment', async () => {
await write(env, 'dist: .alt')
const site = await createSite({ root, env })

expect(site.dist).toBe('.alt')
expect(site.dist).toBe('_test/.alt')
expect(site.port).toBe(8080)
})

Expand Down

0 comments on commit 850e85f

Please sign in to comment.