Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix appveyor broken ci builds #45

Merged
merged 27 commits into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ os:

node_js:
- "node"
- "6"
- "5"
- "4"

install:
- npm install
- travis_wait npm install

before_script:
- node --version
- npm --version
- npm run lint
- npm run test

Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[![Build Status](https://travis-ci.org/AndyOGo/node-sync-glob.svg?branch=master)](https://travis-ci.org/AndyOGo/node-sync-glob)

[![Build status](https://ci.appveyor.com/api/projects/status/9i48hbtrfsy5sk1m/branch/master?svg=true)](https://ci.appveyor.com/project/AndyOGo/node-sync-glob/branch/master)

Synchronize files and folders locally by glob patterns, watch option included.

## Install
Expand Down Expand Up @@ -78,6 +80,21 @@ To exclude stuff from source just use glob exclusion - `!` prefix, like:
}
```

### Windows

As [`node-glob`](https://www.npmjs.com/package/glob#windows) and [`node-glob-all`](https://www.npmjs.com/package/glob-all) respectively only support unix style path separators `/`, don't use windows style `\`.

> **Please only use forward-slashes in glob expressions.**
>
> Though windows uses either `/` or `\` as its path separator, only `/`
> characters are used by this glob implementation. You must use
>forward-slashes **only** in glob expressions. Back-slashes will always
> be interpreted as escape characters, not path separators.
>
> Results from absolute patterns such as `/foo/*` are mounted onto the
> root setting using `path.join`. On windows, this will by default result
> in `/foo/*` matching `C:\foo\bar.txt`.

## API

Check our [API documentation](./API.md)
Expand Down
4 changes: 3 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ clone_depth: 3
environment:
matrix:
# node.js
- nodejs_version: "5"
- nodejs_version: "stable"
- nodejs_version: "6"
- nodejs_version: "5"
- nodejs_version: "4"

platform:
- x86
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@
"babel-plugin-transform-object-assign": "^6.8.0",
"babel-plugin-transform-object-rest-spread": "^6.16.0",
"babel-preset-es2015": "^6.18.0",
"dir-compare": "^1.3.0",
"dir-compare": "^1.4.0",
"documentation": "^4.0.0-beta.18",
"eslint": "^3.9.1",
"eslint-config-airbnb-base": "^9.0.0",
"eslint-plugin-import": "^2.0.1",
"jest": "^18.1.0"
"jest": "^19.0.2"
}
}
13 changes: 8 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => {
// Initial mirror
const mirrorInit = [
promisify(globAll)(sources.map(source => (isGlob(source) === -1
&& fs.statSync(source).isDirectory() ? `${source}/**` : source))),
&& fs.statSync(source).isDirectory() ? `${source}/**` : source)))
.then(files => files.map(file => path.normalize(file))),
]

if (options.delete) {
Expand Down Expand Up @@ -147,11 +148,13 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => {
mirrorPromiseAll = null
}

activePromises.forEach((promise) => {
promise.cancel()
})
if (activePromises) {
activePromises.forEach((promise) => {
promise.cancel()
})

activePromises = null
activePromises = null
}
}

// Watcher to keep in sync from that
Expand Down
4 changes: 4 additions & 0 deletions src/lib/sources-bases.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import path from 'path'
import isGlob from './is-glob'

const reDir = /\/|\\/
const reDirAll = new RegExp(reDir.source, 'gm')

/**
* Determine the base paths of `sources` like:
Expand Down Expand Up @@ -48,6 +49,9 @@ const sourcesBases = (sources) => {
}
}

// eslint-disable-next-line no-param-reassign
pattern = pattern.replace(reDirAll, path.sep)

if (bases.indexOf(pattern) === -1) {
bases.push(pattern)
}
Expand Down
4 changes: 2 additions & 2 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const compare = (done, source, target, options) => (event, data) => {
[source, target] = data
}

const res = dirCompare.compareSync(path.normalize(source), path.normalize(target), {
const res = dirCompare.compareSync(source, target, {
...options,
compareSize: true,
compareContent: true,
Expand All @@ -134,7 +134,7 @@ export const compare = (done, source, target, options) => (event, data) => {

export const compareDir = (done, source, target, options = {}) => (event) => {
if (event) {
const res = dirCompare.compareSync(path.normalize(source), path.normalize(target), {
const res = dirCompare.compareSync(source, target, {
...options,
compareSize: true,
compareContent: true,
Expand Down
2 changes: 1 addition & 1 deletion test/lib/is-glob.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import isGlob from '../../src/lib/is-glob'
// eslint-disable-next-line no-bitwise
const isGloby = value => !!~isGlob(value)

describe('lib/is-glib', () => {
describe('lib/is-glob', () => {
describe('truthy', () => {
it('should match asterisk wildcard', () => {
expect(isGloby('*')).toBe(true)
Expand Down
35 changes: 18 additions & 17 deletions test/lib/sources-bases.spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { sep } from 'path'
import sourcesBases from '../../src/lib/sources-bases'

describe('lib/sources-bases', () => {
it('should resolve the base path of globs', () => {
expect(sourcesBases('*')).toEqual([''])
expect(sourcesBases('test/mock/*.txt')).toEqual(['test/mock'])
expect(sourcesBases('test/mock/a*txt')).toEqual(['test/mock'])
expect(sourcesBases('test/mock/*.txt')).toEqual([`test${sep}mock`])
expect(sourcesBases('test/mock/a*txt')).toEqual([`test${sep}mock`])

expect(sourcesBases('test/**/*.txt')).toEqual(['test'])

expect(sourcesBases('test/mock/?.txt')).toEqual(['test/mock'])
expect(sourcesBases('test/mock/a?txt')).toEqual(['test/mock'])
expect(sourcesBases('test/mock/?.txt')).toEqual([`test${sep}mock`])
expect(sourcesBases('test/mock/a?txt')).toEqual([`test${sep}mock`])

expect(sourcesBases('test/mock/{@org,foo}/.txt')).toEqual(['test/mock'])
expect(sourcesBases('test/mock/{@org,foo}/.txt')).toEqual([`test${sep}mock`])

expect(sourcesBases('test/[a-z]')).toEqual(['test'])
expect(sourcesBases('test/[!a-z]')).toEqual(['test'])
Expand All @@ -25,15 +26,15 @@ describe('lib/sources-bases', () => {
})

it('should resolve the base path of files', () => {
expect(sourcesBases('test/mock/a.txt')).toEqual(['test/mock'])
expect(sourcesBases('test/mock/@org/a.txt')).toEqual(['test/mock/@org'])
expect(sourcesBases('test/mock/a.txt')).toEqual([`test${sep}mock`])
expect(sourcesBases('test/mock/@org/a.txt')).toEqual([`test${sep}mock${sep}@org`])
})

it('should leave directories unchanged', () => {
expect(sourcesBases('test/mock')).toEqual(['test/mock'])
expect(sourcesBases('test/mock/')).toEqual(['test/mock'])
expect(sourcesBases('test/mock/@org')).toEqual(['test/mock/@org'])
expect(sourcesBases('test/mock/@org/')).toEqual(['test/mock/@org'])
expect(sourcesBases('test/mock')).toEqual([`test${sep}mock`])
expect(sourcesBases('test/mock/')).toEqual([`test${sep}mock`])
expect(sourcesBases('test/mock/@org')).toEqual([`test${sep}mock${sep}@org`])
expect(sourcesBases('test/mock/@org/')).toEqual([`test${sep}mock${sep}@org`])
})

it('should ignore exclude patterns', () => {
Expand All @@ -47,16 +48,16 @@ describe('lib/sources-bases', () => {
'test/mock/@org',
'test/mock/foo/*.txt',
])).toEqual([
'test/mock',
'test/mock/bar',
'test/mock/@org',
'test/mock/foo',
`test${sep}mock`,
`test${sep}mock${sep}bar`,
`test${sep}mock${sep}@org`,
`test${sep}mock${sep}foo`,
])
})

it('should list common base baths no more than once', () => {
expect(sourcesBases(['test/mock/a.txt', 'test/mock/b.txt'])).toEqual(['test/mock'])
expect(sourcesBases(['test/mock', 'test/mock/'])).toEqual(['test/mock'])
expect(sourcesBases(['test/mock/a.txt', 'test/mock/b.txt'])).toEqual([`test${sep}mock`])
expect(sourcesBases(['test/mock', 'test/mock/'])).toEqual([`test${sep}mock`])
expect(sourcesBases(['test/*.txt', 'test/*.txt'])).toEqual(['test'])
})
})