using my boilerplate yuh
This commit is contained in:
7
webpack/utils/chalk.ts
Normal file
7
webpack/utils/chalk.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import chalk from 'chalk';
|
||||
|
||||
export const error = chalk.bold.red;
|
||||
export const { bold } = chalk;
|
||||
export const info = chalk.bgHex('#673AB7').rgb(255, 255, 255);
|
||||
export const warning = chalk.bgHex('#FF9800').rgb(255, 255, 255);
|
||||
export const success = chalk.bgHex('#4CAF50').rgb(255, 255, 255);
|
||||
22
webpack/utils/convertSemver.ts
Normal file
22
webpack/utils/convertSemver.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { parse } from 'semver';
|
||||
|
||||
/**
|
||||
* Converts npm semver-style strings (including pre-releases) to a release version compatible
|
||||
* with the extension stores.
|
||||
*
|
||||
* @example
|
||||
* semverVersionTo('1.0.0-beta.1`) returns 1.0.0.100
|
||||
*/
|
||||
export function convertSemver(version: string): string {
|
||||
const semver = parse(version);
|
||||
if (!semver) {
|
||||
throw new Error(`Couldn't parse ${version}!`);
|
||||
}
|
||||
|
||||
const { major, minor, patch, prerelease } = semver;
|
||||
let manifestVersion = `${major}.${minor}.${patch}`;
|
||||
if (prerelease.length) {
|
||||
manifestVersion += `.${prerelease[1]}00`;
|
||||
}
|
||||
return manifestVersion;
|
||||
}
|
||||
28
webpack/utils/git/getSourceRef.ts
Normal file
28
webpack/utils/git/getSourceRef.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import prompts from 'prompts';
|
||||
import { simpleGit } from 'simple-git';
|
||||
import { error } from '../chalk';
|
||||
|
||||
const git = simpleGit();
|
||||
|
||||
export async function getSourceRef(destinationBranch: 'preview' | 'production'): Promise<string> {
|
||||
if (destinationBranch === 'preview') {
|
||||
return 'main';
|
||||
}
|
||||
|
||||
const tags = await git.tags(['--sort=-committerdate']);
|
||||
const alphaTags = tags.all.filter((tag: string) => tag.includes('alpha'));
|
||||
|
||||
if (!alphaTags.length) {
|
||||
console.log(error('No preview builds found, please create one before releasing a production build.'));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const { sourceTag } = await prompts({
|
||||
message: 'Which preview tag do you want to create a production build from?',
|
||||
type: 'select',
|
||||
name: 'sourceTag',
|
||||
choices: alphaTags.map(tag => ({ title: tag, value: tag })),
|
||||
});
|
||||
|
||||
return sourceTag;
|
||||
}
|
||||
16
webpack/utils/printError.ts
Normal file
16
webpack/utils/printError.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import printBuildError from 'react-dev-utils/printBuildError';
|
||||
import { error } from './chalk';
|
||||
/**
|
||||
* Print Errors that we got back from webpack
|
||||
* @param e the error provided by webpacxk
|
||||
*/
|
||||
export default function printError(e: Error) {
|
||||
console.log('printBuildError -> e', e);
|
||||
if (process.env.TSC_COMPILE_ON_ERROR === 'true') {
|
||||
printBuildError(e);
|
||||
} else {
|
||||
// console.log(error('Failed to compile.\n'));
|
||||
printBuildError(e);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
35
webpack/utils/zipProductionBuild.ts
Normal file
35
webpack/utils/zipProductionBuild.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import fs, { mkdirSync } from 'fs';
|
||||
import archiver from 'archiver';
|
||||
import chalk from 'chalk';
|
||||
import path from 'path';
|
||||
|
||||
/**
|
||||
* Creates a zip file from the given source directory
|
||||
* @param fileName the name of the zip file to create
|
||||
* @param outDir the directory to zip up
|
||||
* @param globOptions the glob options to use when finding files to zip
|
||||
* @returns
|
||||
*/
|
||||
export async function zipProductionBuild(fileName: string) {
|
||||
const outDirectory = path.resolve('build');
|
||||
const artifactsDir = path.join(outDirectory, 'artifacts');
|
||||
|
||||
mkdirSync(artifactsDir, { recursive: true });
|
||||
|
||||
const output = fs.createWriteStream(`${artifactsDir}/${fileName}.zip`);
|
||||
const archive = archiver('zip', {
|
||||
zlib: { level: 9 },
|
||||
});
|
||||
archive.pipe(output);
|
||||
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
output.on('close', resolve);
|
||||
archive.on('warning', warn => console.log(chalk.red(warn)));
|
||||
archive.on('error', err => reject(err));
|
||||
});
|
||||
|
||||
archive.glob('**/*', { cwd: outDirectory, ignore: ['*.zip', 'artifacts'] });
|
||||
// eslint-disable-next-line no-void
|
||||
void archive.finalize(); // The promise returned is what's `await-ed`, not the call to `finalize()`
|
||||
return promise;
|
||||
}
|
||||
Reference in New Issue
Block a user