feat: netlify staging build implemented

- release scripts refactored
This commit is contained in:
Nishchit14
2022-10-08 15:46:16 +05:30
parent 3cc6e245de
commit 6ed17b8755
5 changed files with 136 additions and 174 deletions

View File

@@ -13,14 +13,13 @@
"electron": "npx electron .",
"release:web-app": "AppFormat=webapp && node scripts/release production",
"release:web-app:staging": "AppFormat=webapp && node scripts/release staging",
"release:extension": "export AppFormat=extension && node scripts/release production",
"release:prod:mac-dmg": "export AppFormat=dmg && node scripts/release production p",
"release:prod:linux-appImage": "export AppFormat=appImage && node scripts/release production",
"release:prod:linux-snap": "export AppFormatode scripts/release production p",
"release:prod:win32-nsis": "export AppFormat=nsis && node scripts/release production p",
"release:canary:mac-dmg": "export AppFormatdmg && node scripts/release canary p",
"release:canary:linux-appImage": "export AppFormatappImage && node scripts/release canary p",
"release:canary:win32-nsis": "export AppFormat=nsis && node scripts/release canary p",
"release:prod:mac-dmg": "AppFormat=dmg && node scripts/release production p",
"release:prod:linux-appImage": "AppFormat=appImage && node scripts/release production",
"release:prod:linux-snap": "AppFormat=snap scripts/release production p",
"release:prod:win32-nsis": "AppFormat=nsis && node scripts/release production p",
"release:canary:mac-dmg": "AppFormat=dmg && node scripts/release canary p",
"release:canary:linux-appImage": "AppFormat=appImage && node scripts/release canary p",
"release:canary:win32-nsis": "AppFormat=nsis && node scripts/release canary p",
"clean": "rimraf build/ development/ *.zip* .crx",
"lint": "eslint packages/firecamp-rest/src/**/*.{ts|tsx} packages/*.js packages-clients/*.js scripts webpack/*.js",
"test-e2e": "cross-env NODE_ENV=test mocha -r ./test/setup-app test/e2e",

View File

