fast-deployment
Version:
A lightweight Node.js package for rapid deployment of Vue.js, Next.js, and Nuxt.js applications
50 lines (49 loc) • 2.1 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createArchive = createArchive;
const tar_1 = __importDefault(require("tar"));
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
/**
* Creates a tarball of the application build
* @param config The deployment configuration
* @returns A promise that resolves with the path to the created tarball
*/
async function createArchive(config) {
const archiveName = `${config.folderName}.tar.gz`;
const filesToInclude = getFilesToInclude(config.appType);
// Filter to only include files that actually exist
const existingFiles = filesToInclude.filter(file => fs_1.default.existsSync(file));
if (existingFiles.length === 0) {
throw new Error('No files found to archive. Make sure the build process completed successfully.');
}
console.log(`Creating archive ${archiveName} with files:`, existingFiles);
// Create the tarball
await tar_1.default.create({
gzip: true,
file: archiveName,
cwd: process.cwd()
}, existingFiles);
// Return the full path to the created tarball
return path_1.default.join(process.cwd(), archiveName);
}
/**
* Determines which files to include in the tarball based on the application type
* @param appType The type of application (vue, next, or nuxt)
* @returns An array of file/directory paths to include in the tarball
*/
function getFilesToInclude(appType) {
switch (appType) {
case 'vue':
return ['dist', 'package.json', 'package-lock.json', 'public'];
case 'next':
return ['.next', 'package.json', 'package-lock.json', 'public', 'next.config.js', 'prisma'];
case 'nuxt':
return ['.nuxt', '.output', 'package.json', 'package-lock.json', 'public', 'nuxt.config.js'];
default:
throw new Error(`Unsupported application type: ${appType}`);
}
}