onlybuild 1.2.0 → 1.3.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 +15 -0
- package/README.md +23 -0
- package/dist/bin/index.d.ts +1 -1
- package/dist/bin/index.js +24 -11
- package/dist/package.json +51 -0
- package/dist/src/build.d.ts +30 -9
- package/dist/src/build.js +34 -20
- package/dist/src/copy.d.ts +5 -5
- package/dist/src/copy.js +8 -8
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [v1.3.0](https://github.com/neogeek/onlybuild/tree/v1.3.0) - (2024-05-08)
|
|
4
|
+
|
|
5
|
+
[Full Changelog](https://github.com/neogeek/onlybuild/compare/v1.2.1...v1.3.0)
|
|
6
|
+
|
|
7
|
+
- [hotfix] Updated packages. [#15](https://github.com/neogeek/onlybuild/pull/15)
|
|
8
|
+
- [feat] Added TypeScript support. (experimental) [#14](https://github.com/neogeek/onlybuild/pull/14)
|
|
9
|
+
- [hotfix] Added experimental code coverage flag to test command. [#13](https://github.com/neogeek/onlybuild/pull/13)
|
|
10
|
+
- [feat] Split build and copy logic into separate methods. [#12](https://github.com/neogeek/onlybuild/pull/12)
|
|
11
|
+
|
|
12
|
+
## [v1.2.1](https://github.com/neogeek/onlybuild/tree/v1.2.1) - (2024-05-07)
|
|
13
|
+
|
|
14
|
+
[Full Changelog](https://github.com/neogeek/onlybuild/compare/v1.2.0...v1.2.1)
|
|
15
|
+
|
|
16
|
+
- [hotfix] Fixed issue with getting version from package.json [#11](https://github.com/neogeek/onlybuild/pull/11)
|
|
17
|
+
|
|
3
18
|
## [v1.2.0](https://github.com/neogeek/onlybuild/tree/v1.2.0) - (2024-05-07)
|
|
4
19
|
|
|
5
20
|
[Full Changelog](https://github.com/neogeek/onlybuild/compare/v1.1.0...v1.2.0)
|
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
- [Getting Started](#getting-started)
|
|
33
33
|
- [File Structure](#file-structure)
|
|
34
34
|
- [Ignore Files](#ignore-files)
|
|
35
|
+
- [TypeScript](#typescript)
|
|
35
36
|
- [Formatting Files](#formatting-files)
|
|
36
37
|
- [Watching For Changes](#watching-for-changes)
|
|
37
38
|
- [Local Server](#local-server)
|
|
@@ -91,6 +92,7 @@ Usage: onlybuild <path> [options]
|
|
|
91
92
|
-v, --version Display the current installed version.
|
|
92
93
|
-o, --out Sets build directory. Default path is build/
|
|
93
94
|
-i, --ignore Sets ignore file path. Default path is .onlyignore
|
|
95
|
+
-t, --typescript Parse TypeScript files. (experimental)
|
|
94
96
|
```
|
|
95
97
|
|
|
96
98
|
## Quick Start Guide
|
|
@@ -262,6 +264,27 @@ screenshot.png
|
|
|
262
264
|
LICENSE
|
|
263
265
|
```
|
|
264
266
|
|
|
267
|
+
## TypeScript
|
|
268
|
+
|
|
269
|
+
> [!WARNING]
|
|
270
|
+
> This feature is experimental.
|
|
271
|
+
|
|
272
|
+
By default `onlybuild` looks for `.mjs` files, but if you add the `--typescript` flag to the build command, it will instead look for `.ts` files.
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
$ npx onlybuild --typescript
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
You will also need to add `"type": "module"` to your `package.json` file for imports to work correctly.
|
|
279
|
+
|
|
280
|
+
```json
|
|
281
|
+
{
|
|
282
|
+
...
|
|
283
|
+
"type": "module",
|
|
284
|
+
...
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
265
288
|
## Formatting Files
|
|
266
289
|
|
|
267
290
|
If you want to reformat the HTML files in the build directory, you can use [Prettier](https://prettier.io/) after the build completes.
|
package/dist/bin/index.d.ts
CHANGED
package/dist/bin/index.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
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';
|
|
1
|
+
#!/usr/bin/env node --no-warnings
|
|
5
2
|
import 'dotenv/config';
|
|
3
|
+
import { register } from 'tsx/esm/api';
|
|
6
4
|
import { globby } from 'globby';
|
|
7
5
|
import parseCmdArgs from 'parse-cmd-args';
|
|
8
|
-
import { buildFiles } from '../src/build.js';
|
|
6
|
+
import { buildFiles, writeFiles } from '../src/build.js';
|
|
9
7
|
import { copyFiles } from '../src/copy.js';
|
|
8
|
+
import pkg from '../package.json' assert { type: 'json' };
|
|
10
9
|
const args = parseCmdArgs(null, {
|
|
11
10
|
requireUserInput: false
|
|
12
11
|
});
|
|
13
12
|
if (args.flags['--version'] || args.flags['-v']) {
|
|
14
|
-
process.stdout.write(`${
|
|
13
|
+
process.stdout.write(`${pkg.version}\n`);
|
|
15
14
|
process.exit();
|
|
16
15
|
}
|
|
17
16
|
else if (args.flags['--help'] || args.flags['-h']) {
|
|
@@ -23,6 +22,7 @@ else if (args.flags['--help'] || args.flags['-h']) {
|
|
|
23
22
|
-v, --version Display the current installed version.
|
|
24
23
|
-o, --out Sets build directory. Default path is build/
|
|
25
24
|
-i, --ignore Sets ignore file path. Default path is .onlyignore
|
|
25
|
+
-t, --typescript Parse TypeScript files. (experimental)
|
|
26
26
|
`);
|
|
27
27
|
process.exit();
|
|
28
28
|
}
|
|
@@ -32,14 +32,25 @@ const [buildDir = 'build/'] = [args.flags['--out'], args.flags['-o']]
|
|
|
32
32
|
const [ignoreFile = '.onlyignore'] = [args.flags['--ignore'], args.flags['-i']]
|
|
33
33
|
.filter(flag => typeof flag === 'string')
|
|
34
34
|
.map(String);
|
|
35
|
-
|
|
35
|
+
const [typescript = false] = [args.flags['--typescript'], args.flags['-t']]
|
|
36
|
+
.filter(flag => typeof flag === 'boolean')
|
|
37
|
+
.map(Boolean);
|
|
38
|
+
if (typescript) {
|
|
39
|
+
register();
|
|
40
|
+
}
|
|
41
|
+
const filesToBuild = await globby([
|
|
42
|
+
typescript ? '**/*.ts' : '**/*.mjs',
|
|
43
|
+
'!_*/**/*',
|
|
44
|
+
'!node_modules/',
|
|
45
|
+
`!${buildDir}`
|
|
46
|
+
], {
|
|
36
47
|
gitignore: false,
|
|
37
48
|
ignoreFiles: [ignoreFile],
|
|
38
49
|
cwd: args.inputs[0]
|
|
39
|
-
})
|
|
40
|
-
|
|
50
|
+
});
|
|
51
|
+
const filesToCopy = await globby([
|
|
41
52
|
'**/*',
|
|
42
|
-
'!**/*.mjs',
|
|
53
|
+
typescript ? '!**/*.ts' : '!**/*.mjs',
|
|
43
54
|
'!_*/**/*',
|
|
44
55
|
'!package.json',
|
|
45
56
|
'!package-lock.json',
|
|
@@ -49,4 +60,6 @@ await copyFiles(await globby([
|
|
|
49
60
|
gitignore: false,
|
|
50
61
|
ignoreFiles: [ignoreFile],
|
|
51
62
|
cwd: args.inputs[0]
|
|
52
|
-
})
|
|
63
|
+
});
|
|
64
|
+
await writeFiles(await buildFiles(filesToBuild), buildDir);
|
|
65
|
+
await copyFiles(filesToCopy, buildDir);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "onlybuild",
|
|
3
|
+
"description": "A zero-config cli for building static websites.",
|
|
4
|
+
"version": "1.3.0",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=20.x"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"bin": {
|
|
10
|
+
"onlybuild": "dist/bin/index.js"
|
|
11
|
+
},
|
|
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",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"dotenv": "16.4.5",
|
|
21
|
+
"globby": "14.0.1",
|
|
22
|
+
"parse-cmd-args": "5.0.2",
|
|
23
|
+
"tsx": "4.9.3"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "20.12.11",
|
|
27
|
+
"typescript": "5.4.5"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"test": "node --import tsx --test --experimental-test-coverage ./src/*.test.ts",
|
|
31
|
+
"build": "rm -rf dist/ && tsc && chmod +x ./dist/bin/index.js",
|
|
32
|
+
"prepare": "npm run build"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"javascript",
|
|
36
|
+
"build",
|
|
37
|
+
"static"
|
|
38
|
+
],
|
|
39
|
+
"authors": [
|
|
40
|
+
{
|
|
41
|
+
"name": "Scott Doxey",
|
|
42
|
+
"email": "hello@scottdoxey.com",
|
|
43
|
+
"homepage": "http://scottdoxey.com/"
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
"homepage": "https://github.com/neogeek/onlybuild",
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "git://github.com/neogeek/onlybuild.git"
|
|
50
|
+
}
|
|
51
|
+
}
|
package/dist/src/build.d.ts
CHANGED
|
@@ -1,22 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Calculates the output path of the file based on the original input path.
|
|
3
3
|
*
|
|
4
4
|
* @param {string} path
|
|
5
|
-
* @param {string} buildDir
|
|
6
|
-
* @param {string} contents
|
|
7
5
|
*/
|
|
8
|
-
export declare const
|
|
6
|
+
export declare const calculateOutputPathFromInputPath: (path: string) => string;
|
|
9
7
|
/**
|
|
10
|
-
*
|
|
8
|
+
* Returns the default export if it is a string.
|
|
11
9
|
*
|
|
12
10
|
* @param {string} path
|
|
13
|
-
* @
|
|
11
|
+
* @returns {Promise<{ path: string; contents: string }>}
|
|
14
12
|
*/
|
|
15
|
-
export declare const buildFile: (path: string
|
|
13
|
+
export declare const buildFile: (path: string) => Promise<{
|
|
14
|
+
path: string;
|
|
15
|
+
contents: string;
|
|
16
|
+
}>;
|
|
16
17
|
/**
|
|
17
|
-
* Iterate over all
|
|
18
|
+
* Iterate over all file paths and returns the default export for each file if it is a string.
|
|
18
19
|
*
|
|
19
20
|
* @param {string[]} paths
|
|
21
|
+
* @returns {Promise<{ path: string; contents: string }[]>}
|
|
22
|
+
*/
|
|
23
|
+
export declare const buildFiles: (paths: string[]) => Promise<{
|
|
24
|
+
path: string;
|
|
25
|
+
contents: string;
|
|
26
|
+
}[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Writes the contents of a file to a path, creating parent directories as needed.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} path
|
|
31
|
+
* @param {string} contents
|
|
32
|
+
*/
|
|
33
|
+
export declare const writeFileAndMakeDir: (path: string, contents: string) => Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Write files to the build directory.
|
|
36
|
+
*
|
|
37
|
+
* @param {{ path: string; contents: string }[]} files,
|
|
20
38
|
* @param {string} buildDir
|
|
21
39
|
*/
|
|
22
|
-
export declare const
|
|
40
|
+
export declare const writeFiles: (files: {
|
|
41
|
+
path: string;
|
|
42
|
+
contents: string;
|
|
43
|
+
}[], buildDir: string) => Promise<void>;
|
package/dist/src/build.js
CHANGED
|
@@ -1,38 +1,52 @@
|
|
|
1
1
|
import { writeFile, mkdir } from 'node:fs/promises';
|
|
2
|
-
import {
|
|
2
|
+
import { dirname, join, parse, resolve } from 'node:path';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Calculates the output path of the file based on the original input path.
|
|
5
5
|
*
|
|
6
6
|
* @param {string} path
|
|
7
|
-
* @param {string} buildDir
|
|
8
|
-
* @param {string} contents
|
|
9
7
|
*/
|
|
10
|
-
export const
|
|
11
|
-
const filename =
|
|
12
|
-
const directory = filename === 'index'
|
|
13
|
-
|
|
14
|
-
: join(buildDir, dirname(path), filename);
|
|
15
|
-
await mkdir(directory, { recursive: true });
|
|
16
|
-
await writeFile(join(directory, 'index.html'), contents);
|
|
8
|
+
export const calculateOutputPathFromInputPath = (path) => {
|
|
9
|
+
const filename = parse(path).name;
|
|
10
|
+
const directory = filename === 'index' ? dirname(path) : join(dirname(path), filename);
|
|
11
|
+
return join(directory, 'index.html');
|
|
17
12
|
};
|
|
18
13
|
/**
|
|
19
|
-
*
|
|
14
|
+
* Returns the default export if it is a string.
|
|
20
15
|
*
|
|
21
16
|
* @param {string} path
|
|
22
|
-
* @
|
|
17
|
+
* @returns {Promise<{ path: string; contents: string }>}
|
|
23
18
|
*/
|
|
24
|
-
export const buildFile = async (path
|
|
19
|
+
export const buildFile = async (path) => {
|
|
25
20
|
const contents = (await import(resolve(path))).default;
|
|
26
|
-
|
|
27
|
-
await writeFileAndMakeDir(path, buildDir, contents);
|
|
28
|
-
}
|
|
21
|
+
return { path, contents: typeof contents === 'string' ? contents : '' };
|
|
29
22
|
};
|
|
30
23
|
/**
|
|
31
|
-
* Iterate over all
|
|
24
|
+
* Iterate over all file paths and returns the default export for each file if it is a string.
|
|
32
25
|
*
|
|
33
26
|
* @param {string[]} paths
|
|
27
|
+
* @returns {Promise<{ path: string; contents: string }[]>}
|
|
28
|
+
*/
|
|
29
|
+
export const buildFiles = async (paths) => {
|
|
30
|
+
return (await Promise.all(paths.map(async (path) => await buildFile(path)))).filter(({ contents }) => contents !== '');
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Writes the contents of a file to a path, creating parent directories as needed.
|
|
34
|
+
*
|
|
35
|
+
* @param {string} path
|
|
36
|
+
* @param {string} contents
|
|
37
|
+
*/
|
|
38
|
+
export const writeFileAndMakeDir = async (path, contents) => {
|
|
39
|
+
await mkdir(dirname(path), { recursive: true });
|
|
40
|
+
await writeFile(path, contents);
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Write files to the build directory.
|
|
44
|
+
*
|
|
45
|
+
* @param {{ path: string; contents: string }[]} files,
|
|
34
46
|
* @param {string} buildDir
|
|
35
47
|
*/
|
|
36
|
-
export const
|
|
37
|
-
await Promise.all(
|
|
48
|
+
export const writeFiles = async (files, buildDir) => {
|
|
49
|
+
await Promise.all(files.map(async (file) => {
|
|
50
|
+
await writeFileAndMakeDir(join(buildDir, calculateOutputPathFromInputPath(file.path)), file.contents);
|
|
51
|
+
}));
|
|
38
52
|
};
|
package/dist/src/copy.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Copies a file from one path to another, creating parent directories as needed.
|
|
3
3
|
*
|
|
4
|
-
* @param {string}
|
|
5
|
-
* @param {string}
|
|
4
|
+
* @param {string} src
|
|
5
|
+
* @param {string} dest
|
|
6
6
|
*/
|
|
7
|
-
export declare const copyFileAndMakeDir: (
|
|
7
|
+
export declare const copyFileAndMakeDir: (src: string, dest: string) => Promise<void>;
|
|
8
8
|
/**
|
|
9
|
-
* Iterate over all
|
|
9
|
+
* Iterate over all file paths and copy them to the build directory.
|
|
10
10
|
*
|
|
11
11
|
* @param {string[]} paths
|
|
12
12
|
* @param {string} buildDir
|
package/dist/src/copy.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { copyFile, mkdir } from 'node:fs/promises';
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Copies a file from one path to another, creating parent directories as needed.
|
|
5
5
|
*
|
|
6
|
-
* @param {string}
|
|
7
|
-
* @param {string}
|
|
6
|
+
* @param {string} src
|
|
7
|
+
* @param {string} dest
|
|
8
8
|
*/
|
|
9
|
-
export const copyFileAndMakeDir = async (
|
|
10
|
-
await mkdir(
|
|
11
|
-
await copyFile(
|
|
9
|
+
export const copyFileAndMakeDir = async (src, dest) => {
|
|
10
|
+
await mkdir(dirname(dest), { recursive: true });
|
|
11
|
+
await copyFile(src, dest);
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
|
-
* Iterate over all
|
|
14
|
+
* Iterate over all file paths and copy them to the build directory.
|
|
15
15
|
*
|
|
16
16
|
* @param {string[]} paths
|
|
17
17
|
* @param {string} buildDir
|
|
18
18
|
*/
|
|
19
19
|
export const copyFiles = async (paths, buildDir) => {
|
|
20
|
-
await Promise.all(paths.map(async (path) => await copyFileAndMakeDir(path, buildDir)));
|
|
20
|
+
await Promise.all(paths.map(async (path) => await copyFileAndMakeDir(path, join(buildDir, path))));
|
|
21
21
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onlybuild",
|
|
3
3
|
"description": "A zero-config cli for building static websites.",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20.x"
|
|
7
7
|
},
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"dotenv": "16.4.5",
|
|
21
21
|
"globby": "14.0.1",
|
|
22
|
-
"parse-cmd-args": "5.0.2"
|
|
22
|
+
"parse-cmd-args": "5.0.2",
|
|
23
|
+
"tsx": "4.9.3"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
|
-
"@types/node": "20.12.
|
|
26
|
-
"tsx": "4.9.3",
|
|
26
|
+
"@types/node": "20.12.11",
|
|
27
27
|
"typescript": "5.4.5"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
|
-
"test": "node --import tsx --test ./src/*.test.ts",
|
|
30
|
+
"test": "node --import tsx --test --experimental-test-coverage ./src/*.test.ts",
|
|
31
31
|
"build": "rm -rf dist/ && tsc && chmod +x ./dist/bin/index.js",
|
|
32
32
|
"prepare": "npm run build"
|
|
33
33
|
},
|