Send all files at start unless there is more files than the new argument limit

This commit is contained in:
brunosimon
2018-01-12 01:56:57 +01:00
parent 621211e2d2
commit 10dc1bf24a
11 changed files with 1825 additions and 113 deletions
+20 -15
View File
@@ -71,19 +71,19 @@ class App
})
.option('exclude', {
alias: 'e',
describe: 'Files to exclude',
describe: 'Files to exclude (glob pattern)',
default:
[
'**/.DS_Store',
'node_modules/**',
'vendor/**',
'.git',
'.vscode',
'.env',
'.log',
'**/node_modules/**',
'**/vendor/**',
'**/.git',
'**/.vscode',
'**/.env',
'**/.log',
'.idea/**',
'*___jb_old___',
'*___jb_tmp___'
'**/*___jb_old___',
'**/*___jb_tmp___'
],
type: 'array'
})
@@ -99,11 +99,11 @@ class App
default: false,
type: 'boolean'
})
.option('initial-send', {
alias: 'i',
describe: 'Send files in folder at start',
default: false,
type: 'boolean'
.option('limit', {
alias: 'l',
describe: 'Limit of files above which nothing will be sent at start',
default: 99,
type: 'number'
})
.option('max-file-size', {
alias: 'm',
@@ -131,11 +131,16 @@ class App
config.exclude = args.exclude
config.open = args.open
config.test = args.test
config.initialSend = args['initial-send']
config.limit = args.limit
config.maxFileSize = args['max-file-size']
config.server = args.server
config.host = args.host
if(config.limit === -1)
{
config.limit = Infinity
}
if(config.name === '')
{
if(args._.length > 0 && typeof args._[0] === 'string' && args._[0] !== '')
+6 -5
View File
@@ -3,7 +3,7 @@ const slug = require('slug')
const Files = require('./files.js')
const Chat = require('./chat.js')
const JSZip = require('jszip')
const glob = require('glob')
const globby = require('globby')
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
@@ -15,11 +15,11 @@ class Project
this.config = _config
this.path = _options.path
this.watcherSocket = _options.watcherSocket
this.exclude = _options.exclude
this.setName(_options.name)
this.setSocket()
this.excludeRegex = new RegExp(_options.excludeRegex)
this.zipNeedsUpdate = true
this.files = new Files(this.config, { projectSocket: this.projectSocket })
this.chat = new Chat(this.config, { slug: this.slug, watcherSocket: this.watcherSocket })
@@ -71,9 +71,10 @@ class Project
}
// Search files with glob
const files = glob.sync(this.path + '/**', { dot: true })
const globPattern = ['**', ...this.exclude.map((item) => `!${item}`)]
const files = globby.sync(globPattern, { dot: true })
// // Create a zip file
// Create a zip file
const zip = new JSZip()
// Add files to zip
@@ -82,7 +83,7 @@ class Project
const stats = fs.lstatSync(_file)
// Ignore if folder or exluded
if(stats.isFile() && !_file.match(this.excludeRegex))
if(stats.isFile())
{
const basename = path.basename(_file)
const relativePath = _file.replace(basename, '').replace(this.path, '')
+39 -24
View File
@@ -7,6 +7,7 @@ const opener = require('opener')
const nodeNotifier = require('node-notifier')
const path = require('path')
const chalk = require('chalk')
const globby = require('globby')
/**
* Watcher class
@@ -26,6 +27,32 @@ class Watcher
this.watch()
}
/**
* Set exclude regex
* Because chakodar doesn't support dot files with glob pattern
*/
setExcludeRegex()
{
// Exclude files regex
const regexs = []
const Minimatch = require('minimatch').Minimatch
for(const _excludeKey in this.config.exclude)
{
const _exclude = this.config.exclude[_excludeKey]
const minimatch = new Minimatch(_exclude, { dot: true })
let regex = '' + minimatch.makeRe()
regex = regex.replace('/^', '')
regex = regex.replace('$/', '')
regexs.push(regex)
}
this.excludeRegex = new RegExp(regexs.join('|'))
}
/**
* Set socket
*/
@@ -45,7 +72,7 @@ class Watcher
name = path.parse(this.path).name
}
this.socket.emit('start_project', { name, path: this.path, excludeRegex: '' + this.excludeRegex })
this.socket.emit('start_project', { name, path: this.path, exclude: this.config.exclude })
// Debug
if(this.config.debug)
@@ -88,41 +115,29 @@ class Watcher
})
}
setExcludeRegex()
{
// Exclude files regex
const regexs = []
const Minimatch = require('minimatch').Minimatch
for(const _excludeKey in this.config.exclude)
{
const _exclude = this.config.exclude[_excludeKey]
const minimatch = new Minimatch(_exclude, { dot: true })
let regex = '' + minimatch.makeRe()
regex = regex.replace('/^', '')
regex = regex.replace('$/', '')
regexs.push(regex)
}
this.excludeRegex = new RegExp(regexs.join('|'))
}
/**
* Watch
* Listen to modifications on files and folders
*/
watch()
{
const globPattern = ['**', ...this.config.exclude.map((item) => `!${item}`)]
const files = globby.sync(globPattern, { dot: true })
const ignoreInitial = files.length > this.config.limit
if(ignoreInitial)
{
console.log(`${chalk.green.bold('watcher')} - ${chalk.cyan('start wating')} - ${chalk.red(`File limit exceeded (${this.config.limit})`)}`)
}
// Set up
this.watcher = chokidar.watch(
this.path,
{
// ignored: /[\/\\]\./,
ignored: this.excludeRegex,
ignoreInitial: !this.config.initialSend
ignoreInitial: ignoreInitial,
ignorePermissionErrors: true
}
)
+1404 -51
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -36,10 +36,10 @@
"homepage": "https://github.com/brunosimon/keppler",
"dependencies": {
"chalk": "^2.3.0",
"chokidar": "^1.7.0",
"chokidar": "^2.0.0",
"diff": "^3.3.0",
"express": "^4.15.3",
"glob": "^7.1.2",
"globby": "^7.1.1",
"gradient-string": "^1.0.0",
"helmet": "^3.8.1",
"html-entities": "^1.2.1",
+19 -13
View File
@@ -30,14 +30,14 @@ npm install -g keppler
#### 2 - Launch Keppler inside your project folder
In your console, navigate to your project folder.
Then launch Keppler with the name of your choice:
Then launch Keppler:
```
cd ./my-awesome-project
keppler "My awesome project"
keppler
```
Keppler should open in your default browser and start watching any changes you make on the files inside the folder.
Keppler should open in your default browser and start watching any changes you make inside the folder.
#### 3 - Share the URL with your audience
@@ -49,13 +49,19 @@ By default, you must be on the same network.
You can add configuration arguments when calling Keppler.
```
keppler "My project" --debug 0 --port 1234 --exclude "node_modules/**" --open true --test true --initial-send true --max-file-size 99999
keppler "My project" --debug 0 --port 1234 --exclude "node_modules/**" --open true --test true --limit 200 --max-file-size 99999
```
And you can use shortcuts for those arguments
And you can use shortcuts for those same arguments.
```
keppler "My project" -d 0 -p 1234 -e "node_modules/**" -oti -m 99999
keppler "My project" -d 0 -p 1234 -e "node_modules/**" -oti -l 200 -m 99999
```
All those arguments are optional. You can simply run Keppler.
```
keppler
```
Arguments list
@@ -78,8 +84,8 @@ Arguments list
|---|---|
|parameter|`--exclude`|
|shortcut|`-e`|
|default value|*(string)*`**/.DS_Store,node_modules/**,vendor/**,.git,.vscode,.env,.log,.idea/**,*___jb_old___,*___jb_tmp___`|
|description|List of paths to exclude (comma seperated and wildcards support)|
|default value|*(string)*`**/.DS_Store,**/node_modules/**,**/vendor/**,**/.git,**/.vscode,**/.env,**/.log,.idea/**,**/*___jb_old___,**/*___jb_tmp___`|
|description|List of paths to exclude (glob pattern with comma seperation)|
|||
|---|---|
@@ -97,10 +103,10 @@ Arguments list
|||
|---|---|
|parameter|`--initial-send`|
|shortcut|`-i`|
|default value|*(bool)*`false`|
|description|Send current files in the folder<br>:warning: Too much files may cause issues|
|parameter|`--limit`|
|shortcut|`-l`|
|default value|*(number)*`99`|
|description|Limit of files above which nothing will be sent at start<br>:warning: Too much files may cause issues|
|||
|---|---|
@@ -132,7 +138,7 @@ Arguments list
## Online instance
You can run Keppler online. Anybody would be able to connect to it and your audience won't need to be on the same network as you.
You can run Keppler online. Anyone with access to the server will be able to see the projects without having to be on the same network as you.
Keppler doesn't provide any host solution. You'll have to use your own server.
+1
View File
@@ -0,0 +1 @@
a
+2 -3
View File
@@ -134,16 +134,15 @@
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1515534909890</updated>
<workItem from="1515534912205" duration="739000" />
<workItem from="1515534912205" duration="1588000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="739000" />
<option name="totallyTimeSpent" value="1588000" />
</component>
<component name="ToolWindowManager">
<frame x="443" y="43" width="977" height="795" extended-state="0" />
<editor active="true" />
<layout>
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.3582395" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
+1
View File
@@ -0,0 +1 @@
test
+331
View File
@@ -16,6 +16,337 @@
<a href="#">Contact</a>
</footer>
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
</section>
</body>
</html>