<commit_before>// Load plugins
var gulp = require('gulp'),
    eslint = require('gulp-eslint'),
    uglify = require('gulp-uglify'),
    csso = require('gulp-csso'),
    rename = require('gulp-rename'),
    concat = require('gulp-concat'),
    qunit = require('gulp-qunit'),
    babel = require("gulp-babel");

// Concatenate & Minify JS
gulp.task('scripts', function() {
    return gulp.src('./src/*.js')
        .pipe(babel())
        .pipe(rename({ suffix: '.min' }))
        .pipe(uglify({ preserveComments: "license" }))
        .pipe(gulp.dest('./build'))
});

// Lint Task
gulp.task('lint', function() {
    return gulp.src('./src/*.js')
        .pipe(eslint({
            'rules': {
                'quotes': [1, 'double', {'avoidEscape': true}],
                'semi': [2, 'always'],
                'eqeqeq': [1, 'smart'],
                'strict': [2, 'safe'],
                'no-redeclare': 2
            },
            envs: [
                'browser',
                'es6'
            ]
        }))
        .pipe(eslint.format())
});

// CSS task
gulp.task('css', function () {
    return gulp.src('./src/chordictionary.css')
        .pipe(csso())
        .pipe(rename({ suffix: '.min' }))
        .pipe(gulp.dest('./build'));
});

// Test Tasks
gulp.task('test', function() {
    return gulp.src('./_testfiles/test_dev.html') // check the src file
        .pipe(qunit());
});
gulp.task('testbuild', function() {
    return gulp.src('./_testfiles/test_build.html') // check the builded file
        .pipe(qunit());
});

// Default task
 gulp.task('default', ['watch'], function() {
   gulp.start('lint', 'scripts');
 });

 // Build task
 gulp.task('build', function() {
   gulp.start('css', 'lint', 'scripts', 'testbuild');
 });

// Watch
gulp.task('watch', function() {
  gulp.watch('./src/*.js', ['lint', 'scripts']);
  gulp.watch('./src/chordictionary.css', ['css']);
});
<commit_msg>updated eslint rules for consistency<commit_after>// Load plugins
var gulp = require('gulp'),
    eslint = require('gulp-eslint'),
    uglify = require('gulp-uglify'),
    csso = require('gulp-csso'),
    rename = require('gulp-rename'),
    concat = require('gulp-concat'),
    qunit = require('gulp-qunit'),
    babel = require("gulp-babel");

// Concatenate & Minify JS
gulp.task('scripts', function() {
    return gulp.src('./src/*.js')
        .pipe(babel())
        .pipe(rename({ suffix: '.min' }))
        .pipe(uglify({ preserveComments: "license" }))
        .pipe(gulp.dest('./build'))
});

// Lint Task
gulp.task('lint', function() {
    return gulp.src('./src/*.js')
        .pipe(eslint({
            'rules': {
                'quotes': [1, 'double', {'avoidEscape': true}],
                'semi': [2, 'always'],
                'eqeqeq': [1, 'smart'],
                'strict': [2, 'safe'],
                'no-redeclare': 2,
                'no-lonely-if': 1,
                'one-var-declaration-per-line': [1, "initializations"]
            },
            envs: [
                'browser',
                'es6'
            ]
        }))
        .pipe(eslint.format())
});

// CSS task
gulp.task('css', function () {
    return gulp.src('./src/chordictionary.css')
        .pipe(csso())
        .pipe(rename({ suffix: '.min' }))
        .pipe(gulp.dest('./build'));
});

// Test Tasks
gulp.task('test', function() {
    return gulp.src('./_testfiles/test_dev.html') // check the src file
        .pipe(qunit());
});
gulp.task('testbuild', function() {
    return gulp.src('./_testfiles/test_build.html') // check the builded file
        .pipe(qunit());
});

// Default task
 gulp.task('default', ['watch'], function() {
   gulp.start('lint', 'scripts');
 });

 // Build task
 gulp.task('build', function() {
   gulp.start('css', 'lint', 'scripts', 'testbuild');
 });

// Watch
gulp.task('watch', function() {
  gulp.watch('./src/*.js', ['lint', 'scripts']);
  gulp.watch('./src/chordictionary.css', ['css']);
});
<|endoftext|>


<commit_before>/**
 * `modules/tagmanager` data store: containers.
 *
 * Site Kit by Google, Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * External dependencies
 */
import invariant from 'invariant';

/**
 * Internal dependencies
 */
import API from 'googlesitekit-api';
import Data from 'googlesitekit-data';
import { STORE_NAME, CONTEXT_WEB, CONTEXT_AMP } from './constants';
import { isValidAccountID, isValidContainerID, isValidContainerName, isValidUsageContext } from '../util/validation';
import { createFetchStore } from '../../../googlesitekit/data/create-fetch-store';
const { createRegistrySelector, createRegistryControl } = Data;

// Actions
const WAIT_FOR_CONTAINERS = 'WAIT_FOR_CONTAINERS';

const fetchGetContainersStore = createFetchStore( {
	baseName: 'getContainers',
	argsToParams: ( accountID ) => {
		return { accountID };
	},
	validateParams: ( { accountID } = {} ) => {
		invariant( isValidAccountID( accountID ), 'A valid accountID is required to fetch containers.' );
	},
	controlCallback: ( { accountID } ) => {
		// Always request both contexts to prevent filtering on server.
		// TODO: Remove `usageContext` param when legacy component is removed and datapoint
		// defaults to returning all containers if no context is provided.
		const usageContext = [ CONTEXT_WEB, CONTEXT_AMP ];
		return API.get( 'modules', 'tagmanager', 'containers', { accountID, usageContext }, { useCache: false } );
	},
	reducerCallback: ( state, containers, { accountID } ) => {
		return {
			...state,
			containers: {
				...state.containers,
				[ accountID ]: containers,
			},
		};
	},
} );

const fetchCreateContainerStore = createFetchStore( {
	baseName: 'createContainer',
	argsToParams( accountID, usageContext, { containerName } ) {
		return { accountID, usageContext, containerName };
	},
	validateParams: ( { accountID, usageContext, containerName } = {} ) => {
		invariant( isValidAccountID( accountID ), 'A valid accountID is required to create a container.' );
		invariant( isValidUsageContext( usageContext ), 'A valid usageContext is required to create a container.' );
		invariant( isValidContainerName( containerName ), 'A valid containerName is required to create a container.' );
	},
	controlCallback: ( { accountID, usageContext, containerName: name } ) => {
		return API.set( 'modules', 'tagmanager', 'create-container', { accountID, usageContext, name } );
	},
	reducerCallback( state, container, { accountID } ) {
		return {
			...state,
			containers: {
				...state.containers,
				[ accountID ]: [
					...( state.containers[ accountID ] || [] ),
					container,
				],
			},
		};
	},
} );

const baseInitialState = {
	containers: {},
};

const baseActions = {
	/**
	 * Creates a new Tag Manager container in the given account.
	 *
	 * @since 1.11.0
	 *
	 * @param {string} accountID          Google Tag Manager account ID.
	 * @param {string} usageContext       Container usage context. (Either 'web', or 'amp').
	 * @param {Object} args               Container arguments.
	 * @param {string} args.containerName The name for a new container.
	 * @return {Object} Object with `response` and `error`.
	 */
	*createContainer( accountID, usageContext, { containerName } ) {
		invariant( isValidAccountID( accountID ), 'A valid accountID is required to create a container.' );
		invariant( isValidUsageContext( usageContext ), 'A valid usageContext is required to create a container.' );
		invariant( isValidContainerName( containerName ), 'A valid containerName is required to create a container.' );

		const { response, error } = yield fetchCreateContainerStore.actions.fetchCreateContainer( accountID, usageContext, { containerName } );

		return { response, error };
	},

	/**
	 * Sets selected container settings for the given container ID of the current account.
	 *
	 * Supports selecting a container that has not been received yet.
	 *
	 * @since 1.12.0
	 * @private
	 *
	 * @param {string} containerID Tag Manager container `publicId` of container to select.
	 */
	*selectContainerByID( containerID ) {
		// This action relies on looking up the container in state to know what
		// settings to set the container IDs for. For this reason we cannot use this
		// for selecting the option to "set up a new container"
		invariant( isValidContainerID( containerID ), 'A valid container ID is required to select a container by ID.' );

		const { select, dispatch } = yield Data.commonActions.getRegistry();
		const accountID = select( STORE_NAME ).getAccountID();

		if ( ! isValidAccountID( accountID ) ) {
			return;
		}

		// Containers may not be loaded yet for this account,
		// and no selections are done in the getContainers resolver, so we wait here.
		// This will not guarantee that containers exist, as an account may also have no containers
		// it will simply wait for `getContainers` to be resolved for this account ID.
		yield baseActions.waitForContainers( accountID );

		const container = select( STORE_NAME ).getContainerByID( accountID, containerID );
		if ( ! container ) {
			// Do nothing if the container was not found.
			return;
		}
		if ( container.usageContext.includes( CONTEXT_WEB ) ) {
			dispatch( STORE_NAME ).setContainerID( containerID );
			// eslint-disable-next-line sitekit/acronym-case
			dispatch( STORE_NAME ).setInternalContainerID( container.containerId );
		} else if ( container.usageContext.includes( CONTEXT_AMP ) ) {
			dispatch( STORE_NAME ).setAMPContainerID( containerID );
			// eslint-disable-next-line sitekit/acronym-case
			dispatch( STORE_NAME ).setInternalAMPContainerID( container.containerId );
		}
	},

	/**
	 * Waits for containers to be resolved for the given account ID.
	 *
	 * @since 1.12.0
	 * @private
	 *
	 * @param {string} accountID Google Tag Manager account ID to await containers for.
	 * @return {Object} Redux-style action.
	 */
	*waitForContainers( accountID ) {
		invariant( isValidAccountID( accountID ), 'A valid accountID is required to wait for containers.' );
		return {
			payload: { accountID },
			type: WAIT_FOR_CONTAINERS,
		};
	},
};

