Skip to content

Commit b888df2

Browse files
committed
feat: option to not copy debug dir
1 parent 035c26e commit b888df2

File tree

5 files changed

+60
-24
lines changed

5 files changed

+60
-24
lines changed

Diff for: bin/partytown.cjs

+31-18
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,53 @@
11
#!/usr/bin/env node
22

33
async function run() {
4-
const args = process.argv.slice(2);
5-
const task = args[0];
4+
const task = process.argv.slice(2).filter((a) => !a.startsWith('-'))[0];
5+
const args = process.argv.slice(2).filter((a) => a !== task);
66

7-
if (!task) {
8-
panic('Missing partytown task argument. Example command: partytown copylib dest/directory');
9-
}
10-
11-
switch (task) {
12-
case 'copylib': {
13-
await copyLibTask(args);
14-
break;
15-
}
16-
default: {
17-
panic('Unknown partytown task: ' + task);
18-
}
7+
if (task === 'help' || args.includes('--help') || args.includes('-h')) {
8+
help();
9+
} else if (task === 'version' || args.includes('--version') || args.includes('-v')) {
10+
console.log(version());
11+
} else if (task === 'copylib') {
12+
await copyLibTask(args);
13+
} else {
14+
panic('Unknown partytown task: ' + task);
1915
}
2016
}
2117

2218
async function copyLibTask(args) {
2319
try {
2420
const utils = require('../utils/index.cjs');
25-
const destDir = args[1];
26-
const result = await utils.copyLibFiles(destDir);
21+
const destDir = args.filter((a) => !a.startsWith('-'))[0];
22+
const logResult = !args.includes('--silent');
23+
const includeDebugDir = !args.includes('--no-debug');
24+
const result = await utils.copyLibFiles(destDir, {
25+
debugDir: includeDebugDir,
26+
});
2727

28-
if (!args.includes('--silent')) {
28+
if (logResult) {
2929
console.log('Partytown lib copied to: ' + result.dest);
3030
}
3131
} catch (e) {
3232
panic(String(e.message || e));
3333
}
3434
}
3535

36+
function help() {
37+
console.log(``);
38+
console.log(`Partytown (${version()}):`);
39+
console.log(``);
40+
console.log(` copylib <destDir> [--no-debug | --silent]`);
41+
console.log(``);
42+
}
43+
44+
function version() {
45+
return require('../package.json').version;
46+
}
47+
3648
function panic(msg) {
37-
console.error('❌ ' + msg);
49+
console.error('\n❌ ' + msg);
50+
help();
3851
process.exit(1);
3952
}
4053

Diff for: src/react/snippet.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface PartytownProps extends PartytownConfig {}
1313

1414
/**
1515
* The React `<Partytown/>` component should be placed within the `<head>`
16-
* of the document`.
16+
* of the document.
1717
*
1818
* @public
1919
*/

Diff for: src/utils/api.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
```ts
66

77
// @public
8-
export function copyLibFiles(destDir: string): Promise<{
8+
export function copyLibFiles(destDir: string, opts?: CopyLibFilesOptions): Promise<{
99
src: string;
1010
dest: string;
1111
}>;
1212

13+
// @public (undocumented)
14+
export interface CopyLibFilesOptions {
15+
debugDir?: boolean;
16+
}
17+
1318
// @public
1419
export function libDirPath(): string;
1520

Diff for: src/utils/copy-lib-files.ts

+21-4
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,27 @@ export function libDirPath() {
2929
* This utility function is to make it easier to locate the source library files
3030
* and copy them to your server's correct location, for example: `./public/~partytown/`.
3131
*
32+
* By default, both the minified and debug builds are copied to the destination.
33+
* However, by setting the `debugDir` option to `false`, the debug directory will
34+
* not be copied.
35+
*
3236
* @public
3337
*/
34-
export async function copyLibFiles(destDir: string) {
38+
export async function copyLibFiles(destDir: string, opts: CopyLibFilesOptions = {}) {
3539
if (typeof destDir !== 'string' || destDir.length === 0) {
3640
throw new Error('Missing destDir');
3741
}
3842
if (!isAbsolute(destDir)) {
3943
destDir = resolve(process.cwd(), destDir);
4044
}
41-
await copyLibDir(libDirPath(), destDir);
45+
await copyLibDir(libDirPath(), destDir, opts);
4246
return {
4347
src: libDirPath(),
4448
dest: destDir,
4549
};
4650
}
4751

48-
async function copyLibDir(srcDir: string, destDir: string) {
52+
async function copyLibDir(srcDir: string, destDir: string, opts: CopyLibFilesOptions) {
4953
try {
5054
await mkdir(destDir, { recursive: true });
5155
} catch (e) {}
@@ -61,8 +65,21 @@ async function copyLibDir(srcDir: string, destDir: string) {
6165
if (s.isFile()) {
6266
await copyFile(srcPath, destPath);
6367
} else if (s.isDirectory()) {
64-
await copyLibDir(srcPath, destPath);
68+
if (srcName === 'debug' && opts.debugDir === false) {
69+
return;
70+
}
71+
await copyLibDir(srcPath, destPath, opts);
6572
}
6673
})
6774
);
6875
}
76+
77+
/**
78+
* @public
79+
*/
80+
export interface CopyLibFilesOptions {
81+
/**
82+
* When set to `false` the debug directory will not be copied.
83+
*/
84+
debugDir?: boolean;
85+
}

Diff for: src/utils/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { copyLibFiles, libDirPath } from './copy-lib-files';
2+
export type { CopyLibFilesOptions } from './copy-lib-files';

0 commit comments

Comments
 (0)