-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change list: 1. Creating a zero-configuration CLI. 2. Updated ReadMe with how to use the CLI. 3. Re-ordering directories and cleanup of unused code. 4. default rootElement now will be a new element instead of searching for an arbitrary className.
- Loading branch information
Showing
29 changed files
with
692 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
web: ./node_modules/.bin/rollup -c rollup-build.config.js -o dist/index.js -f iife -n UiZoo -g underscore:_,react:React,react-dom:ReactDOM,react-router-dom:ReactRouterDOM,doctrine:doctrine-standalone,babel-standalone:Babel && node server/main.js | ||
web: ./node_modules/.bin/rollup -c rollup.config.js -o dist/index.js -f iife -n UiZoo && node lib/server/main.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,40 +17,51 @@ This tool can be used for developing, for Product Managers to know what is possi | |
![React UiZoo 3](https://imgur.com/f3B2TDj.gif) | ||
|
||
## How To UiZoo? | ||
Git clone by: | ||
|
||
Just use our zero-configuration CLI! it's easy as pie! 🍽 | ||
|
||
``` | ||
git clone [email protected]:myheritage/uizoo.js.git | ||
npm i -g uizoo | ||
``` | ||
then | ||
|
||
In a directory, do: | ||
``` | ||
cd uizoo.js && npm i | ||
gulp | ||
uizoo | ||
``` | ||
This will start a server on http://localhost:5000 with the UiZoo | ||
you can change the [components file](https://github.com/myheritage/uizoo.js/blob/master/client/components.js) and the [documentation file](https://github.com/myheritage/uizoo.js/blob/master/client/documentation.js) to start rapidly. | ||
We recommend updating those files by a script automatically when files are changing (we plan to create plugins to help with this in the next future). | ||
|
||
*or* npm install by: | ||
It will create a [webpack development server](https://webpack.js.org/configuration/dev-server/) fully configured with [Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/) to watch your files while you develop! | ||
|
||
For example: | ||
|
||
![React UiZoo CLI](https://imgur.com/v3PbP8U.gif) | ||
|
||
Start the server with the newly added script: | ||
``` | ||
npm i -S uizoo | ||
npm start uizoo | ||
``` | ||
then in your code, add: | ||
|
||
### Customization | ||
The CLI creates a directory called `uizoo-app`, in it there is a file called `config.js` that determine basic stuff like the server's port, glob to find your components and more. There is also a very simple webpack configuration called `webpack.uizoo.js`. | ||
|
||
|
||
### Local installation | ||
*If you don't want to install UiZoo globally, you can instead do:* | ||
``` | ||
import 'uizoo/dist/index.css'; | ||
import UiZoo from 'uizoo'; | ||
UiZoo.init(documentation, components, rootElement); | ||
npm i -D uizoo && ./node_modules/.bin/uizoo | ||
``` | ||
|
||
### init | ||
### API | ||
``` | ||
import UiZoo from 'uizoo'; | ||
UiZoo.init(documentation: Object, components: Object, rootElement: HTMLElement?, baseRoute: String?) | ||
``` | ||
|
||
**documentation** - Object, mapping of component name to its documentation. See [example](https://github.com/myheritage/uizoo.js/blob/master/client/documentation.js). | ||
|
||
**components** - Object, mapping of components name to components. See [example](https://github.com/myheritage/uizoo.js/blob/master/client/components.js). | ||
|
||
**rootElement** - HTMLElement, will bootstrap UiZoo on that Element. Default is an element with the id 'library-_-root' | ||
**rootElement** - HTMLElement, will bootstrap UiZoo on that Element. Default is a new element on the body. | ||
|
||
**baseRoute** Route to be the base before the UiZoo routes. Default to '/'. for example if the UiZoo is on your site like so: 'www.mysite.com/my/zoo/', the base route should be '/my/zoo/'. | ||
|
||
|
@@ -108,7 +119,7 @@ To add tests, use the following steps - | |
|
||
First, make sure the app is up and running: | ||
``` | ||
gulp | ||
npm start | ||
``` | ||
The first time tests are run, install the npm dependencies: | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env node | ||
|
||
const chalk = require('chalk'); | ||
const logo = require('../lib/logo'); | ||
const log = console.log.bind(console); | ||
|
||
log(` | ||
Welcome to the ~ | ||
${chalk.bold(chalk.cyan(logo))} | ||
`); | ||
|
||
require('../lib/generate')(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
client/Components/UI/Tooltip/autoLocationDetector/autoLocationDetector.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import _ from 'underscore'; | ||
import { | ||
SIDE_TOP, | ||
SIDE_BOTTOM, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const path = require('path'); | ||
|
||
const appFolderPath = path.resolve('uizoo-app'); | ||
const uiZooScript = `node ${path.join('uizoo-app', 'webpack.uizoo.js')}`; | ||
|
||
const neededPackages = [ | ||
'uizoo', | ||
'webpack', | ||
'webpack-dev-server', | ||
'babel-loader', | ||
'babel-preset-env', | ||
'babel-preset-react', | ||
'babel-plugin-transform-object-rest-spread', | ||
'babel-plugin-syntax-dynamic-import', | ||
'style-loader', | ||
'css-loader', | ||
'fs-extra', | ||
'glob-stream' | ||
]; | ||
|
||
const templatesToCopy = [ | ||
'index.html', | ||
'index.js', | ||
'webpack.uizoo.js', | ||
'createConfigsScript.js', | ||
'componentsContainer.js', | ||
'documentationContainer.js', | ||
'config.js', | ||
]; | ||
|
||
const log = console.log.bind(console); | ||
|
||
module.exports = { | ||
appFolderPath, | ||
uiZooScript, | ||
neededPackages, | ||
templatesToCopy, | ||
log | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const fs = require('fs-extra'); | ||
const opn = require('opn'); | ||
|
||
const {updatePackageJson} = require('./packageJsonService'); | ||
const {copyTemplate} = require('./templatesService'); | ||
const {executeCommand} = require('./processService'); | ||
const {log, templatesToCopy, appFolderPath} = require('./config'); | ||
|
||
function generate() { | ||
log(' ~ Copying templates...\n'); | ||
updatePackageJson() | ||
.then(() => fs.ensureDir(appFolderPath)) | ||
.then(() => Promise.all(templatesToCopy.map(copyTemplate))) | ||
.then(() => log(' ~ Executing commands...\n')) | ||
.then(() => executeCommand('npm i')) | ||
.then(() => {setTimeout(() => opn('http://localhost:5005/uizoo'), 2500)}) | ||
.then(() => log(' ~ Done! Executing `uizoo` script:\n')) | ||
.then(() => executeCommand('npm run uizoo')) | ||
.then(() => process.exit(0)) | ||
.catch(e => console.error(e)); | ||
} | ||
|
||
module.exports = generate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const path = require('path'); | ||
const latestVersion = require('latest-version'); | ||
const fs = require('fs-extra'); | ||
const {resolveTemplatePath} = require('./templatesService'); | ||
const {uiZooScript, neededPackages} = require('./config'); | ||
|
||
module.exports = { | ||
updatePackageJson | ||
}; | ||
|
||
/** | ||
* Update the folder's package.json with needed dependencies or use a fresh one from templates | ||
* if there is none | ||
* @return {Promise} | ||
*/ | ||
function updatePackageJson() { | ||
return new Promise((resolve, reject) => { | ||
const pkgPath = path.resolve('package.json'); | ||
const defaultPkgPath = resolveTemplatePath('package.json'); | ||
|
||
fs.exists(pkgPath) | ||
.then(exists => fs.readFile(exists ? pkgPath : defaultPkgPath)) | ||
.then(modifyPackage) | ||
.then(pkg => fs.writeJSON(pkgPath, pkg, {spaces: 2})) | ||
.then(resolve) | ||
.catch(reject); | ||
}); | ||
} | ||
|
||
function modifyPackage(packageBuffer) { | ||
return new Promise((resolve, reject) => { | ||
Promise.all(neededPackages.map(latestVersion)) | ||
.then(neededPackagesVersions => { | ||
let pkg = JSON.parse(packageBuffer.toString()); | ||
|
||
// Add dependencies | ||
neededPackages.forEach((neededPackage, i) => { | ||
if((!pkg.dependencies || !pkg.dependencies[neededPackage]) && | ||
(!pkg.devDependencies || !pkg.devDependencies[neededPackage])) { | ||
|
||
pkg.devDependencies = Object.assign({}, pkg.devDependencies, { | ||
[neededPackage]: `~${neededPackagesVersions[i]}` | ||
}); | ||
} | ||
}); | ||
|
||
// Add scripts | ||
pkg.scripts = Object.assign({}, pkg.scripts, { | ||
"uizoo": uiZooScript | ||
}); | ||
resolve(pkg); | ||
}) | ||
.catch(reject); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const {spawn} = require('child_process'); | ||
const chalk = require('chalk'); | ||
const {log} = require('./config'); | ||
|
||
module.exports = { | ||
executeCommand | ||
}; | ||
|
||
/** | ||
* Execute a command to terminal with inherit io, resolve when it is done | ||
* @param {String} cmd | ||
* @return {Promise} | ||
*/ | ||
function executeCommand(cmd) { | ||
return new Promise((resolve, reject) => { | ||
log(chalk.grey(` ${cmd}\n`)); | ||
let cmdParts = cmd.split(' '); | ||
const ls = spawn(cmdParts.shift(), [].concat(cmdParts), {stdio: "inherit"}); | ||
ls.on('close', resolve); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default null; |
Oops, something went wrong.