const baseControls = {
	[ WAIT_FOR_CONTAINERS ]: createRegistryControl( ( registry ) => ( { payload: { accountID } } ) => {
		// Select first to ensure resolution is always triggered.
		registry.select( STORE_NAME ).getContainers( accountID );
		const areContainersLoaded = () => registry.select( STORE_NAME ).hasFinishedResolution( 'getContainers', [ accountID ] );

		if ( areContainersLoaded() ) {
			return;
		}

		return new Promise( ( resolve ) => {
			const unsubscribe = registry.subscribe( () => {
				if ( areContainersLoaded() ) {
					unsubscribe();
					resolve();
				}
			} );
		} );
	} ),
};

const baseResolvers = {
	*getContainers( accountID ) {
		if ( ! isValidAccountID( accountID ) ) {
			return;
		}

		const { select } = yield Data.commonActions.getRegistry();

		if ( ! select( STORE_NAME ).getContainers( accountID ) ) {
			yield fetchGetContainersStore.actions.fetchGetContainers( accountID );
		}
	},
};

const baseSelectors = {
	/**
	 * Gets a container by its ID.
	 *
	 * @since 1.11.0
	 *
	 * @param {Object} state       Data store's state.
	 * @param {string} accountID   Account ID to find container in.
	 * @param {string} containerID Container (publicId) of container to get.
	 * @return {(Object|null|undefined)} Container object if found, `null` if not found, or `undefined` if not loaded yet.
	 */
	getContainerByID: createRegistrySelector( ( select ) => ( state, accountID, containerID ) => {
		// Select all containers of the account to find the container, regardless of usageContext.
		const containers = select( STORE_NAME ).getContainers( accountID );

		if ( containers === undefined ) {
			return undefined;
		}

		// eslint-disable-next-line sitekit/acronym-case
		return containers.find( ( { publicId } ) => containerID === publicId ) || null;
	} ),

	/**
	 * Gets all web containers for the given account.
	 *
	 * @since 1.12.0
	 *
	 * @param {Object} state     Data store's state.
	 * @param {string} accountID Account ID to get containers for.
	 * @return {(Array|undefined)} Array of containers, or `undefined` if not loaded yet.
	 */
	getWebContainers: createRegistrySelector( ( select ) => ( state, accountID ) => {
		const containers = select( STORE_NAME ).getContainers( accountID );

		if ( ! Array.isArray( containers ) ) {
			return undefined;
		}

		return containers.filter(
			( { usageContext } ) => usageContext.includes( CONTEXT_WEB )
		);
	} ),

	/**
	 * Gets all AMP containers for the given account.
	 *
	 * @since 1.12.0
	 *
	 * @param {Object} state     Data store's state.
	 * @param {string} accountID Account ID to get containers for.
	 * @return {(Array|undefined)} Array of containers, or `undefined` if not loaded yet.
	 */
	getAMPContainers: createRegistrySelector( ( select ) => ( state, accountID ) => {
		const containers = select( STORE_NAME ).getContainers( accountID );

		if ( ! Array.isArray( containers ) ) {
			return undefined;
		}

		return containers.filter(
			( { usageContext } ) => usageContext.includes( CONTEXT_AMP )
		);
	} ),

	/**
	 * Gets all containers for the given account.
	 *
	 * @since 1.12.0
	 *
	 * @param {Object} state     Data store's state.
	 * @param {string} accountID Account ID to get containers for.
	 * @return {(Array|undefined)} Array of containers, or `undefined` if not loaded yet.
	 */
	getContainers( state, accountID ) {
		return state.containers[ accountID ];
	},

	/**
	 * Checks if containers are currently being fetched for the given account or not.
	 *
	 * @since 1.12.0
	 *
	 * @param {Object} state     Data store's state.
	 * @param {string} accountID Account ID to get containers for.
	 * @return {boolean} True if containers are being fetched for the given account, otherwise false.
	 */
	isDoingGetContainers: createRegistrySelector( ( select ) => ( state, accountID ) => {
		return select( STORE_NAME ).isFetchingGetContainers( accountID );
	} ),

	/**
	 * Checks if any request for creating a container is in progress.
	 *
	 * @since 1.11.0
	 *
	 * @param {Object} state Data store's state.
	 * @return {boolean} True if a request for create-container is in progress, otherwise false.
	 */
	isDoingCreateContainer( state ) {
		return Object.values( state.isFetchingCreateContainer ).some( Boolean );
	},
};

const store = Data.combineStores(
	fetchGetContainersStore,
	fetchCreateContainerStore,
	{
		initialState: baseInitialState,
		actions: baseActions,
		controls: baseControls,
		resolvers: baseResolvers,
		selectors: baseSelectors,
	}
);

export const {
	initialState,
	actions,
	controls,
	reducer,
	resolvers,
	selectors,
} = store;

export default store;
<commit_msg>Migrate more actions to createValidatedAction.<commit_after>/**
 * `modules/tagmanager` data store: containers.
 *
 * Site Kit by Google, Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * External dependencies
 */
import invariant from 'invariant';

/**
 * Internal dependencies
 */
import API from 'googlesitekit-api';
import Data from 'googlesitekit-data';
import { STORE_NAME, CONTEXT_WEB, CONTEXT_AMP } from './constants';
import { isValidAccountID, isValidContainerID, isValidContainerName, isValidUsageContext } from '../util/validation';
import { createFetchStore } from '../../../googlesitekit/data/create-fetch-store';
const { createRegistrySelector, createRegistryControl } = Data;
import { createValidatedAction } from '../../../googlesitekit/data/utils';

// Actions
const WAIT_FOR_CONTAINERS = 'WAIT_FOR_CONTAINERS';

const fetchGetContainersStore = createFetchStore( {
	baseName: 'getContainers',
	argsToParams: ( accountID ) => {
		return { accountID };
	},
	validateParams: ( { accountID } = {} ) => {
		invariant( isValidAccountID( accountID ), 'A valid accountID is required to fetch containers.' );
	},
	controlCallback: ( { accountID } ) => {
		// Always request both contexts to prevent filtering on server.
		// TODO: Remove `usageContext` param when legacy component is removed and datapoint
		// defaults to returning all containers if no context is provided.
		const usageContext = [ CONTEXT_WEB, CONTEXT_AMP ];
		return API.get( 'modules', 'tagmanager', 'containers', { accountID, usageContext }, { useCache: false } );
	},
	reducerCallback: ( state, containers, { accountID } ) => {
		return {
			...state,
			containers: {
				...state.containers,
				[ accountID ]: containers,
			},
		};
	},
} );

const fetchCreateContainerStore = createFetchStore( {
	baseName: 'createContainer',
	argsToParams( accountID, usageContext, { containerName } ) {
		return { accountID, usageContext, containerName };
	},
	validateParams: ( { accountID, usageContext, containerName } = {} ) => {
		invariant( isValidAccountID( accountID ), 'A valid accountID is required to create a container.' );
		invariant( isValidUsageContext( usageContext ), 'A valid usageContext is required to create a container.' );
		invariant( isValidContainerName( containerName ), 'A valid containerName is required to create a container.' );
	},
	controlCallback: ( { accountID, usageContext, containerName: name } ) => {
		return API.set( 'modules', 'tagmanager', 'create-container', { accountID, usageContext, name } );
	},
	reducerCallback( state, container, { accountID } ) {
		return {
			...state,
			containers: {
				...state.containers,
				[ accountID ]: [
					...( state.containers[ accountID ] || [] ),
					container,
				],
			},
		};
	},
} );

const baseInitialState = {
	containers: {},
};

const baseActions = {
	/**
	 * Creates a new Tag Manager container in the given account.
	 *
	 * @since 1.11.0
	 *
	 * @param {string} accountID          Google Tag Manager account ID.
	 * @param {string} usageContext       Container usage context. (Either 'web', or 'amp').
	 * @param {Object} args               Container arguments.
	 * @param {string} args.containerName The name for a new container.
	 * @return {Object} Object with `response` and `error`.
	 */
	createContainer: createValidatedAction( ( accountID, usageContext, { containerName } ) => {
		invariant( isValidAccountID( accountID ), 'A valid accountID is required to create a container.' );
		invariant( isValidUsageContext( usageContext ), 'A valid usageContext is required to create a container.' );
		invariant( isValidContainerName( containerName ), 'A valid containerName is required to create a container.' );
	},
	function* ( accountID, usageContext, { containerName } ) {
		const { response, error } = yield fetchCreateContainerStore.actions.fetchCreateContainer( accountID, usageContext, { containerName } );

		return { response, error };
	} ),

	/**
	 * Sets selected container settings for the given container ID of the current account.
	 *
	 * Supports selecting a container that has not been received yet.
	 *
	 * @since 1.12.0
	 * @private
	 *
	 * @param {string} containerID Tag Manager container `publicId` of container to select.
	 */
	selectContainerByID: createValidatedAction( ( containerID ) => {
		// This action relies on looking up the container in state to know what
		// settings to set the container IDs for. For this reason we cannot use this
		// for selecting the option to "set up a new container"
		// another instance here
		invariant( isValidContainerID( containerID ), 'A valid container ID is required to select a container by ID.' );
	},
	function* ( containerID ) {
		const { select, dispatch } = yield Data.commonActions.getRegistry();
		const accountID = select( STORE_NAME ).getAccountID();

		if ( ! isValidAccountID( accountID ) ) {
			return;
		}

		// Containers may not be loaded yet for this account,
		// and no selections are done in the getContainers resolver, so we wait here.
		// This will not guarantee that containers exist, as an account may also have no containers
		// it will simply wait for `getContainers` to be resolved for this account ID.
		yield baseActions.waitForContainers( accountID );

		const container = select( STORE_NAME ).getContainerByID( accountID, containerID );
		if ( ! container ) {
			// Do nothing if the container was not found.
			return;
		}
		if ( container.usageContext.includes( CONTEXT_WEB ) ) {
			dispatch( STORE_NAME ).setContainerID( containerID );
			// eslint-disable-next-line sitekit/acronym-case
			dispatch( STORE_NAME ).setInternalContainerID( container.containerId );
		} else if ( container.usageContext.includes( CONTEXT_AMP ) ) {
			dispatch( STORE_NAME ).setAMPContainerID( containerID );
			// eslint-disable-next-line sitekit/acronym-case
			dispatch( STORE_NAME ).setInternalAMPContainerID( container.containerId );
		}
	} ),

	/**
	 * Waits for containers to be resolved for the given account ID.
	 *
	 * @since 1.12.0
	 * @private
	 *
	 * @param {string} accountID Google Tag Manager account ID to await containers for.
	 * @return {Object} Redux-style action.
	 */
	waitForContainers: createValidatedAction( ( accountID ) => {
		invariant( isValidAccountID( accountID ), 'A valid accountID is required to wait for containers.' );
	},
	function* ( accountID ) {
		return {
			payload: { accountID },
			type: WAIT_FOR_CONTAINERS,
		};
	} ),
};

