initial commit

This commit is contained in:
Volodymyr Kozieiev 2020-05-08 18:34:27 +03:00
parent 0a48445cbf
commit 5013901aba
No known key found for this signature in database
GPG Key ID: 82B04968DF4C0535
4 changed files with 111 additions and 0 deletions

5
bin.js Normal file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env node
// Yarn will fail to link workspace binaries if they haven't been built yet. Add
// a simple JS file to forward to the CLI which is built after install.
require('./src/cli');

25
package.json Normal file
View File

@ -0,0 +1,25 @@
{
"name": "react-native-desktop-qt-init",
"version": "0.1.0",
"description": "CLI to bootstrap the addition of desktop-qt platform to existing react-native project",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"bin": {
"react-native-desktop-qt-init": "./bin.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/vkjr/react-native-desktop-qt-init.git"
},
"author": "Volodymyr Kozieiev",
"license": "MIT",
"bugs": {
"url": "https://github.com/vkjr/react-native-desktop-qt-init/issues"
},
"homepage": "https://github.com/vkjr/react-native-desktop-qt-init#readme",
"dependencies": {
"chalk": "^1.1.3"
}
}

50
src/cli.js Normal file
View File

@ -0,0 +1,50 @@
'use strict';
const chalk = require('chalk');
const Common = require('./common');
const execSync = require('child_process').execSync;
const path = require('path');
const PACKAGE = "git+https://github.com/status-im/react-native-desktop-qt.git#v060";
const REACT_NATIVE_DESKTOP_GENERATE_PATH = function() {
return path.resolve(
process.cwd(),
'node_modules',
'react-native-desktop-qt',
'local-cli',
'generate-desktop.js'
);
};
function installDesktopPackage() {
let rndPackage = PACKAGE;
console.log(`Installing ${rndPackage}...`);
const pkgmgr = Common.isGlobalCliUsingYarn(process.cwd()) ? 'yarn add' : 'npm install --save';
const execOptions = {}; // use {stdio: 'inherit'} for verbose
execSync(`${pkgmgr} ${rndPackage}`, execOptions);
console.log(chalk.green(`${rndPackage} successfully installed.`));
}
function runDesktopFilesGenerationScript() {
const generateDesktop = require(REACT_NATIVE_DESKTOP_GENERATE_PATH());
generateDesktop(process.cwd(), Common.getReactNativeAppName());
}
(async () => {
try {
installDesktopPackage();
runDesktopFilesGenerationScript();
} catch (error) {
console.error(chalk.red(error.message));
console.error(error);
process.exit(1);
}
})();

31
src/common.js Normal file
View File

@ -0,0 +1,31 @@
'use strict';
const fs = require('fs');
const path = require('path');
const isGlobalCliUsingYarn = function(projectDir) {
return fs.existsSync(path.join(projectDir, 'yarn.lock'));
};
const getReactNativeAppName = function () {
console.log('Reading application name from package.json...');
let name = JSON.parse(fs.readFileSync('package.json', 'utf8')).name;
if (!name) {
if (fs.existsSync('app.json')) {
console.log('Reading application name from app.json...');
name = JSON.parse(fs.readFileSync('app.json', 'utf8')).name;
}
}
if (!name) {
console.error('Please specify name in package.json or app.json');
}
return name;
};
module.exports = {
isGlobalCliUsingYarn,
getReactNativeAppName,
};