@leverege/build-tools 2.93.0-beta.6 → 2.93.0-beta.8

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leverege/build-tools",
3
- "version": "2.93.0-beta.6",
3
+ "version": "2.93.0-beta.8",
4
4
  "description": "A collection of build / support tools for Leverege developers",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -50,12 +50,13 @@
50
50
  "npm-link": "src/npm-link.sh",
51
51
  "npm-unlink": "src/npm-unlink.sh",
52
52
  "overwhelm": "src/overwhelm.mjs",
53
- "package-artifact": "src/package-artifact/command.mjs",
54
53
  "pkgck": "src/pkgck.sh",
55
54
  "pkglint": "src/pkglint.sh",
56
55
  "prepack": "src/prepack.mjs",
57
56
  "prune-git": "src/prune-git.sh",
57
+ "pull-artifact": "src/artifacts/pull-artifact.mjs",
58
58
  "pull-git": "src/pull-git.sh",
59
+ "push-artifact": "src/artifacts/push-artifact.mjs",
59
60
  "push-my-chart": "src/push-my-chart.mjs",
60
61
  "refresh-npm-token": "src/refresh-npm-token.mjs",
61
62
  "refresh-py-idx": "src/refresh-py-idx.sh",
@@ -0,0 +1,21 @@
1
+ import crypto from 'crypto'
2
+ import fs from 'fs'
3
+
4
+ class ArtifactPusher {
5
+ constructor( artifact ) {
6
+ this.artifact = artifact
7
+ }
8
+
9
+ async pull() {
10
+ throw new Error( 'Not implemented' )
11
+ }
12
+ }
13
+
14
+ class GenericArtifactPusher extends ArtifactPusher {
15
+
16
+ async pull() {
17
+ throw new Error( 'Not implemented' )
18
+ }
19
+ }
20
+
21
+ export { ArtifactPusher, GenericArtifactPusher }
@@ -1,7 +1,7 @@
1
1
  import crypto from 'crypto'
2
2
  import fs from 'fs'
3
3
 
