feat(platform): release/build script optimised

This commit is contained in:
Nishchit14
2022-10-07 23:06:50 +05:30
parent 4fbaf2e336
commit 4e5d78db53
8 changed files with 62 additions and 44 deletions

3
.gitignore vendored
View File

@@ -2,10 +2,7 @@ node_modules
npm-debug.log npm-debug.log
.DS_Store .DS_Store
packages/indexed-db/build
build/ build/
stageBuild/
dev/
cypress/screenshots cypress/screenshots
cypress/videos cypress/videos

View File

@@ -11,8 +11,8 @@
"start": "npx webpack serve --config ./webpack.dev.js", "start": "npx webpack serve --config ./webpack.dev.js",
"dev": "APP_VERSION=$npm_package_version RELEASE_SERVER=dev APP_FORMAT=extension && node scripts/build && npm run build:monorepo && yarn start", "dev": "APP_VERSION=$npm_package_version RELEASE_SERVER=dev APP_FORMAT=extension && node scripts/build && npm run build:monorepo && yarn start",
"electron": "npx electron .", "electron": "npx electron .",
"release:web-app": "export APP_FORMAT=webapp && node scripts/release production", "release:web-app": "APP_FORMAT=webapp && node scripts/release production",
"release:web-app:staging": "export APP_FORMAT=webapp && node scripts/release staging", "release:web-app:staging": "APP_FORMAT=webapp && node scripts/release staging",
"release:extension": "export APP_FORMAT=extension && node scripts/release production", "release:extension": "export APP_FORMAT=extension && node scripts/release production",
"release:prod:mac-dmg": "export APP_FORMAT=dmg && node scripts/release production p", "release:prod:mac-dmg": "export APP_FORMAT=dmg && node scripts/release production p",
"release:prod:linux-appImage": "export APP_FORMAT=appImage && node scripts/release production", "release:prod:linux-appImage": "export APP_FORMAT=appImage && node scripts/release production",
@@ -21,7 +21,7 @@
"release:canary:mac-dmg": "export APP_FORMAT=dmg && node scripts/release canary p", "release:canary:mac-dmg": "export APP_FORMAT=dmg && node scripts/release canary p",
"release:canary:linux-appImage": "export APP_FORMAT=appImage && node scripts/release canary p", "release:canary:linux-appImage": "export APP_FORMAT=appImage && node scripts/release canary p",
"release:canary:win32-nsis": "export APP_FORMAT=nsis && node scripts/release canary p", "release:canary:win32-nsis": "export APP_FORMAT=nsis && node scripts/release canary p",
"clean": "rimraf build/ dev/ *.zip* .crx", "clean": "rimraf build/ development/ *.zip* .crx",
"lint": "eslint packages/firecamp-rest/src/**/*.{ts|tsx} packages/*.js packages-clients/*.js scripts webpack/*.js", "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", "test-e2e": "cross-env NODE_ENV=test mocha -r ./test/setup-app test/e2e",
"_test": "cross-env NODE_ENV=test mocha -r ./test/setup-app test/app", "_test": "cross-env NODE_ENV=test mocha -r ./test/setup-app test/app",

View File

