|
12 | 12 | // See the License for the specific language governing permissions and
|
13 | 13 | // limitations under the License.
|
14 | 14 |
|
15 |
| -import { readFile, mkdir, copyFile } from 'fs/promises'; |
16 |
| -import { dirname, join, relative } from 'path'; |
| 15 | +import { readFile, mkdir, copyFile, stat } from 'fs/promises'; |
| 16 | +import { dirname, extname, join } from 'path'; |
17 | 17 | import type { NextConfig } from 'next/dist/server/config-shared';
|
18 | 18 | import type { Header, Rewrite, Redirect } from 'next/dist/lib/load-custom-routes';
|
19 | 19 | import nextBuild from 'next/dist/build';
|
| 20 | +import { copy } from 'fs-extra'; |
20 | 21 |
|
21 | 22 | import { DeployConfig, PathFactory, exec } from '../../utils';
|
22 | 23 |
|
@@ -50,21 +51,19 @@ export const build = async (config: DeployConfig | Required<DeployConfig>, getPr
|
50 | 51 | const exportDetailJson = await readFile(getProjectPath(distDir, 'export-detail.json')).then(it => JSON.parse(it.toString()), () => { success: false });
|
51 | 52 | if (exportDetailJson.success) {
|
52 | 53 | usingCloudFunctions = false;
|
53 |
| - asyncSteps.push(exec(`cp -r ${exportDetailJson.outDirectory}/* ${getHostingPath()}`)); |
| 54 | + asyncSteps.push( |
| 55 | + copy(exportDetailJson.outDirectory, getHostingPath()) |
| 56 | + ); |
54 | 57 | } else {
|
55 |
| - await exec(`cp -r ${getProjectPath('public')}/* ${getHostingPath()}`); |
56 |
| - await exec(`cp -r ${getProjectPath(distDir, 'static')} ${getHostingPath('_next')}`); |
| 58 | + await copy(getProjectPath('public'), getHostingPath()); |
| 59 | + await copy(getProjectPath(distDir, 'static'), getHostingPath('_next', 'static')); |
57 | 60 |
|
58 |
| - // TODO clean this up, probably conflicts with the code blow |
59 | 61 | const serverPagesDir = getProjectPath(distDir, 'server', 'pages');
|
60 |
| - const htmlFiles = (await exec(`find ${serverPagesDir} -name '*.html'`) as string).split("\n").map(it => it.trim()); |
61 |
| - await Promise.all( |
62 |
| - htmlFiles.map(async path => { |
63 |
| - const newPath = getHostingPath(relative(serverPagesDir, path)); |
64 |
| - await mkdir(dirname(newPath), { recursive: true }); |
65 |
| - await copyFile(path, newPath); |
66 |
| - }) |
67 |
| - ); |
| 62 | + await copy(serverPagesDir, getHostingPath(), { filter: async filename => { |
| 63 | + const status = await stat(filename); |
| 64 | + if (status.isDirectory()) return true; |
| 65 | + return extname(filename) === '.html' |
| 66 | + }}); |
68 | 67 |
|
69 | 68 | const prerenderManifestBuffer = await readFile(getProjectPath(distDir, 'prerender-manifest.json'));
|
70 | 69 | const prerenderManifest = JSON.parse(prerenderManifestBuffer.toString());
|
@@ -96,8 +95,8 @@ export const build = async (config: DeployConfig | Required<DeployConfig>, getPr
|
96 | 95 | await mkdir(deployPath('functions'), { recursive: true });
|
97 | 96 | asyncSteps.push(
|
98 | 97 | copyFile(getProjectPath('next.config.js'), deployPath('functions', 'next.config.js')),
|
99 |
| - exec(`cp -r ${getProjectPath('public')} ${deployPath('functions', 'public')}`), |
100 |
| - exec(`cp -r ${getProjectPath(distDir)} ${deployPath('functions', distDir)}`), |
| 98 | + copy(getProjectPath('public'), deployPath('functions', 'public')), |
| 99 | + copy(getProjectPath(distDir), deployPath('functions', distDir)), |
101 | 100 | );
|
102 | 101 | }
|
103 | 102 |
|
|
0 commit comments