@@ -2,54 +2,33 @@
require('dotenv').config();
const fs = require('fs');
const path = require('path');
const colors = require('colors');
// const colors = require('colors');
const { Environment, AppFormat } = require('./constants');
const build = require('../webpack.prod');
require('shelljs/global');
const env = process.env.NODE_ENV;
module.exports = async () => {
try {
// const replaceTasks = [
// {
// from: path.join(
// __dirname,
// '../webpack/replace/JsonpMainTemplate.runtime.js'
// ),
// to: path.join(
// __dirname,
// '../node_modules/webpack/lib/JsonpMainTemplate.runtime.js'
// ),
// },
// {
// from: path.join(__dirname, '../webpack/replace/process-update.js'),
// to: path.join(
// __dirname,
// '../node_modules/webpack-hot-middleware/process-update.js'
// ),
// },
// ];
// hold the build path as per the environment mode
const buildPath = path.join(`${__dirname}/../build/${env}`);
// copy project assets and generate config.
const directoryPaths = [path.join(`${__dirname}/../build`), buildPath];
if (env === Environment.Development) {
directoryPaths.push(
path.join(`${__dirname}/../build/${env}/build-scripts`)
);
}
if (env === Environment.Production) {
directoryPaths.push(
path.join(`${__dirname}/../build/${env}/build-scripts`),
path.join(`${__dirname}/../build/${env}/services`),
path.join(`${__dirname}/../build/${env}/packages-executors`)
);
}
// // Replace webpack config path
// replaceTasks.forEach((task) => cp(task.from, task.to));
// Copy project assets and generate config.
const directoryPaths = [
path.join(`${__dirname}/../build`),
path.join(`${__dirname}/../build/development`),
path.join(`${__dirname}/../build/production`),
path.join(`${__dirname}/../build/development/build-scripts`),
path.join(`${__dirname}/../build/production/build-scripts`),
path.join(`${__dirname}/../build/production/services`),
path.join(`${__dirname}/../build/production/packages-executors`),
];
// Hold the build path as per the environment mode
const buildPath =
process.env.NODE_ENV === Environment.Development
? directoryPaths[1]
: directoryPaths[2];
// Remove all builds before start bundle
// Remove build before start bundle
rm('-rf', buildPath);
// Create build directories
@@ -74,29 +53,27 @@ module.exports = async () => {
);
// generate package.json and manifest based on app environment
if (process.env.NODE_ENV === Environment.Development)
exec(`node ${buildPath}/build-scripts/init-package.js`);
else exec(`node ${buildPath}/build-scripts/init-package.js`);
// exec(`node ${buildPath}/build-scripts/init-package.js`);
// Generate .html
exec(
`pug -O "{ env: '${process.env.NODE_ENV}' }" -o ${buildPath} ${path.join(
`pug -O "{ env: '${env}' }" -o ${buildPath} ${path.join(
__dirname,
'../packages/firecamp-core/public/views/'
)}`
);
cp(
'-R',
path.join(
`${__dirname}/../packages/firecamp-desktop-app/public/splashscreen.html`
),
`${buildPath}`
);
// cp(
// '-R',
// path.join(
// `${__dirname}/../packages/firecamp-desktop-app/public/splashscreen.html`
// ),
// `${buildPath}`
// );
// Copy electron agent assets, config and services
if (
process.env.NODE_ENV === Environment.Production &&
env === Environment.Production &&
process.env.AppFormat !== AppFormat.WebApp
) {
// Copy electron agent services
@@ -122,7 +99,7 @@ module.exports = async () => {
cp(
'-R',
path.join(
`${__dirname}/../packages/firecamp-desktop-app/public/assets/${process.env.NODE_ENV}/mac/*`
`${__dirname}/../packages/firecamp-desktop-app/public/assets/${env}/mac/*`
),
`${buildPath}/build`
);
@@ -133,7 +110,7 @@ module.exports = async () => {
'-R',
path.join(
`${__dirname}/../packages/firecamp-desktop-app/public/assets/${
[...Object.values(Environment)].includes(process.env.NODE_ENV)
[...Object.values(Environment)].includes(env)
? 'production'
: 'canary'
}`
@@ -142,7 +119,7 @@ module.exports = async () => {
);
}
if (process.env.NODE_ENV === 'production') {
if (env === Environment.Production || env === Environment.Staging) {
await build();
}
@@ -152,30 +129,4 @@ module.exports = async () => {
}
};
if (process.env.NODE_ENV === 'development') {
if (process.env.NODE_ENV === Environment.Production) {
console.log(
`${colors.red(
'Error:'
)} Invalid value set for env. variable (NODE_ENV: ${colors.yellow(
process.env.NODE_ENV
)})`
);
process.exit();
}
if (process.env.NODE_ENV === Environment.Development) module.exports();
}
if (process.env.NODE_ENV === 'production') {
if (process.env.NODE_ENV === Environment.Development) {
console.log(
`${colors.red(
'Error:'
)} Invalid value set for env. variable (NODE_ENV: ${colors.yellow(
process.env.NODE_ENV
)})`
);
process.exit();
}
}
if (env === Environment.Development) module.exports();

View File

@@ -1,57 +1,93 @@
/* eslint-disable no-console */
require('dotenv').config();
const colors = require('colors');
const { red, yellow } = require('colors');
const semver = require('semver');
require('shelljs/global');
const build = require('./build');
const { version } = require('../package.json');
const { Environment, AppFormat } = require('./constants');
const variables = [
// 'FIRECAMP_API_HOST',
// 'CSC_KEY_PASSWORD',
// 'CSC_LINK',
// 'DO_KEY_ID',
// 'DO_SECRET_KEY',
];
const env = process.env.NODE_ENV;
// Validate project version
if (!semver.valid(version)) {
/**
* 1. test variables
*/
const validator = {
/** validate project version */
version: () => {
if (!semver.valid(version)) {
console.log(
`${colors.red('Error:')} Invalid project version(${colors.yellow(version)})`
`${red('Error:')} invalid project version(${yellow(version)})`
);
process.exit();
}
}
},
// Set app version in the environment
process.env.APP_VERSION = version;
/** validate env variables */
variables: () => {
const variables = [
'FIRECAMP_API_HOST',
'CSC_KEY_PASSWORD',
'CSC_LINK',
'DO_KEY_ID',
'DO_SECRET_KEY',
];
// Check if environment variables set
variables.forEach((variable) => {
// Check if environment variables set
variables.forEach((variable) => {
if (
!(variable in process.env) ||
!process.env.variable ||
typeof process.env[variable] === 'undefined' ||
process.env[variable].length < 5
) {
console.log(
`${colors.red('Error:')} Env. variable ${colors.yellow(variable)} not set`
`${red('Error:')} Env. variable ${yellow(variable)} not set`
);
process.exit();
}
});
});
},
};
// Check FIRECAMP_API_HOST env. variable value does not contains invalid value
const helper = {
buildWebApp: async () => {
process.env.NODE_OPTIONS = '--max-old-space-size=4096';
await build();
// Finished the process if build=chrome
if (process.env.AppFormat === AppFormat.WebApp) {
// remove unused packages
rm('-rf', `build/${env}/build-scripts`);
rm('-rf', `build/${env}/packages-executors`);
rm('-rf', `build/${env}/services`);
// remove chrome extension app files // TODO: remove it later
rm('-rf', `build/${env}/splashscreen.html`);
rm('-rf', `build/${env}/manifest.json`);
rm('-rf', `build/${env}/background.html`);
rm('-rf', `build/${env}/window.html`);
process.exit();
}
},
};
// set app version in the environment
process.env.APP_VERSION = version;
// check FIRECAMP_API_HOST env. variable value does not contains invalid value
if (
process.env.NODE_ENV !== Environment.Staging &&
env !== Environment.Staging &&
(process.env.FIRECAMP_API_HOST.includes('localhost') ||
process.env.FIRECAMP_API_HOST.includes('testing') ||
process.env.FIRECAMP_API_HOST.includes('127.0.0.1'))
) {
console.log(
`${colors.red(
`${red(
'Error:'
)} Invalid value set for env. variable (FIRECAMP_API_HOST ${colors.yellow(
)} invalid value set for env. variable (FIRECAMP_API_HOST ${yellow(
process.env.FIRECAMP_API_HOST
)})`
);
@@ -72,7 +108,7 @@ const _exec = (command) =>
if (code !== 0) {
console.error(
`
${colors.red('Error: ')}Failed to execute command: ${command}`
${red('Error: ')}Failed to execute command: ${command}`
);
process.exit();
@@ -87,7 +123,7 @@ ${colors.red('Error: ')}Failed to execute command: ${command}`
const preBuildCliCommands = async () => {
// Prevent check git tag while staging build
if (process.env.NODE_ENV === Environment.Staging) return Promise.resolve();
if (env === Environment.Staging) return Promise.resolve();
// Check is tag was checked out or not
// await _exec('git describe --tags', { async: true })
@@ -95,7 +131,7 @@ const preBuildCliCommands = async () => {
// console.log(result);
// if (result.replace(/\n/g, '') !== `v${version}`) {
// console.log(
// `${colors.red('Error:')} Please checkout tag '${colors.yellow(
// `${red('Error:')} Please checkout tag '${yellow(
// `v${version}`
// )}' for release`
// );
@@ -107,41 +143,18 @@ const preBuildCliCommands = async () => {
// });
};
if (process.env.NODE_ENV === Environment.Production) {
if (env === Environment.Staging) {
helper.buildWebApp();
}
if (env === Environment.Production) {
try {
preBuildCliCommands().then(async () => {
/**
* Setting environments
*/
process.env.NODE_OPTIONS = '--max-old-space-size=4096';
await build();
// Finished the process if build=chrome
if (['extension', AppFormat.WebApp].includes(process.env.AppFormat)) {
// Remove unused packages
rm('-rf', 'build/production/build-scripts');
rm('-rf', 'build/production/packages-executors');
rm('-rf', 'build/production/services');
if (process.env.AppFormat === AppFormat.WebApp) {
// Remove chrome extension app files
rm('-rf', 'build/production/splashscreen.html');
rm('-rf', 'build/production/manifest.json');
rm('-rf', 'build/production/background.html');
rm('-rf', 'build/production/window.html');
// TODO: Why it's created
rm('-rf', 'build/production/js/index.html');
rm('-rf', 'build/production/js/background.bundle.js');
}
process.exit();
}
await helper.buildWebApp();
// Set bundle id for electron app
if (process.env.NODE_ENV === Environment.Production)
if (env === Environment.Production)
process.env.appBundleId = 'com.firecamp.app';
else if (process.env.NODE_ENV === Environment.Canary)
else if (env === Environment.Canary)
process.env.appBundleId = 'com.firecamp.canary';
// Copy release note and post build checks
@@ -181,7 +194,7 @@ if (process.env.NODE_ENV === Environment.Production) {
`shasum -a 256 ./dist/Firecamp-${process.env.APP_VERSION}.AppImage`
);
console.log(`${colors.yellow('shasum:')} ${shasum}`);
console.log(`${yellow('shasum:')} ${shasum}`);
}
}
@@ -211,7 +224,7 @@ if (process.env.NODE_ENV === Environment.Production) {
`shasum -a 256 ./dist/Firecamp-${process.env.APP_VERSION}.exe`
);
console.log(`${colors.yellow('shasum:')} ${shasum}`);
console.log(`${yellow('shasum:')} ${shasum}`);
}
}
@@ -231,7 +244,7 @@ if (process.env.NODE_ENV === Environment.Production) {
`shasum -a 256 ./dist/Firecamp-${process.env.APP_VERSION}.dmg`
);
console.log(`${colors.yellow('shasum:')} ${shasum}`);
console.log(`${yellow('shasum:')} ${shasum}`);
}
}
});

View File

@@ -1,5 +1,4 @@
/* eslint-disable no-console */
// import environments
require('dotenv').config();
const webpack = require('webpack');
@@ -7,6 +6,9 @@ const path = require('path');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { Environment } = require('./scripts/constants');
const env = process.env.NODE_ENV;
const metadata = require('./package.json');
@@ -59,12 +61,8 @@ exports.output = {
chunkFilename: '[name].bundle.js',
};
if (process.env.NODE_ENV === 'development') {
exports.output.path = path.join(__dirname, './build/development/js');
exports.output.clean = true;
} else {
exports.output.path = path.join(__dirname, './build/production/js');
}
exports.output.path = path.join(__dirname, `./build/${env}/js`);
if (env === Environment.Development) exports.output.clean = true;
exports.env = {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
@@ -96,7 +94,7 @@ exports.env = {
exports.plugins = [
new HtmlWebpackPlugin({
inject: false,
template: path.join(__dirname, './build/development/index.html'),
template: path.join(__dirname, `./build/${env}/index.html`),
}),
new NodePolyfillPlugin(),
new webpack.ProgressPlugin({

View File

@@ -1,7 +1,9 @@
/* eslint-disable no-console */
const path = require('path');
const webpack = require('webpack');
const { common, env, plugins, rules } = require('./webpack.config');
const nodeEnv = process.env.NODE_ENV;
const config = {
...common,
mode: 'production',
@@ -9,7 +11,7 @@ const config = {
globalObject: 'this',
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js',
path: path.join(__dirname, './build/production/js'),
path: path.join(__dirname, `./build/${nodeEnv}/js`),
},
plugins: [
...plugins,
@@ -56,8 +58,8 @@ const config = {
},
};
module.exports = () => {
return new Promise((resolve, reject) => {
module.exports = () =>
new Promise((resolve, reject) => {
console.log('[Webpack Build]');
console.log('-'.repeat(80));
@@ -88,4 +90,3 @@ module.exports = () => {
resolve();
});
});
};