@@ -1,7 +1,9 @@
/* eslint-disable no-console */
require('dotenv').config(); require('dotenv').config();
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const colors = require('colors'); const colors = require('colors');
const Environment = require('./environment');
const build = require('../webpack.prod'); const build = require('../webpack.prod');
require('shelljs/global'); require('shelljs/global');
@@ -33,9 +35,9 @@ module.exports = async () => {
// Copy project assets and generate config. // Copy project assets and generate config.
const directoryPaths = [ const directoryPaths = [
path.join(`${__dirname}/../build`), path.join(`${__dirname}/../build`),
path.join(`${__dirname}/../build/dev`), path.join(`${__dirname}/../build/development`),
path.join(`${__dirname}/../build/production`), path.join(`${__dirname}/../build/production`),
path.join(`${__dirname}/../build/dev/build-scripts`), path.join(`${__dirname}/../build/development/build-scripts`),
path.join(`${__dirname}/../build/production/build-scripts`), path.join(`${__dirname}/../build/production/build-scripts`),
path.join(`${__dirname}/../build/production/services`), path.join(`${__dirname}/../build/production/services`),
path.join(`${__dirname}/../build/production/packages-executors`), path.join(`${__dirname}/../build/production/packages-executors`),
@@ -56,13 +58,13 @@ module.exports = async () => {
}); });
// Copy build-scripts to generate build // Copy build-scripts to generate build
cp( // cp(
'-R', // '-R',
path.join( // path.join(
`${__dirname}/../packages/firecamp-desktop-app/src/build-scripts/*` // `${__dirname}/../packages/firecamp-desktop-app/src/build-scripts/*`
), // ),
`${buildPath}/build-scripts` // `${buildPath}/build-scripts`
); // );
// Copy react app assets // Copy react app assets
cp( cp(
@@ -120,7 +122,7 @@ module.exports = async () => {
cp( cp(
'-R', '-R',
path.join( path.join(
`${__dirname}/../packages/firecamp-desktop-app/public/assets/${process.env.RELEASE_SERVER}/mac/*` `${__dirname}/../packages/firecamp-desktop-app/public/assets/${process.env.NODE_ENV}/mac/*`
), ),
`${buildPath}/build` `${buildPath}/build`
); );
@@ -131,9 +133,7 @@ module.exports = async () => {
'-R', '-R',
path.join( path.join(
`${__dirname}/../packages/firecamp-desktop-app/public/assets/${ `${__dirname}/../packages/firecamp-desktop-app/public/assets/${
['production', 'staging', 'dev'].includes( [...Object.values(Environment)].includes(process.env.NODE_ENV)
process.env.RELEASE_SERVER
)
? 'production' ? 'production'
: 'canary' : 'canary'
}` }`
@@ -153,7 +153,7 @@ module.exports = async () => {
}; };
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
if (process.env.RELEASE_SERVER === 'production') { if (process.env.NODE_ENV === Environment.Production) {
console.log( console.log(
`${colors.red( `${colors.red(
'Error:' 'Error:'
@@ -164,11 +164,11 @@ if (process.env.NODE_ENV === 'development') {
process.exit(); process.exit();
} }
if (process.env.RELEASE_SERVER === 'dev') module.exports(); if (process.env.NODE_ENV === Environment.Development) module.exports();
} }
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
if (process.env.RELEASE_SERVER === 'dev') { if (process.env.NODE_ENV === Environment.Development) {
console.log( console.log(
`${colors.red( `${colors.red(
'Error:' 'Error:'

8
scripts/environment.js Normal file
View File

@@ -0,0 +1,8 @@
const Environment = {
Development: 'development',
Staging: 'staging', // staging will be for testing purpose
Production: 'production',
Canary: 'canary', // Canary is production but for early adopter
};
module.exports = Environment;

View File

@@ -1,3 +1,4 @@
/* eslint-disable no-console */
require('dotenv').config(); require('dotenv').config();
const colors = require('colors'); const colors = require('colors');
const semver = require('semver'); const semver = require('semver');
@@ -5,6 +6,8 @@ require('shelljs/global');
const build = require('./build'); const build = require('./build');
const { version } = require('../package.json'); const { version } = require('../package.json');
const Environment = require('./environment');
const variables = [ const variables = [
// 'FIRECAMP_API_HOST', // 'FIRECAMP_API_HOST',
// 'CSC_KEY_PASSWORD', // 'CSC_KEY_PASSWORD',
@@ -25,6 +28,7 @@ if (!semver.valid(version)) {
process.env.APP_VERSION = version; process.env.APP_VERSION = version;
// Set release server production/staging/canary // Set release server production/staging/canary
// eslint-disable-next-line prefer-destructuring
process.env.RELEASE_SERVER = process.argv[2]; process.env.RELEASE_SERVER = process.argv[2];
// Check if environment variables set // Check if environment variables set
@@ -43,7 +47,7 @@ variables.forEach((variable) => {
// Check FIRECAMP_API_HOST env. variable value does not contains invalid value // Check FIRECAMP_API_HOST env. variable value does not contains invalid value
if ( if (
process.env.RELEASE_SERVER !== 'staging' && process.env.NODE_ENV !== Environment.Staging &&
(process.env.FIRECAMP_API_HOST.includes('localhost') || (process.env.FIRECAMP_API_HOST.includes('localhost') ||
process.env.FIRECAMP_API_HOST.includes('testing') || process.env.FIRECAMP_API_HOST.includes('testing') ||
process.env.FIRECAMP_API_HOST.includes('127.0.0.1')) process.env.FIRECAMP_API_HOST.includes('127.0.0.1'))
@@ -87,22 +91,27 @@ ${colors.red('Error: ')}Failed to execute command: ${command}`
const preBuildCliCommands = async () => { const preBuildCliCommands = async () => {
// Prevent check git tag while staging build // Prevent check git tag while staging build
if (process.env.RELEASE_SERVER === 'staging') return Promise.resolve(); if (process.env.NODE_ENV === Environment.Staging) return Promise.resolve();
// Check is tag was checked out or not // Check is tag was checked out or not
const result = await _exec('git describe --tags', { async: true }); // await _exec('git describe --tags', { async: true })
if (result.replace(/\n/g, '') !== `v${version}`) { // .then((result) => {
console.log( // console.log(result);
` // if (result.replace(/\n/g, '') !== `v${version}`) {
${colors.red('Error:')} Please checkout tag '${colors.yellow( // console.log(
`v${version}` // `${colors.red('Error:')} Please checkout tag '${colors.yellow(
)}' for release` // `v${version}`
); // )}' for release`
process.exit(); // );
} else return Promise.resolve(); // process.exit();
// } else return Promise.resolve();
// })
// .catch((e) => {
// console.log(e, 'this is the error');
// });
}; };
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === Environment.Production) {
try { try {
preBuildCliCommands().then(async () => { preBuildCliCommands().then(async () => {
/** /**
@@ -134,9 +143,9 @@ if (process.env.NODE_ENV === 'production') {
} }
// Set bundle id for electron app // Set bundle id for electron app
if (process.env.RELEASE_SERVER === 'production') if (process.env.NODE_ENV === Environment.Production)
process.env.appBundleId = 'com.firecamp.app'; process.env.appBundleId = 'com.firecamp.app';
else if (process.env.RELEASE_SERVER === 'canary') else if (process.env.NODE_ENV === Environment.Canary)
process.env.appBundleId = 'com.firecamp.canary'; process.env.appBundleId = 'com.firecamp.canary';
// Copy release note and post build checks // Copy release note and post build checks

View File

@@ -1,13 +1,15 @@
/* eslint-disable no-console */
// import environments // import environments
require('dotenv').config(); require('dotenv').config();
const webpack = require('webpack'); const webpack = require('webpack');
const path = require('path'); const path = require('path');
const metadata = require('./package.json');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin'); const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin'); const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin');
const metadata = require('./package.json');
exports.common = { exports.common = {
entry: { entry: {
app: path.join( app: path.join(
@@ -58,17 +60,19 @@ exports.output = {
}; };
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
exports.output['path'] = path.join(__dirname, './build/dev/js'); exports.output.path = path.join(__dirname, './build/development/js');
exports.output['clean'] = true; exports.output.clean = true;
} else { } else {
exports.output['path'] = path.join(__dirname, './build/production/js'); exports.output.path = path.join(__dirname, './build/production/js');
} }
exports.env = { exports.env = {
NODE_ENV: JSON.stringify(process.env.NODE_ENV), NODE_ENV: JSON.stringify(process.env.NODE_ENV),
FIRECAMP_API_HOST: JSON.stringify(process.env.FIRECAMP_API_HOST), FIRECAMP_API_HOST: JSON.stringify(process.env.FIRECAMP_API_HOST),
FIRECAMP_PROXY_API_HOST: JSON.stringify(process.env.FIRECAMP_PROXY_API_HOST), FIRECAMP_PROXY_API_HOST: JSON.stringify(process.env.FIRECAMP_PROXY_API_HOST),
FIRECAMP_EXTENSION_AGENT_ID: JSON.stringify(process.env.FIRECAMP_EXTENSION_AGENT_ID), FIRECAMP_EXTENSION_AGENT_ID: JSON.stringify(
process.env.FIRECAMP_EXTENSION_AGENT_ID
),
APP_VERSION: JSON.stringify(metadata.version), APP_VERSION: JSON.stringify(metadata.version),
APP_FORMAT: JSON.stringify(process.env.APP_FORMAT), APP_FORMAT: JSON.stringify(process.env.APP_FORMAT),
SENTRY_DSN: JSON.stringify(process.env.SENTRY_DSN), SENTRY_DSN: JSON.stringify(process.env.SENTRY_DSN),
@@ -92,7 +96,7 @@ exports.env = {
exports.plugins = [ exports.plugins = [
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
inject: false, inject: false,
template: path.join(__dirname, './build/dev/app.html'), template: path.join(__dirname, './build/development/index.html'),
}), }),
new NodePolyfillPlugin(), new NodePolyfillPlugin(),
new webpack.ProgressPlugin({ new webpack.ProgressPlugin({
@@ -102,7 +106,7 @@ exports.plugins = [
profile: true, profile: true,
handler: (percentage, message, ...args) => { handler: (percentage, message, ...args) => {
console.clear(); console.clear();
console.log((percentage * 100).toFixed() + '%', message, ...args); console.log(`${(percentage * 100).toFixed()}%`, message, ...args);
}, },
}), }),
new MonacoWebpackPlugin({ new MonacoWebpackPlugin({