@@ -2,35 +2,54 @@ import * as path from "path";
2
2
import * as fs from "fs-extra" ;
3
3
import { execSync } from "child_process" ;
4
4
5
- // var myArgs = process.argv.slice(2);
5
+ /**
6
+ * Use this script to pack .tgz for nativescript-angular package. The first passed param can be:
7
+ * 1. Path to .tgz file - in this case the script replaces the scoped dependency (@nativescript/angular) with it in the package.json file. Then packs.
8
+ * 2. Tag or exact version - in this case the script does `npm install --save-exact` to save the exact version (in case if tag). Then packs.
9
+ * 3. `auto-version` - this is interpreted by getting version from the scoped package.json file (nativescript-angular folder).
10
+ */
11
+
6
12
var scopedVersion = process . argv [ 2 ] ;
7
- var skipInstall = process . argv [ 3 ] ;
13
+
8
14
console . log ( `Packing nativescript-angular package with @nativescript/angular: ${ scopedVersion } ` ) ;
9
15
10
16
const distFolderPath = path . resolve ( "../../dist" ) ;
11
17
const tempFolderPath = path . resolve ( "./temp-compat" ) ;
12
18
const outFileName = "nativescript-angular-compat.tgz" ;
13
19
20
+ const nsAngularScopedPackageJSONPath = path . resolve ( "../../nativescript-angular/package.json" ) ;
14
21
const nsAngularPackagePath = path . resolve ( "../../nativescript-angular-package" ) ;
15
22
const packageJsonPath = path . resolve ( `${ nsAngularPackagePath } /package.json` ) ;
16
23
console . log ( "Getting package.json from" , packageJsonPath ) ;
17
24
18
- let npmInstallParams = "" ;
19
25
20
- if ( scopedVersion . indexOf ( ".tgz" ) > 0 || skipInstall === "no-save-exact" ) {
21
- // rewrite dependency in package.json
26
+ function prepareCompatPackageJSON ( scopedVersion : string ) {
22
27
const packageJsonObject = JSON . parse ( fs . readFileSync ( packageJsonPath , { encoding : "utf8" } ) ) ;
23
28
packageJsonObject . dependencies [ "@nativescript/angular" ] = scopedVersion ;
24
29
fs . writeFileSync ( packageJsonPath , JSON . stringify ( packageJsonObject , null , 4 ) ) ;
25
- } else {
26
- npmInstallParams = `@nativescript/angular@${ scopedVersion } ` ;
27
30
}
28
31
29
- if ( skipInstall !== "no-save-exact" ) {
32
+ if ( scopedVersion === "auto-version" ) {
33
+ // We use this when build for release. In this case we need to get version from scoped package (nativescript-angular)
34
+ // and use it in the compat package.
35
+
36
+ scopedVersion = JSON . parse ( fs . readFileSync ( nsAngularScopedPackageJSONPath , { encoding : "utf8" } ) ) . version ;
37
+ prepareCompatPackageJSON ( scopedVersion )
38
+ } else {
39
+ let npmInstallParams = "" ;
40
+
41
+ if ( scopedVersion . indexOf ( ".tgz" ) > 0 ) {
42
+ // If building with .tgz, we need to update the package.json of the compat package
43
+ prepareCompatPackageJSON ( scopedVersion )
44
+ } else {
45
+ // If building with tag or exact version, just install it with --save-exact
46
+ npmInstallParams = `@nativescript/angular@${ scopedVersion } ` ;
47
+ }
48
+
30
49
execSync ( `npm install --save-exact ${ npmInstallParams } ` , {
31
50
cwd : nsAngularPackagePath
32
51
} ) ;
33
- }
52
+ }
34
53
35
54
// ensure empty temp and existing dist folders
36
55
fs . emptyDirSync ( tempFolderPath ) ;
0 commit comments