4
- class ArtifactPackager {
4
+ class ArtifactPusher {
5
5
  constructor( artifact ) {
6
6
  this.artifact = artifact
7
7
  }
@@ -21,53 +21,21 @@ class ArtifactPackager {
21
21
  throw new Error( 'Not implemented' )
22
22
  }
23
23
 
24
- async build() {
24
+ async push() {
25
25
  throw new Error( 'Not implemented' )
26
26
  }
27
-
28
- async publish() {
29
- throw new Error( 'Not implemented' )
30
- }
31
-
32
- async package() {
33
- if ( await this.exists() ) {
34
- console.log( 'Artifact already exists in the registry' )
35
- return false
36
- }
37
- await this.build()
38
- return this.publish()
39
- }
40
27
  }
41
28
 
42
- class GenericArtifactPackager extends ArtifactPackager {
29
+ class GenericArtifactPusher extends ArtifactPusher {
43
30
 
44
31
  async exists() {
45
-
46
32
  const isDirectory = fs.statSync( this.artifact.source_path ).isDirectory()
47
33
 
48
34
  // If source path is a directory, check whether the destination path alreadu exists in the registry
49
35
  if ( isDirectory ) {
50
- // const command = `gcloud artifacts files list \
51
- // --project=${this.artifact.gcp_project_id} \
52
- // --location=${this.artifact.gcp_location} \
53
- // --repository=${this.artifact.gcp_artifact_registry_repository_name} \
54
- // --package=${this.artifact.gcp_artifact_registry_package_name} \
55
- // --version ${this.artifact.gcp_artifact_registry_package_version} \
56
- // --format="json"`
57
- // const { execSync } = await import( 'child_process' )
58
- // const result = execSync( command, { encoding : 'utf8', stdio : 'pipe' } )
59
- // const files = JSON.parse( result )
60
-
61
- // // Calculate checksum for each file in the directory
62
- // // ...
63
-
64
- // console.log( files )
65
- // if ( files && files.length > 0 ) {
66
- // return true
67
- // }
68
- // return false
69
-
70
36
  // For the time being, return false, and let gcloud skip existing files in upload-time.
37
+ // It's pretty slow, might be worth to break down the directory into individual artifacts
38
+ // and manage each one with its own pusher.
71
39
  return false
72
40
  }
73
41
 
@@ -114,13 +82,16 @@ class GenericArtifactPackager extends ArtifactPackager {
114
82
  throw error
115
83
  }
116
84
  }
117
-
118
- async build() {
119
- return true
120
- }
121
85
 
122
- async publish() {
86
+ async push() {
123
87
  console.log( 'Publishing artifact to registry...' )
88
+
89
+ if ( await this.exists() ) {
90
+ console.log( 'Artifact already exists in the registry' )
91
+ return false
92
+ }
93
+
94
+ console.log( 'Uploading artifact to registry...' )
124
95
 
125
96
  let command = ''
126
97
 
@@ -157,4 +128,4 @@ class GenericArtifactPackager extends ArtifactPackager {
157
128
  }
158
129
  }
159
130
 
160
- export { ArtifactPackager, GenericArtifactPackager }
131
+ export { ArtifactPusher, GenericArtifactPusher }
@@ -1,11 +1,13 @@
1
1
  import { assign, object, string, array, optional, enums, union } from 'superstruct'
2
2
 
3
- const ArtifactTypeEnum = enums( [ 'generic' ] )
3
+ const ArtifactTypeEnum = {
4
+ GENERIC : 'generic',
5
+ }
4
6
 
5
7
  // Superstruct schema for individual artifact configuration
6
- const PartialArtifactEntrySchema = object( {
8
+ const PartialArtifactSchema = object( {
7
9
  name : string(),
8
- type : optional( ArtifactTypeEnum ),
10
+ type : optional( enums( Object.values( ArtifactTypeEnum ) ) ),
9
11
  gcp_project_id : optional( string() ),
10
12
  gcp_location : optional( string() ),
11
13
  gcp_artifact_registry_repository_name : optional( string() ),
@@ -13,9 +15,9 @@ const PartialArtifactEntrySchema = object( {
13
15
  gcp_artifact_registry_package_version : optional( string() )
14
16
  } )
15
17
 
16
- const ArtifactEntrySchema = assign( PartialArtifactEntrySchema, object( {
18
+ const ArtifactSchema = assign( PartialArtifactSchema, object( {
17
19
  name : string(),
18
- type : ArtifactTypeEnum,
20
+ type : enums( Object.values( ArtifactTypeEnum ) ),
19
21
  gcp_project_id : string(),
20
22
  gcp_location : string(),
21
23
  gcp_artifact_registry_repository_name : string(),
@@ -23,13 +25,13 @@ const ArtifactEntrySchema = assign( PartialArtifactEntrySchema, object( {
23
25
  gcp_artifact_registry_package_version : string()
24
26
  } ) )
25
27
 
26
- const PartialGenericArtifactEntrySchema = assign( PartialArtifactEntrySchema, object( {
27
- type : enums( [ 'generic' ] ),
28
+ const PartialGenericArtifactSchema = assign( PartialArtifactSchema, object( {
29
+ type : enums( [ ArtifactTypeEnum.GENERIC ] ),
28
30
  source_path : string(),
29
31
  destination_path : string()
30
32
  } ) )
31
33
 
32
- const GenericArtifactEntrySchema = assign( ArtifactEntrySchema, object( {
34
+ const GenericArtifactSchema = assign( ArtifactSchema, object( {
33
35
  source_path : string(),
34
36
  destination_path : optional( string() )
35
37
  } ) )
@@ -44,17 +46,18 @@ const DefaultsSchema = object( {
44
46
  } )
45
47
 
46
48
  // Superstruct schema for the complete artifacts configuration with defaults
47
- const ArtifactEntriesSchema = object( {
48
- defaults : DefaultsSchema,
49
- artifacts : array( union( [ PartialArtifactEntrySchema, PartialGenericArtifactEntrySchema ] ) )
49
+ const ArtifactsSchema = object( {
50
+ defaults : optional( DefaultsSchema ),
51
+ artifacts : array( union( [ PartialArtifactSchema, PartialGenericArtifactSchema ] ) )
50
52
  } )
51
53
 
52
- const FlattenedArtifactEntriesSchema = array( assign( union( [ ArtifactEntrySchema, GenericArtifactEntrySchema ] ) ) )
54
+ const FlattenedArtifactsSchema = array( assign( union( [ ArtifactSchema, GenericArtifactSchema ] ) ) )
53
55
 
54
56
  export {
55
- ArtifactEntriesSchema,
56
- FlattenedArtifactEntriesSchema,
57
- ArtifactEntrySchema,
57
+ ArtifactTypeEnum,
58
+ ArtifactsSchema,
59
+ FlattenedArtifactsSchema,
60
+ ArtifactSchema,
58
61
  DefaultsSchema,
59
- GenericArtifactEntrySchema,
62
+ GenericArtifactSchema,
60
63
  }
@@ -2,18 +2,18 @@ import { validate } from 'superstruct'
2
2
 
3
3
  import { parseYamlFile, warning } from '../Utils.mjs'
4
4
 
5
- import { ArtifactEntriesSchema, GenericArtifactEntrySchema } from './Structs.mjs'
5
+ import { ArtifactTypeEnum, ArtifactsSchema, GenericArtifactSchema } from './Structs.mjs'
6
6
 
7
- const getArtifactEntriesSchema = async ( artifactsConfigPath = './artifacts.yml' ) => {
8
- const artifactsConfig = await parseYamlFile( artifactsConfigPath )
9
- const [ error, result ] = validate( artifactsConfig, ArtifactEntriesSchema )
7
+ const getArtifactsSchema = async ( artifactsFilePath = './artifacts.yml' ) => {
8
+ const artifactsConfig = await parseYamlFile( artifactsFilePath )
9
+ const [ error, result ] = validate( artifactsConfig, ArtifactsSchema )
10
10
  if ( error ) {
11
11
  throw new Error( `Invalid artifacts.yml file: ${error.message}` )
12
12
  }
13
13
  return result
14
14
  }
15
15
 
16
- const flattenArtifactEntriesSchema = ( artifactsSchema ) => {
16
+ const flattenArtifactsSchema = ( artifactsSchema ) => {
17
17
  return artifactsSchema.artifacts.reduce( ( flattenedArtifacts, artifact ) => {
18
18
  const mergedArtifact = {
19
19
  ...artifactsSchema.defaults,
@@ -22,8 +22,8 @@ const flattenArtifactEntriesSchema = ( artifactsSchema ) => {
22
22
 
23
23
  let schema
24
24
  switch ( mergedArtifact.type ) {
25
- case 'generic':
26
- schema = GenericArtifactEntrySchema
25
+ case ArtifactTypeEnum.GENERIC:
26
+ schema = GenericArtifactSchema
27
27
  break
28
28
  default:
29
29
  warning( `Unsupported artifact type "${mergedArtifact.type}"` )
@@ -46,4 +46,4 @@ const flattenArtifactEntriesSchema = ( artifactsSchema ) => {
46
46
  }, [] )
47
47
  }
48
48
 
49
- export { getArtifactEntriesSchema, flattenArtifactEntriesSchema }
49
+ export { getArtifactsSchema, flattenArtifactsSchema }
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+
3
+ async function main() {
4
+ return null
5
+ }
6
+
7
+ main()
@@ -2,8 +2,9 @@
2
2
 
3
3
  import { warning } from '../Utils.mjs'
4
4
 
5
- import { getArtifactEntriesSchema, flattenArtifactEntriesSchema } from './Utils.mjs'
6
- import { GenericArtifactPackager } from './Packager.mjs'
5
+ import { getArtifactsSchema, flattenArtifactsSchema } from './Utils.mjs'
6
+ import { ArtifactTypeEnum } from './Structs.mjs'
7
+ import { GenericArtifactPusher } from './ArtifactPusher.mjs'
7
8
 
8
9
  async function main() {
9
10
 
@@ -13,8 +14,8 @@ async function main() {
13
14
  const artifactPackageVersion = process.argv[4]
14
15
 
15
16
  if ( artifactsYmlPath ) {
16
- const artifactsSchema = await getArtifactEntriesSchema( artifactsYmlPath )
17
- const flattenedArtifactsSchema = flattenArtifactEntriesSchema( artifactsSchema )
17
+ const artifactsSchema = await getArtifactsSchema( artifactsYmlPath )
18
+ const flattenedArtifactsSchema = flattenArtifactsSchema( artifactsSchema )
18
19
 
19
20
  // Open for unexpected matches if we end up re-using the same package name and version for
20
21
  // multiple artifacts spread across multiple repositories and/or projects.
@@ -23,7 +24,7 @@ async function main() {
23
24
  artifact.gcp_artifact_registry_package_version === artifactPackageVersion )
24
25
 
25
26
  if ( filteredArtifactSchemas.length === 0 ) {
26
- console.error( `No artifact entries found for ${artifactPackageName} version ${artifactPackageVersion} in ${artifactsYmlPath}` )
27
+ console.error( `No artifacts found for ${artifactPackageName} version ${artifactPackageVersion} in ${artifactsYmlPath}` )
27
28
  process.exit( 1 )
28
29
  }
29
30
 
@@ -31,8 +32,8 @@ async function main() {
31
32
  for ( const artifactSchema of filteredArtifactSchemas ) {
32
33
  let packager
33
34
  switch ( artifactSchema.type ) {
34
- case 'generic':
35
- packager = new GenericArtifactPackager( artifactSchema )
35
+ case ArtifactTypeEnum.GENERIC:
36
+ packager = new GenericArtifactPusher( artifactSchema )
36
37
  break
37
38
  default:
38
39
  warning( `Unsupported artifact type "${artifactSchema.type}"` )