diff --git a/bin/generate-android-snapshot b/bin/generate-android-snapshot old mode 100644 new mode 100755 diff --git a/bin/install-ns-webpack b/bin/install-ns-webpack old mode 100644 new mode 100755 diff --git a/bin/ns-bundle b/bin/ns-bundle index a5e4962d..d9ea61fb 100755 --- a/bin/ns-bundle +++ b/bin/ns-bundle @@ -6,9 +6,9 @@ const { existsSync } = require("fs"); const semver = require("semver"); -const { getPackageJson } = require("../projectHelpers"); +const { getPackageJson, getProjectDir } = require("../projectHelpers"); -const PROJECT_DIR = pathResolve(__dirname, "../../../"); +const PROJECT_DIR = getProjectDir({ nestingLvl: 2 }); const packageJson = getPackageJson(PROJECT_DIR); if (!process.env.npm_config_argv) { @@ -152,7 +152,9 @@ function webpack(platform, env) { console.log(`Running webpack for ${platform}...`); const args = [ - `webpack`, + `node`, + `--preserve-symlinks`, + `./node_modules/.bin/webpack`, `--config=webpack.config.js`, `--progress`, `--env.${platform}`, diff --git a/bin/ns-verify-bundle b/bin/ns-verify-bundle old mode 100644 new mode 100755 index 695767c4..7197f987 --- a/bin/ns-verify-bundle +++ b/bin/ns-verify-bundle @@ -3,7 +3,9 @@ const path = require("path"); const fs = require("fs"); -const PROJECT_DIR = path.resolve(__dirname, "../../../"); +const { getProjectDir } = require("../projectHelpers"); + +const PROJECT_DIR = getProjectDir({ nestingLvl: 2 }); const APP_ID = require(path.resolve(PROJECT_DIR, "./package.json")).nativescript.id; const APP_NAME = APP_ID.substring(APP_ID.lastIndexOf(".") + 1); const PROJECT_PATHS = { diff --git a/bin/remove-ns-webpack b/bin/remove-ns-webpack old mode 100644 new mode 100755 diff --git a/bin/update-ns-webpack b/bin/update-ns-webpack old mode 100644 new mode 100755 index e5971284..57c8427b --- a/bin/update-ns-webpack +++ b/bin/update-ns-webpack @@ -1,14 +1,15 @@ #!/usr/bin/env node const { resolve } = require("path"); -const { getPackageJson, writePackageJson } = require("../projectHelpers"); +const { getPackageJson, getProjectDir, writePackageJson } = require("../projectHelpers"); const { forceUpdateProjectDeps } = require("../dependencyManager"); const { editExistingProjectFiles } = require("../projectFilesManager"); -const PROJECT_DIR = resolve(__dirname, "../../../"); +const PROJECT_DIR = getProjectDir({ nestingLvl: 2 }); +const packageJson = getPackageJson(PROJECT_DIR); console.info("Updating dev dependencies..."); -const packageJson = getPackageJson(PROJECT_DIR); + const { deps } = forceUpdateProjectDeps(packageJson); packageJson.devDependencies = deps; writePackageJson(packageJson, PROJECT_DIR); diff --git a/index.js b/index.js index 298d1414..62d1ed5c 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,9 @@ const path = require("path"); const { existsSync } = require("fs"); -const { getPackageJson, isAngular } = require("./projectHelpers"); +const { getPackageJson, getProjectDir, isAngular } = require("./projectHelpers"); -const PROJECT_DIR = path.dirname(path.dirname(__dirname)); +const PROJECT_DIR = getProjectDir({ nestingLvl: 2 }); const APP_DIR = path.join(PROJECT_DIR, "app"); Object.assign(exports, require('./plugins')); diff --git a/installer.js b/installer.js index 043c616e..1dc53159 100644 --- a/installer.js +++ b/installer.js @@ -6,25 +6,7 @@ const projectFilesManager = require("./projectFilesManager"); const npmScriptsManager = require("./npmScriptsManager"); const dependencyManager = require("./dependencyManager"); -// INIT_CWD is available since npm 5.4 -const initCwd = process.env.INIT_CWD; -const shouldUseInitCwd = () => { - if (!initCwd) { - return false; - } - - const installedPackage = path.resolve(initCwd, "node_modules", "nativescript-dev-webpack"); - if (!fs.existsSync(installedPackage)) { - return false; - } - - const stat = fs.lstatSync(installedPackage); - return stat.isSymbolicLink(); -}; - -const PROJECT_DIR = shouldUseInitCwd() ? - initCwd : - path.dirname(path.dirname(__dirname)); +const PROJECT_DIR = helpers.getProjectDir({ nestingLvl: 2 }); const APP_DIR = path.resolve(PROJECT_DIR, "app"); function install() { diff --git a/projectHelpers.js b/projectHelpers.js index 9cd6c4ba..37268f0a 100644 --- a/projectHelpers.js +++ b/projectHelpers.js @@ -30,11 +30,36 @@ const writePackageJson = (content, projectDir) => { fs.writeFileSync(packageJsonPath, JSON.stringify(content, null, 2)) } +const getProjectDir = ({ nestingLvl } = { nestingLvl: 0 }) => { + // INIT_CWD is available since npm 5.4 + const initCwd = process.env.INIT_CWD; + const shouldUseInitCwd = (() => { + if (!initCwd) { + return false; + } + + const installedPackage = path.resolve(initCwd, "node_modules", "nativescript-dev-webpack"); + if (!fs.existsSync(installedPackage)) { + return false; + } + + const stat = fs.lstatSync(installedPackage); + return stat.isSymbolicLink(); + })(); + + return shouldUseInitCwd ? + initCwd : + Array + .from(Array(nestingLvl)) + .reduce(dir => path.dirname(dir), __dirname); +}; + const getPackageJsonPath = projectDir => path.resolve(projectDir, "package.json"); module.exports = { isTypeScript, isAngular, - getPackageJson, writePackageJson, + getPackageJson, + getProjectDir, };