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