@@ -2,35 +2,54 @@ import * as path from "path";
22import * as fs from "fs-extra" ;
33import { execSync } from "child_process" ;
44
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+
612var scopedVersion = process . argv [ 2 ] ;
7- var skipInstall = process . argv [ 3 ] ;
13+
814console . log ( `Packing nativescript-angular package with @nativescript/angular: ${ scopedVersion } ` ) ;
915
1016const distFolderPath = path . resolve ( "../../dist" ) ;
1117const tempFolderPath = path . resolve ( "./temp-compat" ) ;
1218const outFileName = "nativescript-angular-compat.tgz" ;
1319
20+ const nsAngularScopedPackageJSONPath = path . resolve ( "../../nativescript-angular/package.json" ) ;
1421const nsAngularPackagePath = path . resolve ( "../../nativescript-angular-package" ) ;
1522const packageJsonPath = path . resolve ( `${ nsAngularPackagePath } /package.json` ) ;
1623console . log ( "Getting package.json from" , packageJsonPath ) ;
1724
18- let npmInstallParams = "" ;
1925
20- if ( scopedVersion . indexOf ( ".tgz" ) > 0 || skipInstall === "no-save-exact" ) {
21- // rewrite dependency in package.json
26+ function prepareCompatPackageJSON ( scopedVersion : string ) {
2227 const packageJsonObject = JSON . parse ( fs . readFileSync ( packageJsonPath , { encoding : "utf8" } ) ) ;
2328 packageJsonObject . dependencies [ "@nativescript/angular" ] = scopedVersion ;
2429 fs . writeFileSync ( packageJsonPath , JSON . stringify ( packageJsonObject , null , 4 ) ) ;
25- } else {
26- npmInstallParams = `@nativescript/angular@${ scopedVersion } ` ;
2730}
2831
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+
3049 execSync ( `npm install --save-exact ${ npmInstallParams } ` , {
3150 cwd : nsAngularPackagePath
3251 } ) ;
33- }
52+ }
3453
3554// ensure empty temp and existing dist folders
3655fs . emptyDirSync ( tempFolderPath ) ;
0 commit comments