const baseControls = {
	[ WAIT_FOR_CONTAINERS ]: createRegistryControl( ( registry ) => ( { payload: { accountID } } ) => {
		// Select first to ensure resolution is always triggered.
		registry.select( STORE_NAME ).getContainers( accountID );
		const areContainersLoaded = () => registry.select( STORE_NAME ).hasFinishedResolution( 'getContainers', [ accountID ] );

		if ( areContainersLoaded() ) {
			return;
		}

		return new Promise( ( resolve ) => {
			const unsubscribe = registry.subscribe( () => {
				if ( areContainersLoaded() ) {
					unsubscribe();
					resolve();
				}
			} );
		} );
	} ),
};

const baseResolvers = {
	*getContainers( accountID ) {
		if ( ! isValidAccountID( accountID ) ) {
			return;
		}

		const { select } = yield Data.commonActions.getRegistry();

		if ( ! select( STORE_NAME ).getContainers( accountID ) ) {
			yield fetchGetContainersStore.actions.fetchGetContainers( accountID );
		}
	},
};

const baseSelectors = {
	/**
	 * Gets a container by its ID.
	 *
	 * @since 1.11.0
	 *
	 * @param {Object} state       Data store's state.
	 * @param {string} accountID   Account ID to find container in.
	 * @param {string} containerID Container (publicId) of container to get.
	 * @return {(Object|null|undefined)} Container object if found, `null` if not found, or `undefined` if not loaded yet.
	 */
	getContainerByID: createRegistrySelector( ( select ) => ( state, accountID, containerID ) => {
		// Select all containers of the account to find the container, regardless of usageContext.
		const containers = select( STORE_NAME ).getContainers( accountID );

		if ( containers === undefined ) {
			return undefined;
		}

		// eslint-disable-next-line sitekit/acronym-case
		return containers.find( ( { publicId } ) => containerID === publicId ) || null;
	} ),

	/**
	 * Gets all web containers for the given account.
	 *
	 * @since 1.12.0
	 *
	 * @param {Object} state     Data store's state.
	 * @param {string} accountID Account ID to get containers for.
	 * @return {(Array|undefined)} Array of containers, or `undefined` if not loaded yet.
	 */
	getWebContainers: createRegistrySelector( ( select ) => ( state, accountID ) => {
		const containers = select( STORE_NAME ).getContainers( accountID );

		if ( ! Array.isArray( containers ) ) {
			return undefined;
		}

		return containers.filter(
			( { usageContext } ) => usageContext.includes( CONTEXT_WEB )
		);
	} ),

	/**
	 * Gets all AMP containers for the given account.
	 *
	 * @since 1.12.0
	 *
	 * @param {Object} state     Data store's state.
	 * @param {string} accountID Account ID to get containers for.
	 * @return {(Array|undefined)} Array of containers, or `undefined` if not loaded yet.
	 */
	getAMPContainers: createRegistrySelector( ( select ) => ( state, accountID ) => {
		const containers = select( STORE_NAME ).getContainers( accountID );

		if ( ! Array.isArray( containers ) ) {
			return undefined;
		}

		return containers.filter(
			( { usageContext } ) => usageContext.includes( CONTEXT_AMP )
		);
	} ),

	/**
	 * Gets all containers for the given account.
	 *
	 * @since 1.12.0
	 *
	 * @param {Object} state     Data store's state.
	 * @param {string} accountID Account ID to get containers for.
	 * @return {(Array|undefined)} Array of containers, or `undefined` if not loaded yet.
	 */
	getContainers( state, accountID ) {
		return state.containers[ accountID ];
	},

	/**
	 * Checks if containers are currently being fetched for the given account or not.
	 *
	 * @since 1.12.0
	 *
	 * @param {Object} state     Data store's state.
	 * @param {string} accountID Account ID to get containers for.
	 * @return {boolean} True if containers are being fetched for the given account, otherwise false.
	 */
	isDoingGetContainers: createRegistrySelector( ( select ) => ( state, accountID ) => {
		return select( STORE_NAME ).isFetchingGetContainers( accountID );
	} ),

	/**
	 * Checks if any request for creating a container is in progress.
	 *
	 * @since 1.11.0
	 *
	 * @param {Object} state Data store's state.
	 * @return {boolean} True if a request for create-container is in progress, otherwise false.
	 */
	isDoingCreateContainer( state ) {
		return Object.values( state.isFetchingCreateContainer ).some( Boolean );
	},
};

const store = Data.combineStores(
	fetchGetContainersStore,
	fetchCreateContainerStore,
	{
		initialState: baseInitialState,
		actions: baseActions,
		controls: baseControls,
		resolvers: baseResolvers,
		selectors: baseSelectors,
	}
);

export const {
	initialState,
	actions,
	controls,
	reducer,
	resolvers,
	selectors,
} = store;

export default store;
<|endoftext|>


<commit_before>#!/usr/bin/env node

/* eslint-disable no-multi-spaces */

'use strict';

const assert = require('assert');
const common = require('../../prelude/common.js');

if (process.platform === 'win32') {
  assert.equal('c:',                     common.normalizePath('c:'));
  assert.equal('C:\\',                   common.normalizePath('c:\\'));
  assert.equal('C:\\',                   common.normalizePath('c:\\\\'));
  assert.equal('C:\\snapshot',           common.normalizePath('c:\\snapshot'));
  assert.equal('C:\\snapshoter',         common.normalizePath('c:\\snapshoter'));
  assert.equal('C:\\snapshot',           common.normalizePath('c:\\snapshot\\'));
  assert.equal('C:\\snapshoter',         common.normalizePath('c:\\snapshoter\\'));
  assert.equal('C:\\snapshot\\foo',      common.normalizePath('c:\\snapshot\\\\foo'));
  assert.equal('C:\\snapshot\\foo\\bar', common.normalizePath('c:\\snapshot\\\\foo\\\\bar\\\\\\'));

  assert.equal(common.insideSnapshot('c:'), false);
  assert.equal(common.insideSnapshot('c:\\'), false);
  assert.equal(common.insideSnapshot('c:\\foo'), false);
  assert.equal(common.insideSnapshot('c:\\foo\\snapshot'), false);
  assert.equal(common.insideSnapshot('c:\\snapshot'), true);
  assert.equal(common.insideSnapshot('c:\\snapshoter'), false);
  assert.equal(common.insideSnapshot('c:\\snapshot\\'), true);
  assert.equal(common.insideSnapshot('c:\\snapshoter\\'), false);
  assert.equal(common.insideSnapshot('c:\\snapshot\\\\'), true);
  assert.equal(common.insideSnapshot('c:\\snapshot\\foo'), true);
  assert.equal(common.insideSnapshot('c:\\snapshoter\\foo'), false);

  assert.equal('c:\\',             common.stripSnapshot('c:\\'));
  assert.equal('c:\\\\',           common.stripSnapshot('c:\\\\'));
  assert.equal('C:\\',             common.stripSnapshot('c:\\snapshot'));
  assert.equal('c:\\snapshoter',   common.stripSnapshot('c:\\snapshoter'));
  assert.equal('C:\\',             common.stripSnapshot('c:\\snapshot\\'));
  assert.equal('c:\\snapshoter\\', common.stripSnapshot('c:\\snapshoter\\'));
  assert.equal('C:\\foo',          common.stripSnapshot('c:\\snapshot\\\\foo'));
  assert.equal('C:\\foo\\bar',     common.stripSnapshot('c:\\snapshot\\\\foo\\\\bar\\\\\\'));

  assert.equal('C:\\snapshot\\',         common.snapshotify('c:\\'));
  assert.equal('C:\\snapshot\\foo',      common.snapshotify('c:\\foo'));
  assert.equal('C:\\snapshot\\foo',      common.snapshotify('c:\\foo\\'));
  assert.equal('C:\\snapshot\\foo',      common.snapshotify('c:\\foo\\\\'));
  assert.equal('C:\\snapshot\\foo\\bar', common.snapshotify('c:\\foo\\\\bar'));
  assert.equal('C:\\snapshot\\foo\\bar', common.snapshotify('c:\\foo\\\\bar\\\\\\'));
} else {
  assert.equal('/',                 common.normalizePath('/'));
  assert.equal('/',                 common.normalizePath('//'));
  assert.equal('/snapshot',         common.normalizePath('/snapshot'));
  assert.equal('/snapshoter',       common.normalizePath('/snapshoter'));
  assert.equal('/snapshot',         common.normalizePath('/snapshot/'));
  assert.equal('/snapshoter',       common.normalizePath('/snapshoter/'));
  assert.equal('/snapshot/foo',     common.normalizePath('/snapshot//foo'));
  assert.equal('/snapshot/foo/bar', common.normalizePath('/snapshot//foo//bar///'));

  assert.equal(common.insideSnapshot(''), false);
  assert.equal(common.insideSnapshot('/'), false);
  assert.equal(common.insideSnapshot('/foo'), false);
  assert.equal(common.insideSnapshot('/foo/snapshot'), false);
  assert.equal(common.insideSnapshot('/snapshot'), true);
  assert.equal(common.insideSnapshot('/snapshoter'), false);
  assert.equal(common.insideSnapshot('/snapshot/'), true);
  assert.equal(common.insideSnapshot('/snapshoter/'), false);
  assert.equal(common.insideSnapshot('/snapshot//'), true);
  assert.equal(common.insideSnapshot('/snapshot/foo'), true);
  assert.equal(common.insideSnapshot('/snapshoter/foo'), false);

  assert.equal('/',            common.stripSnapshot('/'));
  assert.equal('//',           common.stripSnapshot('//'));
  assert.equal('/',            common.stripSnapshot('/snapshot'));
  assert.equal('/snapshoter',  common.stripSnapshot('/snapshoter'));
  assert.equal('/',            common.stripSnapshot('/snapshot/'));
  assert.equal('/snapshoter/', common.stripSnapshot('/snapshoter/'));
  assert.equal('/foo',         common.stripSnapshot('/snapshot//foo'));
  assert.equal('/foo/bar',     common.stripSnapshot('/snapshot//foo//bar///'));

  assert.equal('/snapshot/',        common.snapshotify('/'));
  assert.equal('/snapshot/foo',     common.snapshotify('/foo'));
  assert.equal('/snapshot/foo',     common.snapshotify('/foo/'));
  assert.equal('/snapshot/foo',     common.snapshotify('/foo//'));
  assert.equal('/snapshot/foo/bar', common.snapshotify('/foo//bar'));
  assert.equal('/snapshot/foo/bar', common.snapshotify('/foo//bar///'));
}
<commit_msg>test insideSnapshot for both win32 and posix<commit_after>#!/usr/bin/env node

