Skip to content

Commit

Permalink
Merge pull request #152 from fritx/win32-squash
Browse files Browse the repository at this point in the history
squashed: Windows adaptation: Fixed some error points in Windows systems
  • Loading branch information
tipiirai authored Jan 9, 2024
2 parents da8222c + 8834aa1 commit c0c7f34
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
3 changes: 2 additions & 1 deletion packages/nuekit/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export function getArgs(argv) {
// read from package.json
async function getVersion() {
const { promises } = await import('fs')
const path = new URL('../package.json', import.meta.url).pathname
const pathname = new URL('../package.json', import.meta.url).pathname
const path = process.platform === "win32" && pathname.startsWith('/') ? pathname.slice(1) : pathname
const json = await promises.readFile(path, 'utf-8')
return JSON.parse(json).version
}
Expand Down
5 changes: 3 additions & 2 deletions packages/nuekit/src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export async function init({ dist, is_dev, esbuild }) {

// directories
const cwd = process.cwd()
const srcdir = new URL('.', import.meta.url).pathname
const pathname = new URL('.', import.meta.url).pathname
const srcdir = process.platform === "win32" && pathname.startsWith('/') ? pathname.slice(1) : pathname
const fromdir = join(srcdir, 'browser')
const outdir = join(cwd, dist, '@nue')
const minify = !is_dev
Expand All @@ -22,7 +23,7 @@ export async function init({ dist, is_dev, esbuild }) {
return await fs.stat(latest)

} catch {
await fs.rmdir(outdir, { recursive: true })
await fs.rm(outdir, { recursive: true, force: true })
await fs.mkdir(outdir, { recursive: true })
await fs.writeFile(latest, '')
}
Expand Down
4 changes: 2 additions & 2 deletions packages/nuekit/src/nuekit.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ export async function createKit(args) {

// else -> build()
await buildJS({
outdir: join(dist, file.dir),
path: join('.', root, path),
outdir: join(process.cwd(), dist, file.dir),
path: join(process.cwd(), root, path),
minify: is_prod,
bundle
})
Expand Down
14 changes: 7 additions & 7 deletions packages/nuekit/src/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import yaml from 'js-yaml'

// file not found error code
const NOT_FOUND = -2
// file not found error code in windows
const ENOENT = -4058

export async function createSite(args) {

Expand Down Expand Up @@ -38,7 +40,7 @@ export async function createSite(args) {
const raw = await read(path)
return yaml.load(raw)
} catch (e) {
if (e.errno != NOT_FOUND) {
if (e.errno != NOT_FOUND && e.errno != ENOENT) {
throw `YAML parse error in ${path}`
} else if (path == env) throw e
}
Expand Down Expand Up @@ -73,7 +75,6 @@ export async function createSite(args) {
self.is_empty = true
}


async function write(content, dir, filename) {
const todir = join(dist, dir)

Expand All @@ -84,7 +85,7 @@ export async function createSite(args) {
return to

} catch (e) {
if (e.errno != NOT_FOUND) throw e
if (e.errno != NOT_FOUND && e.errno != ENOENT) throw e
await fs.mkdir(todir, { recursive: true })
return await write(content, dir, filename)
}
Expand All @@ -99,7 +100,7 @@ export async function createSite(args) {
!is_bulk && !self.is_empty && log(join(dir, base))

} catch (e) {
if (e.errno != NOT_FOUND) throw e
if (e.errno != NOT_FOUND && e.errno != ENOENT) throw e
await fs.mkdir(join(dist, dir), { recursive: true })
await copy(file)
}
Expand Down Expand Up @@ -127,7 +128,7 @@ export async function createSite(args) {
})

} catch (e) {
if (e.errno != NOT_FOUND) return console.error(e)
if (e.errno != NOT_FOUND && e.errno != ENOENT) return console.error(e)
}
}

Expand Down Expand Up @@ -198,7 +199,7 @@ export async function createSite(args) {
const html = await read(path)
lib.push(...parseNue(html))
} catch (e) {
if (e.errno != NOT_FOUND) {
if (e.errno != NOT_FOUND && e.errno != ENOENT) {
log.error('parse error', path)
console.error(e)
}
Expand Down Expand Up @@ -238,4 +239,3 @@ export async function createSite(args) {
return { ...self, dist, port, read, write, copy, getAssets }

}

0 comments on commit c0c7f34

Please sign in to comment.