Skip to content

Commit

Permalink
fix: 修复 minify-docker.js 路径问题
Browse files Browse the repository at this point in the history
  • Loading branch information
CaoMeiYouRen committed Dec 8, 2023
1 parent 95a55d5 commit 04a0c7c
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions templates/scripts/minify-docker.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
/* eslint-disable no-console */
const fs = require('fs-extra');
const path = require('path');
const { nodeFileTrace } = require('@vercel/nft');
/* eslint-disable no-console, @typescript-eslint/no-var-requires */
const fs = require('fs-extra')
const path = require('path')
const { nodeFileTrace } = require('@vercel/nft')
// !!! if any new dependencies are added, update the Dockerfile !!!

const projectRoot = path.resolve(process.env.PROJECT_ROOT || path.join(__dirname, '../'));
const resultFolder = path.join(projectRoot, 'app-minimal'); // no need to resolve, ProjectRoot is always absolute
const files = ['dist/main.js'].map((file) => path.join(projectRoot, file));
const projectRoot = path.resolve(process.env.PROJECT_ROOT || path.join(__dirname, '../'))
const resultFolder = path.join(projectRoot, 'app-minimal') // no need to resolve, ProjectRoot is always absolute
const pkg = fs.readJSONSync(path.join(projectRoot, 'package.json'))
const files = [pkg.main || 'dist/index.js'].map((file) => path.join(projectRoot, file));

(async () => {
console.log('Start analyzing, project root:', projectRoot);
console.log('Start analyzing, project root:', projectRoot)
const { fileList: fileSet } = await nodeFileTrace(files, {
base: projectRoot,
});
let fileList = Array.from(fileSet);
console.log('Total touchable files:', fileList.length);
fileList = fileList.filter((file) => file.startsWith('node_modules')); // only need node_modules
console.log('Total files need to be copied (touchable files in node_modules/):', fileList.length);
console.log('Start copying files, destination:', resultFolder);
return Promise.all(fileList.map((e) =>
fs.copy(path.join(projectRoot, e), path.join(resultFolder, e)).catch(console.error)
));
})
let fileList = Array.from(fileSet)
console.log('Total touchable files:', fileList.length)
fileList = fileList.filter((file) => file.startsWith('node_modules')) // only need node_modules
console.log('Total files need to be copied (touchable files in node_modules):', fileList.length)
console.log('Start copying files, destination:', resultFolder)
return Promise.all(fileList.map((e) => fs.copy(path.join(projectRoot, e), path.join(resultFolder, e)).catch(console.error),
))
})().catch((err) => {
// fix unhandled promise rejections
console.error(err, err.stack);
process.exit(1);
});
console.error(err, err.stack)
process.exit(1)
})

0 comments on commit 04a0c7c

Please sign in to comment.