/
tsup.config.ts
107 lines (94 loc) · 3.24 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import path from 'node:path';
import {defineConfig} from 'tsup';
import fs from 'fs-extra';
import {execAsync} from './src/lib/process';
import {
GENERATOR_TEMPLATES_DIR,
GENERATOR_SETUP_ASSETS_DIR,
GENERATOR_STARTER_DIR,
getSkeletonSourceDir,
} from './src/lib/build';
// Cleanup dist folder before buid/dev.
fs.removeSync('./dist');
const commonConfig = defineConfig({
format: 'esm',
minify: false,
bundle: false,
splitting: true,
treeshake: true,
sourcemap: false,
publicDir: 'templates',
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 TS templates
const i18nTemplatesPath = 'lib/setups/i18n/templates';
await fs.copy(
path.join('src', i18nTemplatesPath),
path.join(outDir, i18nTemplatesPath),
);
console.log('\n', 'Copied i18n template files to build directory', '\n');
// Copy Route Templates
const routeTemplatesPath = 'lib/setups/routes/templates';
await fs.copy(
path.join('src', routeTemplatesPath),
path.join(outDir, routeTemplatesPath),
);
console.log('\n', 'Copied route template files to build directory', '\n');
// Copy Bundle Analyzer
const bundleAnalyzer = 'lib/bundle/bundle-analyzer.html';
await fs.copy(
path.join('src', bundleAnalyzer),
path.join(outDir, bundleAnalyzer),
);
console.log('\n', 'Copied bundle analyzer', '\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}/lib/virtual-routes`,
outExtension: () => ({js: '.jsx'}),
dts: false,
async onSuccess() {
const filterArtifacts = (filepath: string) =>
!/node_modules|\.shopify|\.cache|\.turbo|build|dist/gi.test(filepath);
// These files need to be packaged/distributed with the CLI
// so that we can use them in the `generate` command.
await fs.copy(
getSkeletonSourceDir(),
`${outDir}/lib/${GENERATOR_TEMPLATES_DIR}/${GENERATOR_STARTER_DIR}`,
{filter: filterArtifacts},
);
console.log(
'\n',
'Copied skeleton template files to build directory',
'\n',
);
// For some reason, it seems that publicDir => outDir might be skipped on CI,
// so ensure here that asset files are copied:
await fs.copy(
'../hydrogen/src/vite/virtual-routes/assets',
`${outDir}/lib/virtual-routes/assets`,
);
console.log('\n', 'Copied virtual route assets to build directory', '\n');
await fs.copy(
'src/setup-assets',
`${outDir}/lib/${GENERATOR_TEMPLATES_DIR}/${GENERATOR_SETUP_ASSETS_DIR}`,
);
console.log('\n', 'Copied setup assets build directory', '\n');
},
},
]);