rnpm-plugin-windows
Version:
rnpm plugin that generates a Windows template project
43 lines (35 loc) • 1.49 kB
JavaScript
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
;
const Common = require('./common');
const chalk = require('chalk');
const execSync = require('child_process').execSync;
const path = require('path');
const REACT_NATIVE_WPF_GENERATE_PATH = function() {
return path.resolve(
process.cwd(),
'node_modules',
'react-native-windows',
'local-cli',
'generate-wpf.js'
);
};
module.exports = function (config, args, options) {
const name = args[0] ? args[0] : Common.getReactNativeAppName();
const ns = options.namespace ? options.namespace : name;
const version = options.windowsVersion ? options.windowsVersion : Common.getReactNativeVersion();
// If the template is not set, look for a stable or 'rc' version
const template = options.template ? options.template : 'rc';
return Common.getInstallPackage(version, template)
.then(rnwPackage => {
console.log(`Installing ${rnwPackage}...`);
const pkgmgr = Common.isGlobalCliUsingYarn(process.cwd()) ? 'yarn add' : 'npm install --save';
const execOptions = options.verbose ? { stdio: 'inherit' } : {};
execSync(`${pkgmgr} ${rnwPackage}`, execOptions);
console.log(chalk.green(`${rnwPackage} successfully installed.`));
const generateWPF = require(REACT_NATIVE_WPF_GENERATE_PATH());
generateWPF(process.cwd(), name, ns, options);
}).catch(error => console.error(chalk.red(error.message)));
};