-
-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathpack-compat.ts
45 lines (36 loc) · 1.7 KB
/
pack-compat.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import * as path from "path";
import * as fs from "fs-extra";
import { execSync } from "child_process";
// var myArgs = process.argv.slice(2);
var scopedVersion = process.argv[2];
console.log(`Packing nativescript-angular package with @nativescript/angular: ${scopedVersion}`);
const distFolderPath = path.resolve("../../dist");
const tempFolderPath = path.resolve("./temp-compat");
const outFileName = "nativescript-angular-compat.tgz";
const nsAngularPackagePath = path.resolve("../../nativescript-angular-package");
const packageJsonPath = path.resolve(`${nsAngularPackagePath}/package.json`);
console.log("Getting package.json from", packageJsonPath);
let npmInstallParams = "";
if (scopedVersion.indexOf(".tgz") > 0) {
// rewrite dependency in package.json
const packageJsonObject = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: "utf8" }));
packageJsonObject.dependencies["@nativescript/angular"] = scopedVersion;
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJsonObject, null, 4));
} else {
npmInstallParams = `@nativescript/angular@${scopedVersion}`;
}
execSync(`npm install --save-exact ${npmInstallParams}`, {
cwd: nsAngularPackagePath
});
// ensure empty temp and existing dist folders
fs.emptyDirSync(tempFolderPath);
fs.ensureDirSync(distFolderPath);
// create .tgz in temp folder
execSync(`npm pack ${nsAngularPackagePath}`, {
cwd: tempFolderPath
});
// assume we have a single file built in temp folder, take its name
const currentFileName = fs.readdirSync(tempFolderPath)[0];
// move built file and remove temp folder
fs.moveSync(`${tempFolderPath}/${currentFileName}`, `${distFolderPath}/${outFileName}`, { overwrite: true });
fs.removeSync(`${tempFolderPath}`);