@leverege/build-tools 2.90.2 → 2.91.1

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.90.2",
3
+ "version": "2.91.1",
4
4
  "description": "A collection of build / support tools for Leverege developers",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -11,12 +11,13 @@
11
11
  "clean": "rm -rf lib",
12
12
  "lint": "find ./src -name \\*.\\*js | xargs npx eslint --report-unused-disable-directives",
13
13
  "prepare": "[ $SKIP_PREPARE ] && exit 0 || ./src/hook-and-release.mjs",
14
- "test": "echo \"no tests specified\" && exit 0"
14
+ "test": "echo \"no tests specified\" && exit 0",
15
+ "prepack": "npm exec prepack"
15
16
  },
16
17
  "bin": {
17
- "build-tools": "src/build-tools.mjs",
18
18
  "build-and-push": "src/build-and-push.sh",
19
19
  "build-cnpg-image": "src/build-cnpg-image.mjs",
20
+ "build-tools": "src/build-tools.mjs",
20
21
  "chart-to-museum": "src/chart-to-museum.mjs",
21
22
  "chart-to-registry": "src/chart-to-registry.mjs",
22
23
  "circleate": "src/circleate.sh",
@@ -24,10 +25,10 @@
24
25
  "count-lines-of-code": "src/count-lines-of-code.mjs",
25
26
  "decrypt-secrets": "src/decrypt-secrets.sh",
26
27
  "dirty-git": "src/dirty-git.sh",
27
- "dockreate": "src/dockreate.sh",
28
- "docker-to-registry": "src/docker-to-registry.mjs",
29
28
  "docker-to-registry-py": "src/docker-to-registry-py.mjs",
30
29
  "docker-to-registry.sh": "src/docker-to-registry.sh",
30
+ "docker-to-registry": "src/docker-to-registry.mjs",
31
+ "dockreate": "src/dockreate.sh",
31
32
  "encrypt-secrets": "src/encrypt-secrets.sh",
32
33
  "firebaseDeploy": "src/firebaseDeploy.mjs",
33
34
  "firebaseServe": "src/firebaseServe.mjs",
@@ -38,8 +39,8 @@
38
39
  "helm-audit": "src/helm-audit.mjs",
39
40
  "helmcycle": "src/helmup.sh",
40
41
  "helmdn": "src/helmdn.sh",
41
- "helmup": "src/helmup.sh",
42
42
  "helminit": "src/helmup.sh",
43
+ "helmup": "src/helmup.sh",
43
44
  "helmwhat": "src/helmup.sh",
44
45
  "hook-and-release": "src/hook-and-release.mjs",
45
46
  "init-my-chart": "src/init-my-chart.mjs",
@@ -51,6 +52,7 @@
51
52
  "overwhelm": "src/overwhelm.mjs",
52
53
  "pkgck": "src/pkgck.sh",
53
54
  "pkglint": "src/pkglint.sh",
55
+ "prepack": "src/prepack.mjs",
54
56
  "prune-git": "src/prune-git.sh",
55
57
  "pull-git": "src/pull-git.sh",
56
58
  "push-my-chart": "src/push-my-chart.mjs",
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable no-console */
3
+
4
+ import path from 'node:path'
5
+
6
+ import { parse as semverParse } from 'semver'
7
+ import { $, fs, minimist, chalk } from 'zx'
8
+
9
+ process.env.FORCE_COLOR = '1'
10
+
11
+ const { compile, 'manual-tag' : manualTag, 'force-tag' : forceTag, 'push-tag' : pushTag } = minimist( process.argv.slice( 2 ), {
12
+ default : {
13
+ compile : true,
14
+ 'force-tag' : false,
15
+ 'manual-tag' : false,
16
+ 'push-tag' : true
17
+ },
18
+ boolean : [ 'compile', 'manual-tag', 'force-tag', 'push-tag' ]
19
+ } )
20
+
21
+ try {
22
+ await $`git diff --exit-code --quiet`
23
+ } catch ( err ) {
24
+ console.log( chalk.redBright( 'Your git index is not clean. Stage and/or commit all changes before attempting to publish a version to npm.' ) )
25
+ process.exit( err.exitCode )
26
+ }
27
+
28
+ const isYarn = ( await fs.exists( path.join( process.cwd(), 'yarn.lock' ) ) ) || ( await fs.exists( path.join( process.cwd(), '.yarn' ) ) )
29
+ const packageJson = await fs.readJSON( path.join( process.cwd(), 'package.json' ) )
30
+
31
+ if ( compile && packageJson.scripts?.compile != null ) {
32
+ try {
33
+ await compileCmd( { isYarn } )
34
+ } catch ( error ) {
35
+ process.stderr.write( chalk.redBright( 'Compile command failed with error:\n' ) )
36
+ process.stderr.write( error.text() )
37
+ process.exit( error.exitCode )
38
+ }
39
+ }
40
+
41
+ const version = packageJson.version
42
+ const semanticVersion = semverParse( version )
43
+ const isPrerelease = semanticVersion.prerelease.length > 0
44
+
45
+ if ( !isPrerelease || forceTag ) {
46
+ const name = packageJson.name.replace( /^@leverege\//, '' )
47
+ const isWorkspace = await isInWorkspace( process.cwd() )
48
+
49
+ const tagName = isWorkspace ? `${name}/v${semanticVersion.version}` : `v${semanticVersion.version}`
50
+ const cmd = [ 'git', 'tag', '-a', tagName ]
51
+ if ( !manualTag ) {
52
+ cmd.push( '-m', `"NPM version ${tagName}"` )
53
+ }
54
+
55
+ try {
56
+ await $( {
57
+ quiet : true
58
+ } )`${cmd}`
59
+ } catch ( error ) {
60
+ process.stderr.write( chalk.redBright( 'Failed to create git tag with error:\n' ) )
61
+ process.stderr.write( error.text() )
62
+ process.exit( error.exitCode )
63
+ }
64
+
65
+ if ( pushTag ) {
66
+ try {
67
+ await $( {
68
+ quiet : true
69
+ } )`git push --tags`
70
+ } catch ( error ) {
71
+ process.stderr.write( chalk.redBright( 'Failed to push git tag with error:\n' ) )
72
+ process.stderr.write( error.text() )
73
+ process.exit( error.exitCode )
74
+ }
75
+ }
76
+ }
77
+
78
+ function compileCmd( { isYarn } ) {
79
+ if ( isYarn ) {
80
+ return $( {
81
+ quiet : true
82
+ } )`yarn compile`
83
+ }
84
+
85
+ return $( {
86
+ quiet : true
87
+ } )`npm run compile`
88
+ }
89
+
90
+ async function isInWorkspace( dir ) {
91
+ const parent = path.dirname( dir )
92
+ if ( parent === dir ) {
93
+ return false
94
+ }
95
+
96
+ const parentPkgPath = path.join( parent, 'package.json' )
97
+ if ( await fs.exists( parentPkgPath ) ) {
98
+ const pkg = JSON.parse( await fs.readFile( parentPkgPath, 'utf8' ) )
99
+ if ( pkg.workspaces ) {
100
+ return true
101
+ }
102
+ }
103
+
104
+ return isInWorkspace( parent )
105
+ }