33const BbPromise = require ( 'bluebird' ) ;
44const program = require ( 'child_process' ) ;
55
6+ function getLambdaPackageFlags ( service ) {
7+
8+ let myFramework = '' ;
9+ var frameworkList = {
10+ "dotnet6" : "net6.0" //can add more mappings for more support
11+ } ;
12+ if ( service . provider . runtime && frameworkList [ service . provider . runtime ] ) {
13+ myFramework = ' -f ' + frameworkList [ service . provider . runtime ] ;
14+ }
15+ let architecture = '' ;
16+ if ( service . provider . architecture ) {
17+ architecture = ' -farch ' + service . provider . architecture
18+ }
19+ return architecture + myFramework ;
20+ }
621module . exports = {
722
823 getPackingInfo ( ) {
9-
1024 let service = this . serverless . service ;
11-
1225 const packages = service . getAllFunctions ( ) . reduce ( ( dotnetPackages , funcName ) => {
1326 let func = service . getFunction ( funcName ) ;
1427
@@ -18,14 +31,14 @@ module.exports = {
1831
1932 return dotnetPackages ;
2033 } , [ ] )
21-
34+
2235 let dicArtifacts = { } ;
2336
2437 packages . forEach ( p => {
2538
2639 const projectFolder = p . projectFolder || "" ;
2740 // Validate artifact starts with project folder
28- if ( projectFolder && ! p . artifact . startsWith ( projectFolder ) ) {
41+ if ( projectFolder && ! p . artifact . startsWith ( projectFolder ) ) {
2942 const error = `Serverless DotNet: function/package/projectFolder '${ projectFolder } ' is defined and should be root of function/package/artifact path '${ p . artifact } '. Pleas update your configuration...` ;
3043 throw new Error ( error ) ;
3144 }
@@ -39,10 +52,6 @@ module.exports = {
3952 // subtract project folder from the artifact path
4053 let artifactLessProjectFolderParts = [ ...artifactPathParts ] ;
4154 artifactLessProjectFolderParts . splice ( 0 , cwdParts . length ) ;
42- // console.log('artifact: ' +p.artifact);
43- // console.log('artifact parts: ' +artifactPathParts);
44- // console.log('cwd parts: ' +cwdParts);
45- // console.log('artifact less cwd parts: ' +artifactLessProjectFolderParts);
4655
4756 dicArtifacts [ p . artifact ] = {
4857 currentWorkingDir : cwd ,
@@ -61,33 +70,33 @@ module.exports = {
6170 if ( ! providerRuntime && ! funcRuntime ) {
6271 console . error ( 'No runtime found at global provider or local function level, eg. dotnetcore2.1' )
6372 }
64-
73+
6574 return ( providerRuntime && providerRuntime . startsWith ( 'dotnet' ) && ! funcRuntime )
66- || ( funcRuntime && funcRuntime . startsWith ( 'dotnet' ) )
67- || ( ! providerRuntime && funcRuntime && funcRuntime . startsWith ( 'dotnet' ) ) ;
75+ || ( funcRuntime && funcRuntime . startsWith ( 'dotnet' ) )
76+ || ( ! providerRuntime && funcRuntime && funcRuntime . startsWith ( 'dotnet' ) ) ;
6877 } ,
6978
7079 pack ( ) {
7180 let cli = this . serverless . cli ;
81+ let flags = getLambdaPackageFlags ( this . serverless . service )
7282 cli . log ( 'Serverless DotNet: Pack' ) ;
73-
7483 const dicArtifacts = this . getPackingInfo ( ) ;
75-
7684 var promises = Object . entries ( dicArtifacts ) . map ( kv => {
7785 return new BbPromise ( function ( resolve , reject ) {
7886
7987 try {
8088 const packingInfo = kv [ 1 ] ;
8189
82- var output = program . execSync ( 'dotnet lambda package -o ' + packingInfo . artifactOutput , { "cwd" : packingInfo . currentWorkingDir } , function ( error , stdout , stderr ) {
83- // console.log(stdout);
90+ var output = program . execSync ( 'dotnet lambda package ' + flags + ' -o ' + packingInfo . artifactOutput , { "cwd" : packingInfo . currentWorkingDir } , function ( error , stdout , stderr ) {
91+ console . log ( output )
8492 cli . log ( stdout ) ;
8593
8694 if ( error ) {
8795 console . error ( 'An error occured while restoring packages' ) ;
88- console . error ( stderr . toString ( 'utf8' ) ) ;
89- process . exit ( error . code ) ;
90- return reject ( error ) ;
96+ console . error ( err . stdout . toString ( 'utf8' ) ) ;
97+ console . error ( err . toString ( 'utf8' ) ) ;
98+ process . exit ( ) ;
99+ return reject ( err ) ;
91100 }
92101
93102 console . log ( 'Publishing' ) ;
@@ -96,7 +105,7 @@ module.exports = {
96105 } ) ;
97106
98107 cli . log ( output ) ;
99- return resolve ( ) ;
108+ return resolve ( ) ;
100109 } catch ( err ) {
101110 console . error ( 'An error occured while restoring packages' ) ;
102111 console . error ( err . stdout . toString ( 'utf8' ) ) ;
0 commit comments