@@ -2,36 +2,64 @@ 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 ] ;
13+
714console . log ( `Packing nativescript-angular package with @nativescript/angular: ${ scopedVersion } ` ) ;
815
916const distFolderPath = path . resolve ( "../../dist" ) ;
1017const tempFolderPath = path . resolve ( "./temp-compat" ) ;
1118const outFileName = "nativescript-angular-compat.tgz" ;
1219
20+ const nsAngularScopedPackageJSONPath = path . resolve ( "../../nativescript-angular/package.json" ) ;
1321const nsAngularPackagePath = path . resolve ( "../../nativescript-angular-package" ) ;
1422const packageJsonPath = path . resolve ( `${ nsAngularPackagePath } /package.json` ) ;
1523console . log ( "Getting package.json from" , packageJsonPath ) ;
1624
17- let npmInstallParams = "" ;
18- if ( scopedVersion . indexOf ( ".tgz" ) > 0 ) {
19- // rewrite dependency in package.json
25+
26+ function prepareCompatPackageJSON ( scopedVersion : string ) {
2027 const packageJsonObject = JSON . parse ( fs . readFileSync ( packageJsonPath , { encoding : "utf8" } ) ) ;
2128 packageJsonObject . dependencies [ "@nativescript/angular" ] = scopedVersion ;
2229 fs . writeFileSync ( packageJsonPath , JSON . stringify ( packageJsonObject , null , 4 ) ) ;
23- } else {
24- npmInstallParams = `@nativescript/angular@${ scopedVersion } ` ;
2530}
2631
27- execSync ( `npm install --save-exact ${ npmInstallParams } ` , {
28- cwd : nsAngularPackagePath
29- } ) ;
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+
49+ execSync ( `npm install --save-exact ${ npmInstallParams } ` , {
50+ cwd : nsAngularPackagePath
51+ } ) ;
52+ }
3053
3154// ensure empty temp and existing dist folders
3255fs . emptyDirSync ( tempFolderPath ) ;
3356fs . ensureDirSync ( distFolderPath ) ;
3457
58+ // Install, run tsc and run ngc
59+ execSync ( `npm i && tsc && npm run ngc` , {
60+ cwd : nsAngularPackagePath
61+ } ) ;
62+
3563// create .tgz in temp folder
3664execSync ( `npm pack ${ nsAngularPackagePath } ` , {
3765 cwd : tempFolderPath
0 commit comments