@leverege/build-tools 2.95.0 → 2.96.0-quinn.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ var _execa = _interopRequireDefault(require("execa"));
5
+ var _simpleGit = _interopRequireDefault(require("simple-git"));
6
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
+ const git = new _simpleGit.default();
8
+ const getCurrentBranchName = async () => {
9
+ const branchInfo = await git.branch();
10
+
11
+ // first check to see if there are no branches - new repo?
12
+ if (Object.keys(branchInfo.branches).length === 0) {
13
+ return '';
14
+ }
15
+ return Object.entries(branchInfo.branches).find(([name, info]) => info.current)[0];
16
+ };
17
+ const isProtected = async () => {
18
+ const theBranch = await getCurrentBranchName();
19
+ const protectedBranches = ['main', 'master', 'development'];
20
+ const additionalProtectedBranches = [...process.argv.slice(2)];
21
+
22
+ // Check if the current branch starts with any of the additional
23
+ // protected branch name
24
+ let matchesAdditionalBranch = false;
25
+ for (let i = 0; i < additionalProtectedBranches.length; i++) {
26
+ matchesAdditionalBranch = matchesAdditionalBranch || theBranch.startsWith(additionalProtectedBranches[i]);
27
+ }
28
+ return protectedBranches.includes(theBranch) || matchesAdditionalBranch;
29
+ };
30
+ const npmRunner = async script => {
31
+ try {
32
+ const results = await (0, _execa.default)('npm', ['run', script], {
33
+ stdio: 'inherit'
34
+ });
35
+ return results;
36
+ } catch (err) {
37
+ process.exit(1);
38
+ }
39
+ return undefined;
40
+ };
41
+ (async () => {
42
+ if (await isProtected()) {
43
+ const script = ['test', 'lint'];
44
+ for (let i = 0; i < script.length; i++) {
45
+ await npmRunner(script[i]); // eslint-disable-line no-await-in-loop
46
+ }
47
+ } else {
48
+ process.exit(0);
49
+ }
50
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leverege/build-tools",
3
- "version": "2.95.0",
3
+ "version": "2.96.0-quinn.2",
4
4
  "description": "A collection of build / support tools for Leverege developers",
5
5
  "main": "index.js",
6
6
  "repository": {
package/src/Utils.mjs CHANGED
@@ -585,7 +585,7 @@ export const getRepositoryDescr = async () => {
585
585
  const helmChart = await parseHelmChart()
586
586
  const rootPackageJson = await parseJsonFile( `${gitRoot}/package.json` )
587
587
  const rootPyProjectToml = await parsePyProjectToml( `${gitRoot}/pyproject.toml` )
588
- const isYarnProject = fs.existsSync( path.join( gitRoot, 'yarn.lock' ) ) || fs.existsSync( path.join( gitRoot, '.yarn' ) ) /* eslint-disable-line security/detect-non-literal-fs-filename */
588
+ const isYarnProject = getIsYarnProject( gitRoot )
589
589
 
590
590
  return {
591
591
  currentDir : process.cwd(),
@@ -730,3 +730,30 @@ export const analyzeRepository = async ( giveGuidance ) => {
730
730
  isYarnProject
731
731
  }
732
732
  }
733
+
734
+ export function isDir( path ) {
735
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
736
+ const exists = fs.existsSync( path )
737
+
738
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
739
+ return exists && fs.statSync( path ).isDirectory()
740
+ }
741
+
742
+ export function getSecretsDir() {
743
+ let secretsDir
744
+
745
+ if ( process.env.SECRETS_DIR ) {
746
+ secretsDir = process.env.SECRETS_DIR
747
+ } else if ( isDir( path.join( process.cwd(), 'env' ) ) ) {
748
+ secretsDir = 'env'
749
+ } else {
750
+ secretsDir = 'secrets'
751
+ }
752
+
753
+ return secretsDir
754
+ }
755
+
756
+ export function getIsYarnProject( gitRoot ) {
757
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
758
+ return fs.existsSync( path.join( gitRoot, 'yarn.lock' ) ) || isDir( path.join( gitRoot, '.yarn' ) )
759
+ }
@@ -4,6 +4,8 @@
4
4
  import pkg from 'enquirer'
5
5
  import { $, fs, argv, path, chalk } from 'zx'
6
6
 
7
+ import { getGitRootDirectory, getIsYarnProject, getSecretsDir } from './Utils.mjs'
8
+
7
9
  const { prompt } = pkg
8
10
 
9
11
  // This will preserve coloration from spawned child processes
@@ -34,8 +36,9 @@ const INTERACTIVE_MODE = !TARGET
34
36
 
35
37
  let exited = false
36
38
 
37
- const SECRETS_DIR = 'secrets'
39
+ const SECRETS_DIR = await getSecretsDir()
38
40
  const EXIT_EVENTS = [ 'SIGINT', 'exit', 'uncaughException', 'unhandledRejection' ]
41
+ const isYarnProject = getIsYarnProject( await getGitRootDirectory() )
39
42
 
40
43
  const [
41
44
  firebaserc,
@@ -211,7 +214,10 @@ try {
211
214
  const deployType = CHANNEL ? `hosting:channel:deploy ${CHANNEL.name} ${CHANNEL.expiration ? `--expires ${CHANNEL.expiration}` : ''}`.split( ' ' ) : 'deploy'
212
215
  const hostingPrefix = CHANNEL ? '' : 'hosting:'
213
216
 
214
- await $( { ac } )`npm run clean && DOTENV_CONFIG_PATH=${path.join( process.cwd(), '.env.temp' )} DEPLOYMENT_TARGET=${TARGET.siteId} npm run build && firebase use ${TARGET.projectId} && firebase ${deployType} --only ${hostingPrefix}${TARGET.siteId}`
217
+ const cleanCommand = isYarnProject ? 'yarn clean' : 'npm run clean'
218
+ const buildCommand = isYarnProject ? 'yarn build' : 'npm run build'
219
+
220
+ await $( { ac } )`${cleanCommand} && DOTENV_CONFIG_PATH=${path.join( process.cwd(), '.env.temp' )} DEPLOYMENT_TARGET=${TARGET.siteId} ${buildCommand} && firebase use ${TARGET.projectId} && firebase ${deployType} --only ${hostingPrefix}${TARGET.siteId}`
215
221
  } catch ( err ) {
216
222
  console.error( err )
217
223
  }
@@ -4,6 +4,8 @@
4
4
  import pkg from 'enquirer'
5
5
  import { $, fs, argv, path, chalk } from 'zx'
6
6
 
7
+ import { getGitRootDirectory, getIsYarnProject, getSecretsDir } from './Utils.mjs'
8
+
7
9
  const { prompt } = pkg
8
10
 
9
11
  // This will preserve coloration from spawned child processes
@@ -13,9 +15,12 @@ process.env.FORCE_COLOR = '1'
13
15
  let TARGET = argv._[0]
14
16
  let exited = false
15
17
 
16
- const SECRETS_DIR = 'secrets'
17
18
  const EXIT_EVENTS = [ 'SIGINT', 'exit', 'uncaughtException', 'unhandledRejection' ]
18
19
 
20
+ const SECRETS_DIR = await getSecretsDir()
21
+
22
+ const isYarnProject = getIsYarnProject( await getGitRootDirectory() )
23
+
19
24
  const [
20
25
  firebaserc,
21
26
  firebaseJson,
@@ -142,7 +147,8 @@ EXIT_EVENTS
142
147
  await fs.writeFile( path.join( process.cwd(), '.env.temp' ), envFileContent )
143
148
 
144
149
  try {
145
- await $( { ac } )`DOTENV_CONFIG_PATH=${path.join( process.cwd(), '.env.temp' )} DEPLOYMENT_TARGET=${TARGET.siteId} npm run serve --colors`
150
+ const serveCommand = isYarnProject ? 'yarn serve' : 'npm run serve'
151
+ await $( { ac } )`DOTENV_CONFIG_PATH=${path.join( process.cwd(), '.env.temp' )} DEPLOYMENT_TARGET=${TARGET.siteId} yarn serve --colors`
146
152
  } catch ( err ) {
147
153
  console.error( err )
148
154
  }