/* eslint-disable no-multi-spaces */

'use strict';

const assert = require('assert');
const common = require('../../prelude/common.js');

assert.equal(common.insideSnapshot('c:'), false);
assert.equal(common.insideSnapshot('c:\\'), false);
assert.equal(common.insideSnapshot('c:\\foo'), false);
assert.equal(common.insideSnapshot('c:\\foo\\snapshot'), false);
assert.equal(common.insideSnapshot('c:\\snapshot'), true);
assert.equal(common.insideSnapshot('c:\\snapshoter'), false);
assert.equal(common.insideSnapshot('c:\\snapshot\\'), true);
assert.equal(common.insideSnapshot('c:\\snapshoter\\'), false);
assert.equal(common.insideSnapshot('c:\\snapshot\\\\'), true);
assert.equal(common.insideSnapshot('c:\\snapshot\\foo'), true);
assert.equal(common.insideSnapshot('c:\\snapshoter\\foo'), false);

assert.equal(common.insideSnapshot(''), false);
assert.equal(common.insideSnapshot('/'), false);
assert.equal(common.insideSnapshot('/foo'), false);
assert.equal(common.insideSnapshot('/foo/snapshot'), false);
assert.equal(common.insideSnapshot('/snapshot'), true);
assert.equal(common.insideSnapshot('/snapshoter'), false);
assert.equal(common.insideSnapshot('/snapshot/'), true);
assert.equal(common.insideSnapshot('/snapshoter/'), false);
assert.equal(common.insideSnapshot('/snapshot//'), true);
assert.equal(common.insideSnapshot('/snapshot/foo'), true);
assert.equal(common.insideSnapshot('/snapshoter/foo'), false);

if (process.platform === 'win32') {
  assert.equal('c:',                     common.normalizePath('c:'));
  assert.equal('C:\\',                   common.normalizePath('c:\\'));
  assert.equal('C:\\',                   common.normalizePath('c:\\\\'));
  assert.equal('C:\\snapshot',           common.normalizePath('c:\\snapshot'));
  assert.equal('C:\\snapshoter',         common.normalizePath('c:\\snapshoter'));
  assert.equal('C:\\snapshot',           common.normalizePath('c:\\snapshot\\'));
  assert.equal('C:\\snapshoter',         common.normalizePath('c:\\snapshoter\\'));
  assert.equal('C:\\snapshot\\foo',      common.normalizePath('c:\\snapshot\\\\foo'));
  assert.equal('C:\\snapshot\\foo\\bar', common.normalizePath('c:\\snapshot\\\\foo\\\\bar\\\\\\'));

  assert.equal('c:\\',             common.stripSnapshot('c:\\'));
  assert.equal('c:\\\\',           common.stripSnapshot('c:\\\\'));
  assert.equal('C:\\',             common.stripSnapshot('c:\\snapshot'));
  assert.equal('c:\\snapshoter',   common.stripSnapshot('c:\\snapshoter'));
  assert.equal('C:\\',             common.stripSnapshot('c:\\snapshot\\'));
  assert.equal('c:\\snapshoter\\', common.stripSnapshot('c:\\snapshoter\\'));
  assert.equal('C:\\foo',          common.stripSnapshot('c:\\snapshot\\\\foo'));
  assert.equal('C:\\foo\\bar',     common.stripSnapshot('c:\\snapshot\\\\foo\\\\bar\\\\\\'));

  assert.equal('C:\\snapshot\\',         common.snapshotify('c:\\'));
  assert.equal('C:\\snapshot\\foo',      common.snapshotify('c:\\foo'));
  assert.equal('C:\\snapshot\\foo',      common.snapshotify('c:\\foo\\'));
  assert.equal('C:\\snapshot\\foo',      common.snapshotify('c:\\foo\\\\'));
  assert.equal('C:\\snapshot\\foo\\bar', common.snapshotify('c:\\foo\\\\bar'));
  assert.equal('C:\\snapshot\\foo\\bar', common.snapshotify('c:\\foo\\\\bar\\\\\\'));
} else {
  assert.equal('/',                 common.normalizePath('/'));
  assert.equal('/',                 common.normalizePath('//'));
  assert.equal('/snapshot',         common.normalizePath('/snapshot'));
  assert.equal('/snapshoter',       common.normalizePath('/snapshoter'));
  assert.equal('/snapshot',         common.normalizePath('/snapshot/'));
  assert.equal('/snapshoter',       common.normalizePath('/snapshoter/'));
  assert.equal('/snapshot/foo',     common.normalizePath('/snapshot//foo'));
  assert.equal('/snapshot/foo/bar', common.normalizePath('/snapshot//foo//bar///'));

  assert.equal('/',            common.stripSnapshot('/'));
  assert.equal('//',           common.stripSnapshot('//'));
  assert.equal('/',            common.stripSnapshot('/snapshot'));
  assert.equal('/snapshoter',  common.stripSnapshot('/snapshoter'));
  assert.equal('/',            common.stripSnapshot('/snapshot/'));
  assert.equal('/snapshoter/', common.stripSnapshot('/snapshoter/'));
  assert.equal('/foo',         common.stripSnapshot('/snapshot//foo'));
  assert.equal('/foo/bar',     common.stripSnapshot('/snapshot//foo//bar///'));

  assert.equal('/snapshot/',        common.snapshotify('/'));
  assert.equal('/snapshot/foo',     common.snapshotify('/foo'));
  assert.equal('/snapshot/foo',     common.snapshotify('/foo/'));
  assert.equal('/snapshot/foo',     common.snapshotify('/foo//'));
  assert.equal('/snapshot/foo/bar', common.snapshotify('/foo//bar'));
  assert.equal('/snapshot/foo/bar', common.snapshotify('/foo//bar///'));
}
<|endoftext|>


<commit_before>
require('./lib/0_type.js');

exports.testSomething = function(test){
    var A = type('A', [], {}); // Empty type
    test.expect(1);
    test.ok(true, "this assertion should pass");
    test.done();
};

exports.testSomethingElse = function(test){
    test.ok(false, "this assertion should fail");
    test.done();
};

<commit_msg>basic tests<commit_after>
function code(path){
  return require('fs').readFileSync('./lib/' + path, 'utf8');
}
eval(code('0_type.js'));

exports.testType = function(test){
    var A = type('A', [], {}); // Empty type
    test.ok(A);
    var B = type('B', [], {
        __init__: function(self, v){
          self.v = v;
        },
        getValue: function(self){
          return self.v;
        }
    })
    var b = B(7);
    test.equal(b.getValue(), 7, "getValue");
    var C = type('C', [B], {
        __init__: function(self, v){
          self.v = v * 2;
        }
    })
    var c = C(4);
    test.equal(c.getValue(), 8);
    test.done();
};

<|endoftext|>


<commit_before>'use strict';

var argv = require('yargs').argv;
var gulp = require('gulp');
var clean = require('gulp-clean');
var concat = require('gulp-concat');
var insert = require('gulp-insert');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
var karma = require('gulp-karma');
var mocha = require('gulp-mocha');
var gutil = require('gulp-util');
var connect = require('gulp-connect');
var opens = require('open');
var webserver = require('gulp-webserver');
var webpack = require('webpack-stream');
var webpackConfig = require('./webpack.config.js');
var replace = require('gulp-replace');
var optimizejs = require('gulp-optimize-js');
var stripCode = require('gulp-strip-code');
var eslint = require('gulp-eslint');
var karmaServer = require('karma').Server;
var stripComments = require('gulp-strip-comments');

var CI_MODE = (argv.mode === 'test-build') ? true : false;

console.log("argv ==>", argv);

var prebidRepoPath = argv.prebidpath || "../Prebid.js/";

gulp.task('clean', function() {
    return gulp.src(['dist/**/*.js', 'build/'], {
            read: true
        })
        .pipe(clean());
});

// What all processing needs to be done ?
gulp.task('webpack', ['clean'], function() {

    webpackConfig.devtool = null;

    return gulp.src('src_new/owt.js')
        .pipe(webpack(webpackConfig))
        //.pipe(uglify())
        //.pipe(optimizejs())
        .pipe(gulp.dest('build/dist'))
        .pipe(connect.reload())
    ;
});

// Run below task to create owt.js for creative
gulp.task('webpack-creative', ['clean'], function() {

    webpackConfig.devtool = null;

    return gulp.src('src_new/creative/owCreativeRenderer.js')
        .pipe(webpack(webpackConfig))
        .pipe(uglify())
        .pipe(optimizejs())
        .pipe(gulp.dest('build/dist'))
        .pipe(connect.reload())
    ;
});

gulp.task('devpack', function () {
  webpackConfig.devtool = 'source-map';

  return gulp.src('src_new/owt.js')
    .pipe(webpack(webpackConfig))
    .pipe(gulp.dest('build/dev'))
    .pipe(connect.reload());
});

