@@ -19,10 +19,10 @@ public sealed class Pack : Command
19
19
public string Manifest { get ; set ; }
20
20
21
21
[ DisplayName ( "source" ) ]
22
- [ Description ( "Directory containing files to add to the package." ) ]
22
+ [ Description ( "File or directory containing files to add to the package." ) ]
23
23
[ PositionalArgument ( 0 ) ]
24
24
[ ExpandPath ]
25
- public string SourceDirectory { get ; set ; }
25
+ public string SourcePath { get ; set ; }
26
26
27
27
[ DisplayName ( "targetDirectory" ) ]
28
28
[ Description ( "Directory where the .upack file will be created. If not specified, the current working directory is used." ) ]
@@ -126,30 +126,40 @@ public override async Task<int> RunAsync(CancellationToken cancellationToken)
126
126
info [ "createdBy" ] = Environment . UserName ;
127
127
}
128
128
129
- if ( ! Directory . Exists ( this . SourceDirectory ) )
129
+ if ( ! Directory . Exists ( this . SourcePath ) && ! File . Exists ( this . SourcePath ) )
130
130
{
131
- Console . Error . WriteLine ( $ "The source directory '{ this . SourceDirectory } ' does not exist.") ;
131
+ Console . Error . WriteLine ( $ "The source directory '{ this . SourcePath } ' does not exist.") ;
132
132
return 2 ;
133
133
}
134
134
135
135
string relativePackageFileName = $ "{ info . Name } -{ info . Version . Major } .{ info . Version . Minor } .{ info . Version . Patch } .upack";
136
136
string targetFileName = Path . Combine ( this . TargetDirectory ?? Environment . CurrentDirectory , relativePackageFileName ) ;
137
137
138
- if ( File . Exists ( Path . Combine ( this . SourceDirectory , relativePackageFileName ) ) )
138
+ if ( File . Exists ( Path . Combine ( this . SourcePath , relativePackageFileName ) ) )
139
139
{
140
140
Console . Error . WriteLine ( "Warning: output file already exists in source directory and may be included inadvertently in the package contents." ) ;
141
141
}
142
142
143
143
string tmpPath = Path . GetTempFileName ( ) ;
144
144
using ( var builder = new UniversalPackageBuilder ( tmpPath , info ) )
145
145
{
146
- await builder . AddContentsAsync (
147
- this . SourceDirectory ,
148
- "/" ,
149
- true ,
150
- s => string . IsNullOrWhiteSpace ( this . Manifest ) || ! string . Equals ( s , "upack.json" , StringComparison . OrdinalIgnoreCase ) ,
151
- cancellationToken
152
- ) ;
146
+ if ( Directory . Exists ( this . SourcePath ) )
147
+ {
148
+ await builder . AddContentsAsync (
149
+ this . SourcePath ,
150
+ "/" ,
151
+ true ,
152
+ s => string . IsNullOrWhiteSpace ( this . Manifest ) || ! string . Equals ( s , "upack.json" , StringComparison . OrdinalIgnoreCase ) ,
153
+ cancellationToken
154
+ ) ;
155
+ }
156
+ else
157
+ {
158
+ using ( var file = File . Open ( this . SourcePath , FileMode . Open , FileAccess . Read , FileShare . Read ) )
159
+ {
160
+ await builder . AddFileAsync ( file , Path . GetFileName ( this . SourcePath ) , File . GetLastWriteTimeUtc ( this . SourcePath ) , cancellationToken ) ;
161
+ }
162
+ }
153
163
}
154
164
155
165
Directory . CreateDirectory ( Path . GetDirectoryName ( targetFileName ) ) ;
0 commit comments