opencv-build
Advanced tools
Comparing version 0.1.8 to 0.1.9
@@ -10,2 +10,4 @@ import { AutoBuildFile } from './types'; | ||
export declare function readAutoBuildFile(): AutoBuildFile | undefined; | ||
export declare function readEnvsFromPackageJson(): void; | ||
export declare function getCwd(): string; | ||
export declare function readEnvsFromPackageJson(): any; | ||
export declare function applyEnvsFromPackageJson(): void; |
@@ -59,31 +59,39 @@ "use strict"; | ||
exports.readAutoBuildFile = readAutoBuildFile; | ||
function getCwd() { | ||
var cwd = process.env.INIT_CWD || process.cwd(); | ||
if (!cwd) { | ||
throw new Error('process.env.INIT_CWD || process.cwd() is undefined or empty'); | ||
} | ||
return cwd; | ||
} | ||
exports.getCwd = getCwd; | ||
function parsePackageJson() { | ||
if (!process.env.INIT_CWD) { | ||
log.error('process.env.INIT_CWD is undefined or empty'); | ||
return; | ||
} | ||
var absPath = path.resolve(process.env.INIT_CWD, 'package.json'); | ||
var absPath = path.resolve(getCwd(), 'package.json'); | ||
if (!fs.existsSync(absPath)) { | ||
log.info('No package.json in folder.'); | ||
return; | ||
return null; | ||
} | ||
return JSON.parse(fs.readFileSync(absPath).toString()); | ||
} | ||
function readEnvsFromPackageJson() { | ||
var rootPackageJSON = parsePackageJson(); | ||
return rootPackageJSON | ||
? (rootPackageJSON.opencv4nodejs || {}) | ||
: {}; | ||
} | ||
exports.readEnvsFromPackageJson = readEnvsFromPackageJson; | ||
function applyEnvsFromPackageJson() { | ||
var envs = {}; | ||
try { | ||
return JSON.parse(fs.readFileSync(absPath).toString()); | ||
envs = readEnvsFromPackageJson(); | ||
} | ||
catch (error) { | ||
catch (err) { | ||
log.error('failed to parse package.json:'); | ||
log.error(error); | ||
log.error(err); | ||
} | ||
} | ||
function readEnvsFromPackageJson() { | ||
var rootPackageJSON = parsePackageJson(); | ||
if (!rootPackageJSON || !rootPackageJSON.opencv4nodejs) { | ||
return; | ||
} | ||
var envs = Object.keys(rootPackageJSON.opencv4nodejs); | ||
if (envs.length) { | ||
var envKeys = Object.keys(envs); | ||
if (envKeys.length) { | ||
log.info('the following opencv4nodejs environment variables are set in the package.json:'); | ||
envs.forEach(function (key) { return log.info(key + ": " + rootPackageJSON.opencv4nodejs[key]); }); | ||
envKeys.forEach(function (key) { return log.info(key + ": " + envs[key]); }); | ||
} | ||
var _a = rootPackageJSON.opencv4nodejs, autoBuildBuildCuda = _a.autoBuildBuildCuda, autoBuildFlags = _a.autoBuildFlags, autoBuildOpencvVersion = _a.autoBuildOpencvVersion, autoBuildWithoutContrib = _a.autoBuildWithoutContrib, disableAutoBuild = _a.disableAutoBuild, opencvIncludeDir = _a.opencvIncludeDir, opencvLibDir = _a.opencvLibDir, opencvBinDir = _a.opencvBinDir; | ||
var autoBuildBuildCuda = envs.autoBuildBuildCuda, autoBuildFlags = envs.autoBuildFlags, autoBuildOpencvVersion = envs.autoBuildOpencvVersion, autoBuildWithoutContrib = envs.autoBuildWithoutContrib, disableAutoBuild = envs.disableAutoBuild, opencvIncludeDir = envs.opencvIncludeDir, opencvLibDir = envs.opencvLibDir, opencvBinDir = envs.opencvBinDir; | ||
if (autoBuildFlags) { | ||
@@ -114,2 +122,2 @@ process.env.OPENCV4NODEJS_AUTOBUILD_FLAGS = autoBuildFlags; | ||
} | ||
exports.readEnvsFromPackageJson = readEnvsFromPackageJson; | ||
exports.applyEnvsFromPackageJson = applyEnvsFromPackageJson; |
export { opencvModules } from './constants'; | ||
export { isAutoBuildDisabled, readAutoBuildFile, readEnvsFromPackageJson } from './env'; | ||
export { isAutoBuildDisabled, readAutoBuildFile, readEnvsFromPackageJson, applyEnvsFromPackageJson } from './env'; | ||
export { isOSX, isWin, isUnix } from './utils'; | ||
@@ -4,0 +4,0 @@ export declare const opencvInclude: string; |
@@ -15,2 +15,3 @@ "use strict"; | ||
exports.readEnvsFromPackageJson = env_1.readEnvsFromPackageJson; | ||
exports.applyEnvsFromPackageJson = env_1.applyEnvsFromPackageJson; | ||
var utils_2 = require("./utils"); | ||
@@ -17,0 +18,0 @@ exports.isOSX = utils_2.isOSX; |
@@ -77,3 +77,3 @@ "use strict"; | ||
// apply these variables to the process environment | ||
env_1.readEnvsFromPackageJson(); | ||
env_1.applyEnvsFromPackageJson(); | ||
if (env_1.isAutoBuildDisabled()) { | ||
@@ -80,0 +80,0 @@ log.info('install', 'OPENCV4NODEJS_DISABLE_AUTOBUILD is set'); |
{ | ||
"name": "opencv-build", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "A simple script to auto build recent OpenCV + contrib version via npm", | ||
@@ -5,0 +5,0 @@ "main": "./build/index.js", |
@@ -30,6 +30,5 @@ [![Build Status](https://travis-ci.org/justadudewhohacks/npm-opencv-build.svg?branch=master)](http://travis-ci.org/justadudewhohacks/npm-opencv-build) | ||
{ | ||
... | ||
"opencv4nodejs": { | ||
"autoBuildFlags": "-DOPENCV_GENERATE_PKGCONFIG=ON -DOPENCV_PC_FILE_NAME=opencv.pc", | ||
"autoBuildOpenCVVersion": 4.1.0 | ||
"autoBuildOpencvVersion": "4.1.0" | ||
} | ||
@@ -36,0 +35,0 @@ } |
@@ -60,19 +60,16 @@ import * as fs from 'fs'; | ||
export function getCwd() { | ||
const cwd = process.env.INIT_CWD || process.cwd() | ||
if (!cwd) { | ||
throw new Error('process.env.INIT_CWD || process.cwd() is undefined or empty') | ||
} | ||
return cwd | ||
} | ||
function parsePackageJson() { | ||
if (!process.env.INIT_CWD) { | ||
log.error('process.env.INIT_CWD is undefined or empty') | ||
return | ||
} | ||
const absPath = path.resolve(process.env.INIT_CWD, 'package.json') | ||
const absPath = path.resolve(getCwd(), 'package.json') | ||
if (!fs.existsSync(absPath)) { | ||
log.info('No package.json in folder.') | ||
return | ||
return null | ||
} | ||
try { | ||
return JSON.parse(fs.readFileSync(absPath).toString()) | ||
} catch (error) { | ||
log.error('failed to parse package.json:') | ||
log.error(error) | ||
} | ||
return JSON.parse(fs.readFileSync(absPath).toString()) | ||
} | ||
@@ -82,10 +79,20 @@ | ||
const rootPackageJSON = parsePackageJson() | ||
if (!rootPackageJSON || !rootPackageJSON.opencv4nodejs) { | ||
return | ||
return rootPackageJSON | ||
? (rootPackageJSON.opencv4nodejs || {}) | ||
: {} | ||
} | ||
export function applyEnvsFromPackageJson() { | ||
let envs: any = {} | ||
try { | ||
envs = readEnvsFromPackageJson() | ||
} catch (err) { | ||
log.error('failed to parse package.json:') | ||
log.error(err) | ||
} | ||
const envs = Object.keys(rootPackageJSON.opencv4nodejs) | ||
if (envs.length) { | ||
const envKeys = Object.keys(envs) | ||
if (envKeys.length) { | ||
log.info('the following opencv4nodejs environment variables are set in the package.json:') | ||
envs.forEach(key => log.info(`${key}: ${rootPackageJSON.opencv4nodejs[key]}`)) | ||
envKeys.forEach(key => log.info(`${key}: ${envs[key]}`)) | ||
} | ||
@@ -102,3 +109,3 @@ | ||
opencvBinDir | ||
} = rootPackageJSON.opencv4nodejs | ||
} = envs | ||
@@ -105,0 +112,0 @@ if (autoBuildFlags) { |
@@ -7,6 +7,6 @@ import * as fs from 'fs'; | ||
import { getLibsFactory } from './getLibsFactory'; | ||
import { isOSX, isUnix, isWin } from './utils'; | ||
import { isOSX, isWin } from './utils'; | ||
export { opencvModules } from './constants'; | ||
export { isAutoBuildDisabled, readAutoBuildFile, readEnvsFromPackageJson } from './env'; | ||
export { isAutoBuildDisabled, readAutoBuildFile, readEnvsFromPackageJson, applyEnvsFromPackageJson } from './env'; | ||
export { isOSX, isWin, isUnix } from './utils'; | ||
@@ -13,0 +13,0 @@ export const opencvInclude = dirs.opencvInclude |
@@ -7,2 +7,3 @@ import * as fs from 'fs'; | ||
import { | ||
applyEnvsFromPackageJson, | ||
autoBuildFlags, | ||
@@ -13,3 +14,2 @@ isAutoBuildDisabled, | ||
readAutoBuildFile, | ||
readEnvsFromPackageJson, | ||
} from './env'; | ||
@@ -52,3 +52,3 @@ import { getLibsFactory } from './getLibsFactory'; | ||
// apply these variables to the process environment | ||
readEnvsFromPackageJson() | ||
applyEnvsFromPackageJson() | ||
@@ -55,0 +55,0 @@ if (isAutoBuildDisabled()) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
91872
1840
22
47