onlybuild 1.1.0 → 1.2.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [v1.2.0](https://github.com/neogeek/onlybuild/tree/v1.2.0) - (2024-05-07)
4
+
5
+ [Full Changelog](https://github.com/neogeek/onlybuild/compare/v1.1.0...v1.2.0)
6
+
7
+ - [feat] Added .env support. [#10](https://github.com/neogeek/onlybuild/pull/10)
8
+ - [hotfix] Added a prepare build target. [#9](https://github.com/neogeek/onlybuild/pull/9)
9
+ - [hotfix] Fix permissions on bin file after build. [#8](https://github.com/neogeek/onlybuild/pull/8)
10
+ - [feat] Converted project to typescript. [#7](https://github.com/neogeek/onlybuild/pull/7)
11
+ - [hotfix] Updated packages. [#6](https://github.com/neogeek/onlybuild/pull/6)
12
+ - [hotfix] Disable gitignore in globby. [#3](https://github.com/neogeek/onlybuild/pull/3)
13
+
3
14
  ## [v1.1.0](https://github.com/neogeek/onlybuild/tree/v1.1.0) - (2024-04-26)
4
15
 
5
16
  [Full Changelog](https://github.com/neogeek/onlybuild/compare/v1.0.0...v1.1.0)
package/README.md CHANGED
@@ -331,13 +331,13 @@ Serving the files once the build is complete is easy using the NPM package [http
331
331
  ## Benchmark
332
332
 
333
333
  > [!NOTE]
334
- > Each run (for onlybuild only) was repeated 5 times and the average time was selected. This result set was generated on a MacBook Air (M1, 2020), macOS Sonoma 14.4.1, 8 GB memory.
334
+ > Each run (for `onlybuild` only) was repeated 5 times and the lowest/fastest time was selected. This result set was generated on a MacBook Air (M1, 2020), macOS Sonoma 14.4.1, 8 GB memory.
335
335
 
336
336
  Times shown are in seconds. Lower is better.
337
337
 
338
338
  | Markdown Files | 250 | 500 | 1000 | 2000 | 4000 |
339
339
  | ---------------------------------------------- | -------: | -------: | -------: | -------: | -------: |
340
- | onlybuild | `0.321` | `0.390` | `0.554` | `0.892` | `1.717` |
340
+ | onlybuild | `0.296` | `0.356` | `0.512` | `0.770` | `1.309` |
341
341
  | [Hugo](https://gohugo.io/) v0.101.0 | `0.071` | `0.110` | `0.171` | `0.352` | `0.684` |
342
342
  | [Eleventy](https://www.11ty.dev/) 1.0.1 | `0.584` | `0.683` | `0.914` | `1.250` | `1.938` |
343
343
  | [Astro](https://astro.build/) 1.0.1 | `2.270` | `3.172` | `5.098` | `9.791` | `22.907` |
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import 'dotenv/config';
3
+ export {};
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+ import { readFile } from 'node:fs/promises';
3
+ import { dirname, join } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import 'dotenv/config';
6
+ import { globby } from 'globby';
7
+ import parseCmdArgs from 'parse-cmd-args';
8
+ import { buildFiles } from '../src/build.js';
9
+ import { copyFiles } from '../src/copy.js';
10
+ const args = parseCmdArgs(null, {
11
+ requireUserInput: false
12
+ });
13
+ if (args.flags['--version'] || args.flags['-v']) {
14
+ process.stdout.write(`${JSON.parse(await readFile(join(dirname(fileURLToPath(import.meta.url)), '../package.json'), 'utf8')).version}\n`);
15
+ process.exit();
16
+ }
17
+ else if (args.flags['--help'] || args.flags['-h']) {
18
+ process.stdout.write(`Usage: onlybuild <path> [options]
19
+
20
+ Options:
21
+
22
+ -h, --help Display this help message.
23
+ -v, --version Display the current installed version.
24
+ -o, --out Sets build directory. Default path is build/
25
+ -i, --ignore Sets ignore file path. Default path is .onlyignore
26
+ `);
27
+ process.exit();
28
+ }
29
+ const [buildDir = 'build/'] = [args.flags['--out'], args.flags['-o']]
30
+ .filter(flag => typeof flag === 'string')
31
+ .map(String);
32
+ const [ignoreFile = '.onlyignore'] = [args.flags['--ignore'], args.flags['-i']]
33
+ .filter(flag => typeof flag === 'string')
34
+ .map(String);
35
+ await buildFiles(await globby(['**/*.mjs', '!_*/**/*', '!node_modules/', `!${buildDir}`], {
36
+ gitignore: false,
37
+ ignoreFiles: [ignoreFile],
38
+ cwd: args.inputs[0]
39
+ }), buildDir);
40
+ await copyFiles(await globby([
41
+ '**/*',
42
+ '!**/*.mjs',
43
+ '!_*/**/*',
44
+ '!package.json',
45
+ '!package-lock.json',
46
+ '!node_modules/',
47
+ `!${buildDir}`
48
+ ], {
49
+ gitignore: false,
50
+ ignoreFiles: [ignoreFile],
51
+ cwd: args.inputs[0]
52
+ }), buildDir);
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Write the file to the build directory while creating the directory, recursively, if it doesn't exist.
3
+ *
4
+ * @param {string} path
5
+ * @param {string} buildDir
6
+ * @param {string} contents
7
+ */
8
+ export declare const writeFileAndMakeDir: (path: string, buildDir: string, contents: string) => Promise<void>;
9
+ /**
10
+ * Import the default export of a JavaScript file and check that the default export is a string before writing the contents to a build file.
11
+ *
12
+ * @param {string} path
13
+ * @param {string} buildDir
14
+ */
15
+ export declare const buildFile: (path: string, buildDir: string) => Promise<void>;
16
+ /**
17
+ * Iterate over all the file paths and write them to the build directory.
18
+ *
19
+ * @param {string[]} paths
20
+ * @param {string} buildDir
21
+ */
22
+ export declare const buildFiles: (paths: string[], buildDir: string) => Promise<void>;
@@ -1,6 +1,5 @@
1
1
  import { writeFile, mkdir } from 'node:fs/promises';
2
2
  import { basename, dirname, join, resolve } from 'node:path';
3
-
4
3
  /**
5
4
  * Write the file to the build directory while creating the directory, recursively, if it doesn't exist.
6
5
  *
@@ -9,18 +8,13 @@ import { basename, dirname, join, resolve } from 'node:path';
9
8
  * @param {string} contents
10
9
  */
11
10
  export const writeFileAndMakeDir = async (path, buildDir, contents) => {
12
- const filename = basename(path, '.mjs');
13
-
14
- const directory =
15
- filename === 'index'
16
- ? join(buildDir, dirname(path))
17
- : join(buildDir, dirname(path), filename);
18
-
19
- await mkdir(directory, { recursive: true });
20
-
21
- await writeFile(join(directory, 'index.html'), contents);
11
+ const filename = basename(path, '.mjs');
12
+ const directory = filename === 'index'
13
+ ? join(buildDir, dirname(path))
14
+ : join(buildDir, dirname(path), filename);
15
+ await mkdir(directory, { recursive: true });
16
+ await writeFile(join(directory, 'index.html'), contents);
22
17
  };
23
-
24
18
  /**
25
19
  * Import the default export of a JavaScript file and check that the default export is a string before writing the contents to a build file.
26
20
  *
@@ -28,13 +22,11 @@ export const writeFileAndMakeDir = async (path, buildDir, contents) => {
28
22
  * @param {string} buildDir
29
23
  */
30
24
  export const buildFile = async (path, buildDir) => {
31
- const contents = (await import(resolve(path))).default;
32
-
33
- if (typeof contents === 'string') {
34
- await writeFileAndMakeDir(path, buildDir, contents);
35
- }
25
+ const contents = (await import(resolve(path))).default;
26
+ if (typeof contents === 'string') {
27
+ await writeFileAndMakeDir(path, buildDir, contents);
28
+ }
36
29
  };
37
-
38
30
  /**
39
31
  * Iterate over all the file paths and write them to the build directory.
40
32
  *
@@ -42,5 +34,5 @@ export const buildFile = async (path, buildDir) => {
42
34
  * @param {string} buildDir
43
35
  */
44
36
  export const buildFiles = async (paths, buildDir) => {
45
- await Promise.all(paths.map(async path => await buildFile(path, buildDir)));
37
+ await Promise.all(paths.map(async (path) => await buildFile(path, buildDir)));
46
38
  };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copy the file to the build directory while creating the directory, recursively, if it doesn't exist.
3
+ *
4
+ * @param {string} path
5
+ * @param {string} buildDir
6
+ */
7
+ export declare const copyFileAndMakeDir: (path: string, buildDir: string) => Promise<void>;
8
+ /**
9
+ * Iterate over all the file paths and copy them to the build directory.
10
+ *
11
+ * @param {string[]} paths
12
+ * @param {string} buildDir
13
+ */
14
+ export declare const copyFiles: (paths: string[], buildDir: string) => Promise<void>;
@@ -1,6 +1,5 @@
1
1
  import { copyFile, mkdir } from 'node:fs/promises';
2
2
  import { dirname, join } from 'node:path';
3
-
4
3
  /**
5
4
  * Copy the file to the build directory while creating the directory, recursively, if it doesn't exist.
6
5
  *
@@ -8,11 +7,9 @@ import { dirname, join } from 'node:path';
8
7
  * @param {string} buildDir
9
8
  */
10
9
  export const copyFileAndMakeDir = async (path, buildDir) => {
11
- await mkdir(join(buildDir, dirname(path)), { recursive: true });
12
-
13
- await copyFile(path, join(buildDir, path));
10
+ await mkdir(join(buildDir, dirname(path)), { recursive: true });
11
+ await copyFile(path, join(buildDir, path));
14
12
  };
15
-
16
13
  /**
17
14
  * Iterate over all the file paths and copy them to the build directory.
18
15
  *
@@ -20,7 +17,5 @@ export const copyFileAndMakeDir = async (path, buildDir) => {
20
17
  * @param {string} buildDir
21
18
  */
22
19
  export const copyFiles = async (paths, buildDir) => {
23
- await Promise.all(
24
- paths.map(async path => await copyFileAndMakeDir(path, buildDir))
25
- );
20
+ await Promise.all(paths.map(async (path) => await copyFileAndMakeDir(path, buildDir)));
26
21
  };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * String template utility that adds syntax highlighting and formatting in text editors.
3
+ *
4
+ * @param {TemplateStringsArray} strings
5
+ * @param {any[]} values
6
+ */
7
+ export declare const html: (strings: TemplateStringsArray, ...values: any[]) => string;
@@ -5,12 +5,6 @@
5
5
  * @param {any[]} values
6
6
  */
7
7
  export const html = (strings, ...values) => {
8
- const processedValues = values.map(value =>
9
- Array.isArray(value) ? value.join('') : value
10
- );
11
-
12
- return strings.reduce(
13
- (prev, curr, i) => `${prev}${curr}${processedValues[i] || ''}`,
14
- ''
15
- );
8
+ const processedValues = values.map(value => Array.isArray(value) ? value.join('') : value);
9
+ return strings.reduce((prev, curr, i) => `${prev}${curr}${processedValues[i] || ''}`, '');
16
10
  };
@@ -0,0 +1 @@
1
+ export { html } from './html.js';
package/package.json CHANGED
@@ -1,22 +1,35 @@
1
1
  {
2
2
  "name": "onlybuild",
3
3
  "description": "A zero-config cli for building static websites.",
4
- "version": "1.1.0",
4
+ "version": "1.2.0",
5
5
  "engines": {
6
6
  "node": ">=20.x"
7
7
  },
8
8
  "type": "module",
9
9
  "bin": {
10
- "onlybuild": "./bin/index.js"
10
+ "onlybuild": "dist/bin/index.js"
11
11
  },
12
- "main": "./src/index.js",
12
+ "exports": {
13
+ ".": "./dist/src/index.js",
14
+ "./build": "./dist/src/build.js",
15
+ "./copy": "./dist/src/copy.js"
16
+ },
17
+ "types": "./dist/src/index.d.ts",
13
18
  "license": "MIT",
14
19
  "dependencies": {
20
+ "dotenv": "16.4.5",
15
21
  "globby": "14.0.1",
16
- "parse-cmd-args": "5.0.1"
22
+ "parse-cmd-args": "5.0.2"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "20.12.10",
26
+ "tsx": "4.9.3",
27
+ "typescript": "5.4.5"
17
28
  },
18
29
  "scripts": {
19
- "test": "node --test"
30
+ "test": "node --import tsx --test ./src/*.test.ts",
31
+ "build": "rm -rf dist/ && tsc && chmod +x ./dist/bin/index.js",
32
+ "prepare": "npm run build"
20
33
  },
21
34
  "keywords": [
22
35
  "javascript",
package/bin/index.js DELETED
@@ -1,80 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { readFile } from 'node:fs/promises';
4
- import { dirname, join } from 'node:path';
5
- import { fileURLToPath } from 'node:url';
6
-
7
- import { globby } from 'globby';
8
-
9
- import parseCmdArgs from 'parse-cmd-args';
10
-
11
- import { buildFiles } from '../src/build.js';
12
- import { copyFiles } from '../src/copy.js';
13
-
14
- const args = parseCmdArgs(null, {
15
- requireUserInput: false
16
- });
17
-
18
- if (args.flags['--version'] || args.flags['-v']) {
19
- process.stdout.write(
20
- `${
21
- JSON.parse(
22
- await readFile(
23
- join(dirname(fileURLToPath(import.meta.url)), '../package.json'),
24
- 'utf8'
25
- )
26
- ).version
27
- }\n`
28
- );
29
- process.exit();
30
- } else if (args.flags['--help'] || args.flags['-h']) {
31
- process.stdout.write(`Usage: onlybuild <path> [options]
32
-
33
- Options:
34
-
35
- -h, --help Display this help message.
36
- -v, --version Display the current installed version.
37
- -o, --out Sets build directory. Default path is build/
38
- -i, --ignore Sets ignore file path. Default path is .onlyignore
39
- `);
40
- process.exit();
41
- }
42
-
43
- const [buildDir = 'build/'] = [args.flags['--out'], args.flags['-o']]
44
- .filter(flag => typeof flag === 'string')
45
- .map(String);
46
-
47
- const [ignoreFile = '.onlyignore'] = [args.flags['--ignore'], args.flags['-i']]
48
- .filter(flag => typeof flag === 'string')
49
- .map(String);
50
-
51
- await buildFiles(
52
- await globby(['**/*.mjs', '!_*/**/*', '!node_modules/', `!${buildDir}`], {
53
- gitignore: true,
54
- ignoreFiles: [ignoreFile],
55
- cwd: args.inputs[0]
56
- }),
57
- buildDir
58
- );
59
-
60
- await copyFiles(
61
- await globby(
62
- [
63
- '**/*',
64
- '!**/*.mjs',
65
- '!_*/**/*',
66
- '!package.json',
67
- '!package-lock.json',
68
- '!node_modules/',
69
- `!${buildDir}`
70
- ],
71
- {
72
- gitignore: true,
73
- ignoreFiles: [ignoreFile],
74
- cwd: args.inputs[0]
75
- }
76
- ),
77
- buildDir
78
- );
79
-
80
- export {};
File without changes