@@ -2,36 +2,64 @@ 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 ] ;
13
+
7
14
console . log ( `Packing nativescript-angular package with @nativescript/angular: ${ scopedVersion } ` ) ;
8
15
9
16
const distFolderPath = path . resolve ( "../../dist" ) ;
10
17
const tempFolderPath = path . resolve ( "./temp-compat" ) ;
11
18
const outFileName = "nativescript-angular-compat.tgz" ;
12
19
20
+ const nsAngularScopedPackageJSONPath = path . resolve ( "../../nativescript-angular/package.json" ) ;
13
21
const nsAngularPackagePath = path . resolve ( "../../nativescript-angular-package" ) ;
14
22
const packageJsonPath = path . resolve ( `${ nsAngularPackagePath } /package.json` ) ;
15
23
console . log ( "Getting package.json from" , packageJsonPath ) ;
16
24
17
- let npmInstallParams = "" ;
18
- if ( scopedVersion . indexOf ( ".tgz" ) > 0 ) {
19
- // rewrite dependency in package.json
25
+
26
+ function prepareCompatPackageJSON ( scopedVersion : string ) {
20
27
const packageJsonObject = JSON . parse ( fs . readFileSync ( packageJsonPath , { encoding : "utf8" } ) ) ;
21
28
packageJsonObject . dependencies [ "@nativescript/angular" ] = scopedVersion ;
22
29
fs . writeFileSync ( packageJsonPath , JSON . stringify ( packageJsonObject , null , 4 ) ) ;
23
- } else {
24
- npmInstallParams = `@nativescript/angular@${ scopedVersion } ` ;
25
30
}
26
31
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
+ }
30
53
31
54
// ensure empty temp and existing dist folders
32
55
fs . emptyDirSync ( tempFolderPath ) ;
33
56
fs . ensureDirSync ( distFolderPath ) ;
34
57
58
+ // Install, run tsc and run ngc
59
+ execSync ( `npm i && tsc && npm run ngc` , {
60
+ cwd : nsAngularPackagePath
61
+ } ) ;
62
+
35
63
// create .tgz in temp folder
36
64
execSync ( `npm pack ${ nsAngularPackagePath } ` , {
37
65
cwd : tempFolderPath
0 commit comments