|
| 1 | +/** |
| 2 | + * Copyright (c) 2015-present, Facebook, Inc. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. An additional grant |
| 7 | + * of patent rights can be found in the PATENTS file in the same directory. |
| 8 | + */ |
| 9 | +'use strict'; |
| 10 | + |
| 11 | +const findWindowsSolution = require('./findWindowsSolution'); |
| 12 | +const findNamespace = require('./findNamespace'); |
| 13 | +const findProject = require('./findProject'); |
| 14 | +const findDependencyProject = require('./findDependencyProject'); |
| 15 | +const findProjectName = require('./findProjectName'); |
| 16 | +const findProjectGUID = require('./findProjectGUID'); |
| 17 | +const findPackageClassName = require('./findPackageClassName'); |
| 18 | +const findMainFile = require('./findMainFile'); |
| 19 | +const path = require('path'); |
| 20 | + |
| 21 | +const relativeProjectPath = (fullProjPath) => { |
| 22 | + const windowsPath = fullProjPath |
| 23 | + .substring(fullProjPath.lastIndexOf("node_modules") - 1, fullProjPath.length) |
| 24 | + .replace(/\//g, '\\'); |
| 25 | + |
| 26 | + return path.join('..', windowsPath); |
| 27 | +}; |
| 28 | + |
| 29 | +/** |
| 30 | + * Gets windows project config by analyzing given folder and taking some |
| 31 | + * defaults specified by user into consideration |
| 32 | + */ |
| 33 | +exports.projectConfig = function projectConfigWindows(folder, userConfig) { |
| 34 | + |
| 35 | + const csSolution = userConfig.csSolution || findWindowsSolution(folder); |
| 36 | + const projectPath = userConfig.projectPath || findProject(folder); |
| 37 | + |
| 38 | + if (!csSolution || !projectPath) { |
| 39 | + return null; |
| 40 | + } |
| 41 | + |
| 42 | + // expects solutions to be named the same as project folders |
| 43 | + const solutionPath = path.join(folder, csSolution); |
| 44 | + const sourceDir = userConfig.sourceDir || path.dirname(projectPath); |
| 45 | + const mainFilePath = findMainFile(sourceDir); |
| 46 | + |
| 47 | + return { |
| 48 | + sourceDir, |
| 49 | + solutionPath, |
| 50 | + projectPath, |
| 51 | + mainFilePath, |
| 52 | + folder, |
| 53 | + userConfig, |
| 54 | + }; |
| 55 | +}; |
| 56 | + |
| 57 | +/** |
| 58 | + * Same as projectConfigWindows except it returns |
| 59 | + * different config that applies to packages only |
| 60 | + */ |
| 61 | +exports.dependencyConfig = function dependencyConfigWindows(folder, userConfig) { |
| 62 | + |
| 63 | + const projectPath = userConfig.projectPath || findDependencyProject(folder); |
| 64 | + |
| 65 | + if (!projectPath) { |
| 66 | + return null; |
| 67 | + } |
| 68 | + |
| 69 | + const sourceDir = userConfig.sourceDir || path.dirname(projectPath); |
| 70 | + const packageClassName = findPackageClassName(sourceDir); |
| 71 | + const namespace = userConfig.namespace || findNamespace(sourceDir); |
| 72 | + |
| 73 | + /** |
| 74 | + * This module has no package to export or no namespace |
| 75 | + */ |
| 76 | + if (!packageClassName || !namespace) { |
| 77 | + return null; |
| 78 | + } |
| 79 | + |
| 80 | + const packageUsingPath = userConfig.packageUsingPath || |
| 81 | + `using ${namespace};`; |
| 82 | + |
| 83 | + const packageInstance = userConfig.packageInstance || |
| 84 | + `new ${packageClassName}()`; |
| 85 | + |
| 86 | + const projectGUID = findProjectGUID(projectPath); |
| 87 | + const projectName = findProjectName(projectPath); |
| 88 | + const relativeProjPath = relativeProjectPath(projectPath); |
| 89 | + |
| 90 | + return { |
| 91 | + sourceDir, |
| 92 | + packageUsingPath, |
| 93 | + packageInstance, |
| 94 | + projectName, |
| 95 | + projectPath, |
| 96 | + folder, |
| 97 | + projectGUID, |
| 98 | + relativeProjPath, |
| 99 | + }; |
| 100 | +}; |
| 101 | + |
0 commit comments