vite-plugin-unit 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/vite-plugin-unit.svg?style=for-the-badge)](https://www.npmjs.com/package/vite-plugin-unit)
4
4
 
5
- A vite plugin for handling unit.js projects
5
+ A vite plugin to enable you build websites in units using alpine.js
6
6
 
7
7
  ## installation
8
8
 
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * vite-plugin-unit
3
+ * @description A vite plugin to enable you build websites in units using alpine.js
3
4
  * @author Henry Hale
4
5
  * @license MIT
5
- * @url https://github.com/unit-js/vite-plugin-unit
6
+ * @url https://github.com/henryhale/vite-plugin-unit
6
7
  */
7
8
  import type { Plugin } from "vite";
8
9
  export type PluginOptions = {
@@ -10,4 +11,4 @@ export type PluginOptions = {
10
11
  template: string;
11
12
  slot: string;
12
13
  };
13
- export default function plugin(options: Partial<PluginOptions>): Plugin[];
14
+ export default function plugin(options?: Partial<PluginOptions>): Plugin[];
package/dist/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * vite-plugin-unit
3
+ * @description A vite plugin to enable you build websites in units using alpine.js
3
4
  * @author Henry Hale
4
5
  * @license MIT
5
- * @url https://github.com/unit-js/vite-plugin-unit
6
+ * @url https://github.com/henryhale/vite-plugin-unit
6
7
  */
7
8
  import { existsSync, readFileSync } from "node:fs";
8
- import { dirname, extname, join } from "node:path";
9
+ import { dirname, extname, join, resolve } from "node:path";
9
10
  import { cp, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
10
11
  import { log } from "node:console";
11
12
  const defaultOptions = {
@@ -13,8 +14,10 @@ const defaultOptions = {
13
14
  template: "template.html",
14
15
  slot: "#slot#"
15
16
  };
16
- export default function plugin(options) {
17
+ export default function plugin(options = {}) {
17
18
  const opt = Object.assign({}, defaultOptions, options);
19
+ // https://stackoverflow.com/questions/64963450/dirname-is-not-defined
20
+ const __dirname = resolve(dirname(""));
18
21
  // unit file extension
19
22
  const ext = ".unit";
20
23
  // source code folder
@@ -86,6 +89,7 @@ export default function plugin(options) {
86
89
  res.statusCode = 200;
87
90
  res.setHeader("Content-Type", "text/html");
88
91
  const contents = await readFile(join(config.root, opt.template), { encoding: "utf-8" });
92
+ pathToCode.clear();
89
93
  const compiled = compile(file, await readFile(file, { encoding: "utf-8" }));
90
94
  res.end(contents.replace(opt.slot, compiled));
91
95
  }
@@ -98,7 +102,7 @@ export default function plugin(options) {
98
102
  filePath = filePath.replace(".html", ext);
99
103
  if (existsSync(filePath)) {
100
104
  // print request to the console
101
- log(req.method?.toUpperCase(), req.url, filePath);
105
+ log(req.method?.toUpperCase(), req.url, filePath.slice(config?.root?.length || 0));
102
106
  // send requested file
103
107
  return await respond(filePath);
104
108
  }
@@ -142,7 +146,7 @@ export default function plugin(options) {
142
146
  * Create unit.js compiled output directory
143
147
  */
144
148
  if (existsSync(output)) {
145
- rm(output, { recursive: true, force: true });
149
+ await rm(output, { recursive: true, force: true });
146
150
  }
147
151
  await mkdir(outputDir);
148
152
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-plugin-unit",
3
- "version": "0.0.2",
4
- "description": "A vite plugin for handling unit.js projects",
3
+ "version": "0.0.4",
4
+ "description": "A vite plugin to enable you build websites in units using alpine.js",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",