// Test all code without private functions
gulp.task('test', ['unexpose'], function (done) {
    var defaultBrowsers = CI_MODE ? ['PhantomJS'] : ['Chrome'];
    new karmaServer({
        browsers: defaultBrowsers,
        basePath: './temp',
        configFile: __dirname + '/karma.conf.js',
        singleRun: true
    }, function (exitCode) {
        console.log("exitCode ==>", exitCode);
        gulp.src('temp', {
            read: true
        })
        .pipe(clean())
        .pipe(function () {
            if (exitCode != 0) {
                process.exit(exitCode);
            }
        });
    }).start();
});

// Test all code including private functions
gulp.task('testall', function (done) {
    var defaultBrowsers = CI_MODE ? ['PhantomJS'] : ['Chrome'];
    new karmaServer({
        browsers: defaultBrowsers,
        configFile: __dirname + '/karma.conf.js',
        singleRun: true
    }, function (exitCode) {
        console.log("exitCode ==>", exitCode);
        if (exitCode != 0) {
            process.exit(exitCode);
        }
    }).start();
});

// Small task to load coverage reports in the browser
gulp.task('coverage', function (done) {
    var coveragePort = 1999;
    connect.server({
        port: 1999,
        root: 'build',
        livereload: false
    });
    opens('http://localhost:' + coveragePort + '/coverage/');
    done();
});

// Task to remove privately exposed functions as well as remove test cases which test private functions
gulp.task('unexpose', function() {
    return gulp
        .src([
            'src_new/**/*.js',
            'test/**/*.js'
            ],
            { base: './' }
        )
        .pipe(stripCode({
            start_comment: "start-test-block",
            end_comment: "end-test-block"
        }))
        .pipe(gulp.dest('./temp/'));
});

// Code linting with eslint
gulp.task('lint', () => {
  return gulp.src([
        'src_new/**/*.js',
        'test/**/*.js'
    ])
    .pipe(eslint())
    .pipe(eslint.format('stylish'))
    .pipe(eslint.failAfterError());
});

// Task to build minified version of owt.js
gulp.task('bundle', function () {
    console.log("Executing build");
    return gulp.src([prebidRepoPath + '/build/dist/prebid.js', './build/dist/owt.js'])
    //return gulp.src(['prebid-header.js', prebidRepoPath + '/build/dist/prebid.js','prebid-footer.js','./build/dist/owt.js'])
        .pipe(concat('owt.min.js'))
        .pipe(gulp.dest('build'));
});

// Task to build minified version of owt.js
gulp.task('bundle-creative', function () {
    console.log("Executing creative-build");
    return gulp.src(['./build/dist/owt.js'])
        .pipe(concat('owt.min.js'))
        .pipe(gulp.dest('build'));
});

// Task to build non-minified version of owt.js
gulp.task('devbundle', function () {
    console.log("Executing Dev Build");
    return gulp.src([prebidRepoPath + '/build/dev/prebid.js', './build/dev/owt.js'])
    //return gulp.src(['prebid-header.js', prebidRepoPath + '/build/dev/prebid.js', 'prebid-footer.js', './build/dev/owt.js'])
        .pipe(concat('owt.js'))
        .pipe(gulp.dest('build'));
});
<commit_msg>removed comments from code<commit_after>'use strict';

var argv = require('yargs').argv;
var gulp = require('gulp');
var clean = require('gulp-clean');
var concat = require('gulp-concat');
var insert = require('gulp-insert');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
var karma = require('gulp-karma');
var mocha = require('gulp-mocha');
var gutil = require('gulp-util');
var connect = require('gulp-connect');
var opens = require('open');
var webserver = require('gulp-webserver');
var webpack = require('webpack-stream');
var webpackConfig = require('./webpack.config.js');
var replace = require('gulp-replace');
var optimizejs = require('gulp-optimize-js');
var stripCode = require('gulp-strip-code');
var eslint = require('gulp-eslint');
var karmaServer = require('karma').Server;
var stripComments = require('gulp-strip-comments');

var CI_MODE = (argv.mode === 'test-build') ? true : false;

console.log("argv ==>", argv);

var prebidRepoPath = argv.prebidpath || "../Prebid.js/";

gulp.task('clean', function() {
    return gulp.src(['dist/**/*.js', 'build/'], {
            read: true
        })
        .pipe(clean());
});

// What all processing needs to be done ?
gulp.task('webpack', ['clean'], function() {

    webpackConfig.devtool = null;

    return gulp.src('src_new/owt.js')
        .pipe(webpack(webpackConfig))
        .pipe(uglify())
        .pipe(optimizejs())
        .pipe(gulp.dest('build/dist'))
        .pipe(connect.reload())
    ;
});

// Run below task to create owt.js for creative
gulp.task('webpack-creative', ['clean'], function() {

    webpackConfig.devtool = null;

    return gulp.src('src_new/creative/owCreativeRenderer.js')
        .pipe(webpack(webpackConfig))
        .pipe(uglify())
        .pipe(optimizejs())
        .pipe(gulp.dest('build/dist'))
        .pipe(connect.reload())
    ;
});

gulp.task('devpack', function () {
  webpackConfig.devtool = 'source-map';

  return gulp.src('src_new/owt.js')
    .pipe(webpack(webpackConfig))
    .pipe(gulp.dest('build/dev'))
    .pipe(connect.reload());
});

// Test all code without private functions
gulp.task('test', ['unexpose'], function (done) {
    var defaultBrowsers = CI_MODE ? ['PhantomJS'] : ['Chrome'];
    new karmaServer({
        browsers: defaultBrowsers,
        basePath: './temp',
        configFile: __dirname + '/karma.conf.js',
        singleRun: true
    }, function (exitCode) {
        console.log("exitCode ==>", exitCode);
        gulp.src('temp', {
            read: true
        })
        .pipe(clean())
        .pipe(function () {
            if (exitCode != 0) {
                process.exit(exitCode);
            }
        });
    }).start();
});

// Test all code including private functions
gulp.task('testall', function (done) {
    var defaultBrowsers = CI_MODE ? ['PhantomJS'] : ['Chrome'];
    new karmaServer({
        browsers: defaultBrowsers,
        configFile: __dirname + '/karma.conf.js',
        singleRun: true
    }, function (exitCode) {
        console.log("exitCode ==>", exitCode);
        if (exitCode != 0) {
            process.exit(exitCode);
        }
    }).start();
});

// Small task to load coverage reports in the browser
gulp.task('coverage', function (done) {
    var coveragePort = 1999;
    connect.server({
        port: 1999,
        root: 'build',
        livereload: false
    });
    opens('http://localhost:' + coveragePort + '/coverage/');
    done();
});

// Task to remove privately exposed functions as well as remove test cases which test private functions
gulp.task('unexpose', function() {
    return gulp
        .src([
            'src_new/**/*.js',
            'test/**/*.js'
            ],
            { base: './' }
        )
        .pipe(stripCode({
            start_comment: "start-test-block",
            end_comment: "end-test-block"
        }))
        .pipe(gulp.dest('./temp/'));
});

// Code linting with eslint
gulp.task('lint', () => {
  return gulp.src([
        'src_new/**/*.js',
        'test/**/*.js'
    ])
    .pipe(eslint())
    .pipe(eslint.format('stylish'))
    .pipe(eslint.failAfterError());
});

// Task to build minified version of owt.js
gulp.task('bundle', function () {
    console.log("Executing build");
    return gulp.src([prebidRepoPath + '/build/dist/prebid.js', './build/dist/owt.js'])
        .pipe(concat('owt.min.js'))
        .pipe(gulp.dest('build'));
});

// Task to build minified version of owt.js
gulp.task('bundle-creative', function () {
    console.log("Executing creative-build");
    return gulp.src(['./build/dist/owt.js'])
        .pipe(concat('owt.min.js'))
        .pipe(gulp.dest('build'));
});

// Task to build non-minified version of owt.js
gulp.task('devbundle', function () {
    console.log("Executing Dev Build");
    return gulp.src([prebidRepoPath + '/build/dev/prebid.js', './build/dev/owt.js'])
        .pipe(concat('owt.js'))
        .pipe(gulp.dest('build'));
});
<|endoftext|>


<commit_before>var gulp = require('gulp');
var babel = require('gulp-babel');
var bowerFiles = require('main-bower-files');
var cleanCSS = require('gulp-clean-css');
var concat = require('gulp-concat');
var eslint = require('gulp-eslint');
var gulpIf = require('gulp-if');
var htmlreplace = require('gulp-html-replace');
var inject = require('gulp-inject');
var newer = require('gulp-newer');
var print = require('gulp-print');
var sourcemaps = require('gulp-sourcemaps');
var stylus = require('gulp-stylus');
var uglify = require('gulp-uglify');
var useref = require('gulp-useref');

var buildPath = {
    base: '../weatherApp',
    JS: '../weatherApp/js/',
    cssDist: '../weatherApp/styles/'
}

var sourcePath = {
    customJSX: './scripts',
    customCSS: './styles'
}

// Lint JS/JSX files
gulp.task('eslint', function() {
  return gulp.src(jsFiles.source)
    .pipe(eslint({
      baseConfig: {
        "ecmaFeatures": {
           "jsx": true
         }
      }
    }))
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
});

/* concat css files */
gulp.task('concat-minify-css', function() {
    return gulp.src(sourcePath.customCSS + '/*.css')
        .pipe(concat('main.min.css'))
        .pipe(cleanCSS())
        .pipe(gulp.dest(buildPath.cssDist))
});

/* convert jsx to js */
gulp.task('convert-jsx', function() {
  return gulp.src(sourcePath.customJSX + '/*.jsx')
    .pipe(babel({
      "plugins": ["transform-react-jsx"]
    }))
    .pipe(gulp.dest(buildPath.jsCustom));
});

