-
Notifications
You must be signed in to change notification settings - Fork 286
/
Copy pathtsup.config.ts
86 lines (77 loc) · 2.49 KB
/
tsup.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import path from 'node:path';
import {rmSync} from 'node:fs';
import {cp as copy} from 'node:fs/promises';
import {defineConfig} from 'tsup';
import {execAsync} from './src/lib/process';
import {
ASSETS_DIR_PREFIX,
ASSETS_STARTER_DIR,
getSkeletonSourceDir,
} from './src/lib/build';
// Cleanup dist folder before buid/dev.
rmSync('./dist', {recursive: true, force: true});
const commonConfig = defineConfig({
format: 'esm',
minify: false,
bundle: false,
splitting: true,
treeshake: true,
sourcemap: false,
clean: false, // Avoid deleting the assets folder
});
const outDir = 'dist';
export default defineConfig([
{
...commonConfig,
entry: ['src/**/*.ts', '!src/**/*.test.ts'],
outDir,
// Generate types only for the exposed entry points
dts: {entry: ['src/index.ts', 'src/commands/hydrogen/init.ts']},
async onSuccess() {
// Copy assets templates
await copy(path.resolve('assets'), path.join(outDir, ASSETS_DIR_PREFIX), {
recursive: true,
force: true,
});
// These files need to be packaged/distributed with the CLI
// so that we can use them in the `generate` command.
const starterOutDir = path.join(
outDir,
ASSETS_DIR_PREFIX,
ASSETS_STARTER_DIR,
);
await copy(getSkeletonSourceDir(), starterOutDir, {
force: true,
recursive: true,
filter: (filepath: string) =>
!/node_modules|\.shopify|\.cache|\.turbo|build|dist/gi.test(filepath),
});
console.log(
'\n',
'Copied skeleton template files to build directory',
'\n',
);
console.log('\n', 'Generating Oclif manifest...');
await execAsync('node ./scripts/generate-manifest.mjs');
console.log('', 'Oclif manifest generated.\n');
},
},
{
...commonConfig,
// TODO remove virtual routes copy when deprecating classic compiler
entry: ['../hydrogen/src/vite/virtual-routes/**/*.tsx'],
outDir: `${outDir}/${ASSETS_DIR_PREFIX}/virtual-routes`,
outExtension: () => ({js: '.jsx'}),
dts: false,
async onSuccess() {
// For some reason, it seems that publicDir => outDir might be skipped on CI,
// so ensure here that asset files are copied:
await copy(
'../hydrogen/src/vite/virtual-routes/assets',
`${outDir}/${ASSETS_DIR_PREFIX}/virtual-routes/assets`,
{recursive: true, force: true},
);
console.log('\n', 'Copied virtual route assets to build directory', '\n');
},
},
]);