/* concat all min.js files */
gulp.task('concat-minify-js', function() {
    return gulp.src([
        'node_modules/react/dist/react.min.js',
        'node_modules/react-dom/dist/react-dom.min.js',
        'node_modules/jquery/dist/jquery.min.js',
        'node_modules/bootstrap/dist/bootstrap.min.js',
        buildPath.jsCustom
        ])
        .pipe(concat('app.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest(buildPath.JS))
});

gulp.task('replace-html', function() {
    return gulp.src('index.html')
        .pipe(htmlreplace({
            'replace-css': 'styles/main.min.css',
            'replace-js': 'js/app.min.js'
        }))
        .pipe(gulp.dest(buildPath.base))
});

gulp.task('build', ['concat-minify-css', 'convert-jsx', 'concat-minify-js', 'replace-html']);<commit_msg>modified build<commit_after>var gulp = require('gulp');
var babel = require('gulp-babel');
var bowerFiles = require('main-bower-files');
var cleanCSS = require('gulp-clean-css');
var concat = require('gulp-concat');
var eslint = require('gulp-eslint');
var gulpIf = require('gulp-if');
var htmlreplace = require('gulp-html-replace');
var inject = require('gulp-inject');
var newer = require('gulp-newer');
var print = require('gulp-print');
var sourcemaps = require('gulp-sourcemaps');
var stylus = require('gulp-stylus');
var uglify = require('gulp-uglify');
var useref = require('gulp-useref');

var buildPath = {
    base: '../weatherApp',
    JS: '../weatherApp/js/',
    jsCustom: '../weatherApp/js/custom',
    cssDist: '../weatherApp/styles/'
}

var sourcePath = {
    customJSX: './scripts',
    customCSS: './styles'
}

// Lint JS/JSX files
gulp.task('eslint', function() {
  return gulp.src(jsFiles.source)
    .pipe(eslint({
      baseConfig: {
        "ecmaFeatures": {
           "jsx": true
         }
      }
    }))
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
});

/* concat css files */
gulp.task('concat-minify-css', function() {
    return gulp.src(sourcePath.customCSS + '/*.css')
        .pipe(concat('main.min.css'))
        .pipe(cleanCSS())
        .pipe(gulp.dest(buildPath.cssDist))
});

/* convert jsx to js */
gulp.task('convert-jsx', function() {
  return gulp.src(sourcePath.customJSX + '/*.jsx')
    .pipe(babel({
      "plugins": ["transform-react-jsx"]
    }))
    .pipe(gulp.dest(buildPath.jsCustom))
});

/* concat all min.js files */
gulp.task('concat-minify-js', function() {
    return gulp.src([
        'node_modules/react/dist/react.min.js',
        'node_modules/react-dom/dist/react-dom.min.js',
        'node_modules/jquery/dist/jquery.min.js',
        'node_modules/bootstrap/dist/bootstrap.min.js',
        'node_modules/moment/min/moment-with-locales.min.js'
        ])
        .pipe(concat('app.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest(buildPath.JS))
});

/* concat min.js files with jsx-js files */
gulp.task('concat-js-react-components', ['convert-jsx', 'concat-minify-js'], function() {
    return gulp.src([
        buildPath.JS + '/*.min.js',
        buildPath.jsCustom + '/*.js'
    ])
    .pipe(concat('app.min.js'))
    .pipe(gulp.dest(buildPath.JS))
});

gulp.task('replace-html', function() {
    return gulp.src('index.html')
        .pipe(htmlreplace({
            'replace-css': 'styles/main.min.css',
            'replace-js': 'js/app.min.js'
        }))
        .pipe(gulp.dest(buildPath.base))
});

gulp.task('build', ['concat-minify-css', 'concat-js-react-components', 'replace-html']);<|endoftext|>


<commit_before>(function(_R) {
	var global = this || (1,eval)(this);
    try {
        function expect(expected) {
            expect.count = 0 || expect.count++;
            return {
                toEqual: function(actual) {
                    this.actual = actual;
                    return this;
                },
                setTestName: function(name) {
                    this.name = name;
                    return this;
                },
                run: function() {
                    // NaN case
                    if (this.expected !== this.expected) {
                        this.result = this.expected !== this.actual;
                    } else if (_R.getInternalClass(this.actual) === 'Array') {
                        if (this.expected.length !== this.actual.length) {
                            return false;
                        }
                        for (var i = 0; i < this.actual.length; i++) {
                            if (this.actual[i] !== this.expected[i]) {
                                return false;
                            }
                        }
                        return true;
                    } else {
                        this.result = (this.expected === this.actual);

                    }
                    return this;
                },
                end: function(implementationDependant) {
                    var message = 'Test. ' + (this.name || expect.count);
                    if (this.result === false) {
                        message += (implementationDependant ?
                            ' Depends on implementation, but it isn\'t behavior expected by _R.' :
                            'Ouh, it shouldn\'t work this way!');
                        console.warn(message);
                        if (!implementationDependant) {
                            throw JSON.stringify({
                                message: message,
                                expected: this.expected,
                                actual: this.actual
                            });
                        } else {
                            expect.log.push([message, this.expected, this.actual, Error()]);
                        }
                    } else if (this.result === true) {
                        message += ' Result is correct' + (implementationDependant ? ' (but it is implementation dependant)' : '') + '.';
                        console.log(message);
                    } else {
                        throw new Error('Invalid test case');
                    }
                },
                expected: expected,
                actual: undefined
            };
        }
        expect.log = [];
        (function() {
            console.log('\n\tTesting _R.isValidVariableName \n');
            var varsIdentifiers = [
                ['a', true],
                ['b', true],
                ['c', true],
                ['d', true],
                ['var', false],
                ['any way to do this is valid', false],
                [{
                        oh: 'hai'
                    },
                    false
                ],
                [{
                        toString: function() {
                            return 'fromToString';
                        }
                    },
                    true
                ],
                [4, false],
                ['4', false],
                [false, false],
                ['undefined', true],
                ['null', false],
                [null, false],
                ['"wow"', false],
                ['function', false],
                ['//wow', false, true],
                ['/* wow */ a', true],
                ['/* wow a', false, true],
            ];
            var id, expectedVal, implementationDependant, test;
            for (var i = 0; i < varsIdentifiers.length; i++) {
                id = varsIdentifiers[i][0];
                expectedVal = varsIdentifiers[i][1];
                implementationDependant = !!(varsIdentifiers[i][2]);
                expect(
                        _R.isValidVariableName(id)
                    )
                    .toEqual(
                        expectedVal
                    )
                    .setTestName('Is "' + id + '" valid variable name?')
                    .run()
                    .end(implementationDependant);
            }
        })();

        (function() {
            console.log('\n\tTesting _R.isBoundOrNativeFunction \n');
            var functions = [
                [
                    function a() {},
                    false
                ],
                [(function b() {})
                    .bind(null), true
                ],
                [console.log, true, true],
                [Date, true],
                [Date.bind(null), true],
                [setTimeout, true, true],
                [Date, true],
                [(function() {
                    /*
                        [native code]
                    */
                }), false],
                [(function a() {
                    a.toString = Function.toString.bind(setTimeout);
                    return a;
                })(), false],
                [eval, true]
            ];
            var prepare;
            try {
                prepare = [eval('() => global'), false];
                functions.push(prepare);
                prepare = [eval('(a) => a'), false];
                functions.push(prepare)
                prepare = [eval('(() => global).bind(null)'), true];
                functions.push(prepare)
            } catch (e) {
                console.log('\n\tThis implementation does not support arrow functions. Ommiting tests.\n');
            }
            var func, expectedVal, implementationDependant, test;
            for (var i = 0; i < functions.length; i++) {
                func = functions[i][0];
                expectedVal = functions[i][1];
                implementationDependant = !!(functions[i][2]);
                expect(
                        _R.isBoundOrNativeFunction(func)
                    )
                    .toEqual(
                        expectedVal
                    )
                    .setTestName('Is function ("' + (func.name || i) + '") native or bound?')
                    .run()
                    .end(implementationDependant);
            }
        })();

        (function() {
            console.log('\n\tTesting _R.getFunctionSourceCode \n');
            var functions = [
                [
                    function a() {}, 'function a() {}'
                ],
            ];
            var func, expectedVal, implementationDependant, test;
            for (var i = 0; i < functions.length; i++) {
                func = functions[i][0];
                expectedVal = functions[i][1];
                implementationDependant = !!(functions[i][2]);
                expect(
                        _R.getFunctionSourceCode(func)
                    )
                    .toEqual(
                        expectedVal
                    )
                    .setTestName('Can function ("' + (func.name || i) + '") code be retrieved?')
                    .run()
                    .end(implementationDependant);
            }
        })();

        (function() {
            console.log('\n\tTesting _R.getInternalClass \n');
            var values = [
                ['abcd', 'String'],
                [5, 'Number'],
                [null, 'Null', true],
                [undefined, 'Undefined', true],
                [Function(), 'Function'],
                [this, 'global', true],
                [{}, 'Object'],
                [
                    [], 'Array'
                ],
                [Infinity, 'Number'],
                [NaN, 'Number'],
                [true, 'Boolean'],
                [new String('oh hai'), 'String'],
            ];
            if (typeof Symbol !== 'undefined') {
                values.push([Symbol(), 'Symbol', true]);
            }
            var func, expectedVal, implementationDependant, test;
            for (var i = 0; i < values.length; i++) {
                func = values[i][0];
                expectedVal = values[i][1];
                implementationDependant = !!(values[i][2]);
                expect(
                        _R.getInternalClass(func)
                    )
                    .toEqual(
                        expectedVal
                    )
                    .setTestName('Is element ' + i + ' [[Class]] equal to ' + expectedVal + '?')
                    .run()
                    .end(implementationDependant);
            }
        })();

        (function() {
            console.log('\n\tTesting _R.createProxy \n');

            (function() {
                function Circle(r) {
                    this.diameter = undefined; // property have to exist
                    this.area = undefined; // property have to exist
                    this.radius = r;
                    return _R.createProxy(this, Circle.getter, Circle.setter);
                }
                Circle.getter = function circleGetter(originalObject, proxyObject, propertyName) {
                    if (propertyName === 'radius') {
                        return originalObject.radius;
                    }
                    if (propertyName === 'diameter') {
                        return proxyObject.radius * 2;
                    }
                    if (propertyName === 'area') {
                        return proxyObject.radius * proxyObject.radius * Math.PI;
                    }
                }
                Circle.setter = function circleSetter(originalObject, proxyObject, propertyName, propertyValue) {
                    if (propertyName !== 'radius') {
                        throw Error('You can not modify anything in circle except radius');
                    } else {
                        return originalObject.radius = propertyValue;
                    }
                }

                var k = new Circle(5);
                expect(k.radius * 2)
                    .toEqual(k.diameter)
                    .setTestName('k.radius *2 === k.diameter')
                    .run()
                    .end(); // true
                var test = expect(k.diameter);
                try {
                    k.diameter = 7; // Error: You can not modify anything in circle except radius
                    nonexistingVariableName;
                } catch (e) {
                    if (e.message === 'You can not modify anything in circle except radius')
                        test.toEqual(10)
                        .setTestName('was k.diameter modified? ')
                        .run()
                        .end();
                    else
                        throw new Error('Modification of k.diameter did not throw error. WTF is wrong with this engine?');
                }
                k.oh = 'hai'; // Error in strict mode; Does nothing outside of strict mode
                k.radius = 11; // works
                expect(k.diameter)
                    .toEqual(22)
                    .setTestName('k.diameter === 22')
                    .run()
                    .end();
            })();

        })();

        (function() {
            console.log('\n\tTesting _R.indirectEval \n');
            expect(_R.indirectEval('"wow"'))
            	.toEqual("wow")
            	.setTestName('Returning values from indirectEval. ')
            	.run()
            	.end();
			expect(_R.indirectEval('this'))
				.toEqual(global)
				.setTestName('Checking this in indirectEval. Should be global object. ')
				.run()
				.end();
			expect(_R.indirectEval('2+3'))
				.toEqual(5)
				.setTestName('Checking simple expressions in indirectEval. ')
				.run()
				.end()
			_R.indirectEval('var a = 3;')
			expect(global.a)
				.toEqual(undefined)
				.setTestName('Checking if indirectEval modifies global scope. ')
				.run()
				.end();

        })();

     console.log('\n\n\tTESTS PASSED SUCCESFULLY!\n\n');

    } catch (e) {
        console.log(e);
        throw e;
    }
})(typeof _R !== 'undefined' ? _R : require('./reflect-helpers.js'));
<commit_msg>Fixed formatting<commit_after>(function(_R) {
    var global = this || (1, eval)(this);
    try {
        function expect(expected) {
            expect.count = 0 || expect.count++;
            return {
                toEqual: function(actual) {
                    this.actual = actual;
                    return this;
                },
                setTestName: function(name) {
                    this.name = name;
                    return this;
                },
                run: function() {
                    // NaN case
                    if (this.expected !== this.expected) {
                        this.result = this.expected !== this.actual;
                    } else if (_R.getInternalClass(this.actual) === 'Array') {
                        if (this.expected.length !== this.actual.length) {
                            return false;
                        }
                        for (var i = 0; i < this.actual.length; i++) {
                            if (this.actual[i] !== this.expected[i]) {
                                return false;
                            }
                        }
                        return true;
                    } else {
                        this.result = (this.expected === this.actual);

                    }
                    return this;
                },
                end: function(implementationDependant) {
                    var message = 'Test. ' + (this.name || expect.count);
                    if (this.result === false) {
                        message += (implementationDependant ?
                            ' Depends on implementation, but it isn\'t behavior expected by _R.' :
                            'Ouh, it shouldn\'t work this way!');
                        console.warn(message);
                        if (!implementationDependant) {
                            throw JSON.stringify({
                                message: message,
                                expected: this.expected,
                                actual: this.actual
                            });
                        } else {
                            expect.log.push([message, this.expected, this.actual, Error()]);
                        }
                    } else if (this.result === true) {
                        message += ' Result is correct' + (implementationDependant ? ' (but it is implementation dependant)' : '') + '.';
                        console.log(message);
                    } else {
                        throw new Error('Invalid test case');
                    }
                },
                expected: expected,
                actual: undefined
            };
        }
        expect.log = [];
        (function() {
            console.log('\n\tTesting _R.isValidVariableName \n');
            var varsIdentifiers = [
                ['a', true],
                ['b', true],
                ['c', true],
                ['d', true],
                ['var', false],
                ['any way to do this is valid', false],
                [{
                        oh: 'hai'
                    },
                    false
                ],
                [{
                        toString: function() {
                            return 'fromToString';
                        }
                    },
                    true
                ],
                [4, false],
                ['4', false],
                [false, false],
                ['undefined', true],
                ['null', false],
                [null, false],
                ['"wow"', false],
                ['function', false],
                ['//wow', false, true],
                ['/* wow */ a', true],
                ['/* wow a', false, true],
            ];
            var id, expectedVal, implementationDependant, test;
            for (var i = 0; i < varsIdentifiers.length; i++) {
                id = varsIdentifiers[i][0];
                expectedVal = varsIdentifiers[i][1];
                implementationDependant = !!(varsIdentifiers[i][2]);
                expect(
                        _R.isValidVariableName(id)
                    )
                    .toEqual(
                        expectedVal
                    )
                    .setTestName('Is "' + id + '" valid variable name?')
                    .run()
                    .end(implementationDependant);
            }
        })();

        (function() {
            console.log('\n\tTesting _R.isBoundOrNativeFunction \n');
            var functions = [
                [
                    function a() {},
                    false
                ],
                [(function b() {})
                    .bind(null), true
                ],
                [console.log, true, true],
                [Date, true],
                [Date.bind(null), true],
                [setTimeout, true, true],
                [Date, true],
                [(function() {
                    /*
                        [native code]
                    */
                }), false],
                [(function a() {
                    a.toString = Function.toString.bind(setTimeout);
                    return a;
                })(), false],
                [eval, true]
            ];
            var prepare;
            try {
                prepare = [eval('() => global'), false];
                functions.push(prepare);
                prepare = [eval('(a) => a'), false];
                functions.push(prepare)
                prepare = [eval('(() => global).bind(null)'), true];
                functions.push(prepare)
            } catch (e) {
                console.log('\n\tThis implementation does not support arrow functions. Ommiting tests.\n');
            }
            var func, expectedVal, implementationDependant, test;
            for (var i = 0; i < functions.length; i++) {
                func = functions[i][0];
                expectedVal = functions[i][1];
                implementationDependant = !!(functions[i][2]);
                expect(
                        _R.isBoundOrNativeFunction(func)
                    )
                    .toEqual(
                        expectedVal
                    )
                    .setTestName('Is function ("' + (func.name || i) + '") native or bound?')
                    .run()
                    .end(implementationDependant);
            }
        })();

        (function() {
            console.log('\n\tTesting _R.getFunctionSourceCode \n');
            var functions = [
                [
                    function a() {}, 'function a() {}'
                ],
            ];
            var func, expectedVal, implementationDependant, test;
            for (var i = 0; i < functions.length; i++) {
                func = functions[i][0];
                expectedVal = functions[i][1];
                implementationDependant = !!(functions[i][2]);
                expect(
                        _R.getFunctionSourceCode(func)
                    )
                    .toEqual(
                        expectedVal
                    )
                    .setTestName('Can function ("' + (func.name || i) + '") code be retrieved?')
                    .run()
                    .end(implementationDependant);
            }
        })();

        (function() {
            console.log('\n\tTesting _R.getInternalClass \n');
            var values = [
                ['abcd', 'String'],
                [5, 'Number'],
                [null, 'Null', true],
                [undefined, 'Undefined', true],
                [Function(), 'Function'],
                [this, 'global', true],
                [{}, 'Object'],
                [
                    [], 'Array'
                ],
                [Infinity, 'Number'],
                [NaN, 'Number'],
                [true, 'Boolean'],
                [new String('oh hai'), 'String'],
            ];
            if (typeof Symbol !== 'undefined') {
                values.push([Symbol(), 'Symbol', true]);
            }
            var func, expectedVal, implementationDependant, test;
            for (var i = 0; i < values.length; i++) {
                func = values[i][0];
                expectedVal = values[i][1];
                implementationDependant = !!(values[i][2]);
                expect(
                        _R.getInternalClass(func)
                    )
                    .toEqual(
                        expectedVal
                    )
                    .setTestName('Is element ' + i + ' [[Class]] equal to ' + expectedVal + '?')
                    .run()
                    .end(implementationDependant);
            }
        })();

        (function() {
            console.log('\n\tTesting _R.createProxy \n');

            (function() {
                function Circle(r) {
                    this.diameter = undefined; // property have to exist
                    this.area = undefined; // property have to exist
                    this.radius = r;
                    return _R.createProxy(this, Circle.getter, Circle.setter);
                }
                Circle.getter = function circleGetter(originalObject, proxyObject, propertyName) {
                    if (propertyName === 'radius') {
                        return originalObject.radius;
                    }
                    if (propertyName === 'diameter') {
                        return proxyObject.radius * 2;
                    }
                    if (propertyName === 'area') {
                        return proxyObject.radius * proxyObject.radius * Math.PI;
                    }
                }
                Circle.setter = function circleSetter(originalObject, proxyObject, propertyName, propertyValue) {
                    if (propertyName !== 'radius') {
                        throw Error('You can not modify anything in circle except radius');
                    } else {
                        return originalObject.radius = propertyValue;
                    }
                }

                var k = new Circle(5);
                expect(k.radius * 2)
                    .toEqual(k.diameter)
                    .setTestName('k.radius *2 === k.diameter')
                    .run()
                    .end(); // true
                var test = expect(k.diameter);
                try {
                    k.diameter = 7; // Error: You can not modify anything in circle except radius
                    nonexistingVariableName;
                } catch (e) {
                    if (e.message === 'You can not modify anything in circle except radius')
                        test.toEqual(10)
                        .setTestName('was k.diameter modified? ')
                        .run()
                        .end();
                    else
                        throw new Error('Modification of k.diameter did not throw error. WTF is wrong with this engine?');
                }
                k.oh = 'hai'; // Error in strict mode; Does nothing outside of strict mode
                k.radius = 11; // works
                expect(k.diameter)
                    .toEqual(22)
                    .setTestName('k.diameter === 22')
                    .run()
                    .end();
            })();

        })();

        (function() {
            console.log('\n\tTesting _R.indirectEval \n');
            expect(_R.indirectEval('"wow"'))
                .toEqual("wow")
                .setTestName('Returning values from indirectEval. ')
                .run()
                .end();
            expect(_R.indirectEval('this'))
                .toEqual(global)
                .setTestName('Checking this in indirectEval. Should be global object. ')
                .run()
                .end();
            expect(_R.indirectEval('2+3'))
                .toEqual(5)
                .setTestName('Checking simple expressions in indirectEval. ')
                .run()
                .end()
            _R.indirectEval('var a = 3;')
            expect(global.a)
                .toEqual(undefined)
                .setTestName('Checking if indirectEval modifies global scope. ')
                .run()
                .end();

        })();

        console.log('\n\n\tTESTS PASSED SUCCESFULLY!\n\n');

    } catch (e) {
        console.log(e);
        throw e;
    }
})(typeof _R !== 'undefined' ? _R : require('./reflect-helpers.js'));<|endoftext|>


<commit_before>var gulp = require('gulp'),
	sass = require('gulp-sass'),
	autoprefixer = require('gulp-autoprefixer'),
	minifycss = require('gulp-minify-css'),
	jshint = require('gulp-jshint'),
	uglify = require('gulp-uglify'),
	concat = require('gulp-concat'),
	changed = require('gulp-changed'),
	notify = require('gulp-notify'),
	clean = require('gulp-clean'),
	git = require('gulp-git'),
	jscs = require('gulp-jscs'),
	header = require('gulp-header'),
	rename = require('gulp-rename'),
	browserSync = require('browser-sync');

var vars = {
	devDir: 'dev/',
	distDir: 'dist/',
	bowerJquery: 'bower_components/jquery/dist/jquery.js',
	bowerNormalize: 'bower_components/normalize-scss',
	pluginName: 'ysFilter'
}

//////////////////////////////////////////
// HEADER
//////////////////////////////////////////

var pkg = require('./package.json'),
	banner = [
		'/**',
		' * <%= pkg.name %> - <%= pkg.description %>',
		' * @version v<%= pkg.version %>',
		' * @link <%= pkg.homepage %>',
		' * @author <%= pkg.author %>',
		' * @license <%= pkg.license %>',
		' */',
		'',
	].join('\n');

//////////////////////////////////////////
// PUBLISHING
//////////////////////////////////////////

gulp.task('clean-live', function() {
	return gulp.src(vars.distDir+'*', {read: false})
    	.pipe(clean());
});

gulp.task('update-index', ['clean-live'], function() {
	return gulp.src([vars.devDir+'index.html'])
		.pipe(gulp.dest(vars.distDir));
})

gulp.task('update-scss', ['clean-live'], function() {
	return gulp.src([vars.devDir+'css/sass/_'+vars.pluginName+'.scss'])
		.pipe(gulp.dest(vars.distDir+'css'));
})

gulp.task('update-js', ['clean-live'], function() {
	return gulp.src([vars.devDir+'js/'+vars.pluginName+'.js'])
		.pipe(gulp.dest(vars.distDir+'js'));
})

gulp.task('publish-css', ['clean-live'], function() {
	return gulp.src(vars.devDir+'css/main.css')
		.pipe(minifycss({keepBreaks: true}))
		.pipe(gulp.dest(vars.distDir+'css'));
})

gulp.task('publish-js', ['clean-live'], function() {
	return gulp.src(vars.devDir+'js/'+vars.pluginName+'.js')
		.pipe(uglify())
		.pipe(header(banner, {pkg: pkg}))
		.pipe(rename({suffix: '.min'}))
		.pipe(gulp.dest(vars.distDir+'js'));
})

// Publish
gulp.task('publish', function() {
	gulp.start('update-index', 'update-js', 'update-scss', 'publish-css', 'publish-js');
})

//////////////////////////////////////////
// WATCHING
//////////////////////////////////////////

gulp.task('browser-sync', function() {
    browserSync.init(null, {
        proxy: vars.pluginName+".dev"
    });
});

gulp.task('main-css', function() {

	return gulp.src('dev/css/sass/*.scss')
		.pipe(
			sass({
				outputStyle: 'expanded',
				/*sourceComments: 'map',*/
				includePaths: [vars.bowerNormalize],
				errLogToConsole: false,
				onError: function(err) {
					return notify().write(err);
				}
			})
		)
		.pipe(
			autoprefixer(
				["> 1%", "last 2 versions", "Firefox ESR", "Opera 12.1"],
				{
					map: true,
					from: 'main.scss',
					to: 'main.css'
				}
			)
		)
		.pipe(gulp.dest(vars.devDir+'css')) //Dev version has compiled SCSS but not minified
		.pipe(browserSync.reload({stream:true}));
});

gulp.task('plugin-js', function() {
	return gulp.src([vars.devDir+'js/'+vars.pluginName+'.js', vars.devDir+'js/styling-example.js'])
		.pipe(jscs().on("error", notify.onError("JSCS: <%= error %>")))
		.pipe(jshint())
		.pipe(jshint.reporter('default'));
});

gulp.task('init-js', function() {
	return gulp.src([vars.bowerJquery])
		.pipe(gulp.dest(vars.devDir+'js'));
});

gulp.task('bs-reload', function() {
	browserSync.reload();
});

// Watch
gulp.task('default', ['plugin-js', 'init-js', 'main-css', 'browser-sync'], function() {

	//Watch files
	gulp.watch(vars.devDir+'css/sass/**/*.scss', ['main-css']);
	gulp.watch(vars.devDir+'js/'+vars.pluginName+'.js', ['plugin-js']);
	gulp.watch(vars.devDir+"*.html", ['bs-reload']);
	gulp.watch(vars.devDir+"*.js", ['bs-reload']);

});

<commit_msg>Fixed js lint problems<commit_after>var gulp = require('gulp'),
	sass = require('gulp-sass'),
	autoprefixer = require('gulp-autoprefixer'),
	minifycss = require('gulp-minify-css'),
	jshint = require('gulp-jshint'),
	uglify = require('gulp-uglify'),
	concat = require('gulp-concat'),
	changed = require('gulp-changed'),
	notify = require('gulp-notify'),
	clean = require('gulp-clean'),
	git = require('gulp-git'),
	jscs = require('gulp-jscs'),
	header = require('gulp-header'),
	rename = require('gulp-rename'),
	browserSync = require('browser-sync');

var vars = {
	devDir: 'dev/',
	distDir: 'dist/',
	bowerJquery: 'bower_components/jquery/dist/jquery.js',
	bowerNormalize: 'bower_components/normalize-scss',
	pluginName: 'ysFilter'
};

//////////////////////////////////////////
// HEADER
//////////////////////////////////////////

var pkg = require('./package.json'),
	banner = [
		'/**',
		' * <%= pkg.name %> - <%= pkg.description %>',
		' * @version v<%= pkg.version %>',
		' * @link <%= pkg.homepage %>',
		' * @author <%= pkg.author %>',
		' * @license <%= pkg.license %>',
		' */',
		'',
	].join('\n');

//////////////////////////////////////////
// PUBLISHING
//////////////////////////////////////////

gulp.task('clean-live', function() {
	return gulp.src(vars.distDir+'*', {read: false})
    .pipe(clean());
});

gulp.task('update-index', ['clean-live'], function() {
	return gulp.src([vars.devDir+'index.html'])
		.pipe(gulp.dest(vars.distDir));
});

gulp.task('update-scss', ['clean-live'], function() {
	return gulp.src([vars.devDir+'css/sass/_'+vars.pluginName+'.scss'])
		.pipe(gulp.dest(vars.distDir+'css'));
});

gulp.task('update-js', ['clean-live'], function() {
	return gulp.src([vars.devDir+'js/'+vars.pluginName+'.js'])
		.pipe(gulp.dest(vars.distDir+'js'));
});

gulp.task('publish-css', ['clean-live'], function() {
	return gulp.src(vars.devDir+'css/main.css')
		.pipe(minifycss({keepBreaks: true}))
		.pipe(gulp.dest(vars.distDir+'css'));
});

gulp.task('publish-js', ['clean-live'], function() {
	return gulp.src(vars.devDir+'js/'+vars.pluginName+'.js')
		.pipe(uglify())
		.pipe(header(banner, {pkg: pkg}))
		.pipe(rename({suffix: '.min'}))
		.pipe(gulp.dest(vars.distDir+'js'));
});

// Publish
gulp.task('publish', function() {
	gulp.start('update-index', 'update-js', 'update-scss', 'publish-css', 'publish-js');
});

//////////////////////////////////////////
// WATCHING
//////////////////////////////////////////

gulp.task('browser-sync', function() {
    browserSync.init(null, {
        proxy: vars.pluginName+".dev"
    });
});

gulp.task('main-css', function() {

	return gulp.src('dev/css/sass/*.scss')
		.pipe(
			sass({
				outputStyle: 'expanded',
				/*sourceComments: 'map',*/
				includePaths: [vars.bowerNormalize],
				errLogToConsole: false,
				onError: function(err) {
					return notify().write(err);
				}
			})
		)
		.pipe(
			autoprefixer(
				["> 1%", "last 2 versions", "Firefox ESR", "Opera 12.1"],
				{
					map: true,
					from: 'main.scss',
					to: 'main.css'
				}
			)
		)
		.pipe(gulp.dest(vars.devDir+'css')) //Dev version has compiled SCSS but not minified
		.pipe(browserSync.reload({stream:true}));
});

gulp.task('plugin-js', function() {
	return gulp.src([vars.devDir+'js/'+vars.pluginName+'.js', vars.devDir+'js/styling-example.js'])
		.pipe(jscs().on("error", notify.onError("JSCS: <%= error %>")))
		.pipe(jshint())
		.pipe(jshint.reporter('default'));
});

gulp.task('init-js', function() {
	return gulp.src([vars.bowerJquery])
		.pipe(gulp.dest(vars.devDir+'js'));
});

gulp.task('bs-reload', function() {
	browserSync.reload();
});

// Watch
gulp.task('default', ['plugin-js', 'init-js', 'main-css', 'browser-sync'], function() {

	//Watch files
	gulp.watch(vars.devDir+'css/sass/**/*.scss', ['main-css']);
	gulp.watch(vars.devDir+'js/'+vars.pluginName+'.js', ['plugin-js']);
	gulp.watch(vars.devDir+"*.html", ['bs-reload']);
	gulp.watch(vars.devDir+"*.js", ['bs-reload']);

});

<|endoftext|>