Skip to content

Commit

Permalink
Feature/1.0.0/main structure (#103)
Browse files Browse the repository at this point in the history
* added the ability to add documentation

This will allow us to document the api to make it easier to know what's avaiable and what's actually going on.

* removed Yarn for now

This is because yarn doesn't handle binaries correctly, and also doesn't handle things like couchbase which have node-gyp and that have to compile when it's being installed.

* Moved the cli to to be under `cli.js`

* Renamed `generator.js` to be `index.js`

This is so that the main file will  be the `index.js` file. This way we can export it and get the same functionality.

* added the Logger to the utils

This will be the base logger that is used throughout the application

* added documentation to the other util functions

* added support for ci testing

* added unit tests and bug fixes for `utils.js`

* syntax update

* added `base.js` which will be the base for all the classes

This will allow you to run each of the functionalities separately without having to depend on each other. It will also allow the logging to be consistent throught the app.

* added ability to pass a glob to `utils.findFiles`

* updated the way models were parsed

This update removed global variables that were being used in those functions, in favor of passing in the model that is being manipulated.

Also removes the logic that was being used to resolve dependencies in favor of using `dependency-resolver` that already handles this functionality. This will reduce the amount of testing that we have to do around this file.

* added babel-external-helpers

* Updated input to be a class

* updated models to be a class

Also drastically simplified the exisitng code by reworking a few functions and using dependency-resolver to resolve the different dependencies for each model

* updated the main fakit function to be a class

This main function extends Inputs, Models, and the Base

* Updated the cli to only pass valid options.

* Updated documents to be a class

Also updated to generate documents in documents instead of in models

* Updated to return models as an array

This update is to remove the need for `this.model_order` by ordering them to begin with.

* Cleaned up the cli

Also added several todo items to help the various changes that need to take place before the release.

* replaced `--format` with `--spacing`

* Added the base for the new Output class

This also adds tests for validation and options that have been passed.

* Added the base functionality to the outputters

* Finished folder output

Complete with tests

* added a pool utility function

This is a function that is similar to `map` but it will limit the concurrancy of the functions that're running.

* updated archive option to be a filename

* added the zip output type

complete with tests

* general cleanup

* removed the need for output document

* added the `key` generated document

* updated the way the setup function determins the outputter

This update is to accomidate the `return` option

* update the file generation for the zip test

This just updates the location as to where the files get created.

* added the base for `Output.output`

This also adds test cases for the different types and languages.

* added a few prepare tests for output

* added the finalize function

* added the timeout option that's used for servers

* setup the rest of the sync-gateway output

* setup the rest of couchbase output

* removed `object-path` in favor of lodash `set` and `get`

* cleaned up dependencies

* fixed bug with the verbose logging option

* Updated couchbase output to use `couchbase-promises`

Also added test cases for them to ensure it's working correctly

* Added a few tests for sync-gateway

* remove the Documents class because it's no longer needed

* Updated the main fakit class

* added nyc code coverage

* added the basis for testing the data generation

* 🗑removed the `output.js`
  • Loading branch information
tjbenton authored Dec 12, 2016
1 parent 5047bcd commit 3efc1ec
Show file tree
Hide file tree
Showing 142 changed files with 130,698 additions and 1,030 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"stage-0"
],
"plugins": [
"transform-runtime"
"transform-runtime",
"external-helpers"
]
}
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
*.log
*.DS_Store
*.bak
*.csv
export/
.TemporaryItems
dist/
Thumbs.db
thumbs.db
.vagrant/
node_modules/
temp/
.nyc*
.nyc*
coverage
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ app/
examples
test
.eslint*
Makefile
Makefile
.nyc*
coverage
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,21 @@ build compile:
babel app --out-dir dist $(args)

watch:
make build -- --watch
make build -- --watch $(args)

lint:
eslint 'app' 'test'

test:
ava $(args)

test-coverage:
babel app --out-dir dist --source-maps
nyc make test

coverage code-coverage:
NODE_ENV=test nyc

ci:
make lint
make build
Expand Down
47 changes: 47 additions & 0 deletions app/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import path from 'path';
import to from 'to-js';
import * as utils from './utils';

/// @name Base
/// @page api
/// @description
/// This holds the base functions that each of the classes in the application will exten
export default class Base extends utils.Logger {
/// @name constructor
/// @arg {object} options - Global options for the different classes
/// @raw-code
constructor(options = {}) {
super(options);
this.options = to.extend({
root: process.cwd(),
log: true,
verbose: false,
timestamp: true,
}, this.options || {});
this.options = to.extend(this.options, options);

if (this.options.verbose) {
this.options.log = true;
}
}

///# @name resolvePaths
///# @description
///# This is ued to parsed paths that are passed to the different functions
///# @arg {string, array} paths - The paths to normalize
///# @arg {}
resolvePaths(paths) {
if (!paths) {
return [];
}
return to.string(paths, ', ')
.split(/\s*(?:,| )\s*/)
.filter(Boolean)
.map((file) => {
if (path.isAbsolute(file)) {
return file;
}
return path.join(this.options.root, file);
});
}
}
88 changes: 66 additions & 22 deletions app/cli.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,90 @@
import program from 'commander';
import fakeit from './index.js';
import Fakeit from './index.js';
import updateNotifier from 'update-notifier';
import pkg from './../package.json';
import { pick, omit } from 'lodash';
import chalk from 'chalk';
import to from 'to-js';

export default async function() {
// check for update and notify
updateNotifier({ pkg }).notify();

// const deprecated = chalk.red('[DEPRECATED]:');

// get the inputs
program
.version(pkg.version)
.usage('fakeit [options]')
.option('-o, --output [value]', 'The output format to generate. Supported formats are: json, csv, yaml, cson', 'json')
.option('-a, --archive [value]', 'The archive file to generate. Supported formats are: zip')
.option('-m, --models [value]', 'A directory or comma-delimited list of files models to use.', process.cwd())
.option('-d, --destination [value]', 'The output destination. Values can be: couchbase, console or a directory path.', 'console')
.option('-f, --format [value]', 'The spacing format to use for JSON and YAML file generation. Default is 2', 2)

// @todo change this option to be `--format`
.option('-o, --output [value]', `The output format to generate. Supported formats: ${code('json', 'csv', 'yaml', 'yml', 'cson')}. (${dim('json')})`, 'json') // eslint-disable-line max-len

// @todo change this option to a file path and determin the type based off the extention.
.option('-a, --archive [value]', 'The archive file to generate. Supported formats are: zip')

// @todo change this option to be the last argument passed to `fakeit`
.option('-m, --models [value]', `A directory or comma-delimited list of files models to use. (${dim(process.cwd())})`, process.cwd())

// @todo change this option to `--output`
.option('-d, --destination [value]', `The output destination. Supported values: ${code('couchbase', 'sync-gateway', 'console')} or a ${code('directory path')}. (${dim('console')})`, 'console') // eslint-disable-line max-len

// @todo change this option to be `-n`
.option('-f, --spacing [value]', `The spacing format to use for JSON and YAML file generation. ${code('2')}`, 2)

// @todo change this option to be `--count`
.option('-n, --number [value]', 'Overrides the number of documents to generate specified by the model.')
.option('-i, --input [value]', 'Directory or comma-delimited list of files to use as inputs. Support formats are: json, yaml, csv, cson, zip')
.option('-s, --server [address]', 'Couchbase Server or Sync-Gateway address', '127.0.0.1')
.option('-b, --bucket [name]', 'The name of a Couchbase Bucket. The default value is: default', 'default')

// @todo deprecate this option after the `input` has moved to the model layer.
.option('-i, --input [value]', `List of globs to use as inputs. Support formats are: ${code('json', 'yaml', 'yml', 'csv', 'cson', 'zip')}`)

// @todo move these option to `fakeit serve` or `fakeit server`.
.option('-s, --server [address]', `Couchbase Server or Sync-Gateway address. (${dim('127.0.0.1')})`, '127.0.0.1')
.option('-b, --bucket [name]', `The name of a Couchbase Bucket. (${dim('default')})`, 'default')
.option('-p, --password [value]', 'Bucket password')
.option('-t, --timeout [value]', 'A timeout value for database operations', 5000)
.option('-l, --limit [value]', 'Limit the number of save operations at a time. Default: 100', 100)
.option('-u, --username [name]', 'The sync-gateway username')
.option('-e, --exclude [model]', 'A comma-delimited list of model names to exclude from output', '')

.option('-t, --timeout [value]', 'A timeout value for database operations', 5000)
.option('-l, --limit [value]', `Limit the number of save operations at a time. (${dim('100')})`, 100)
.option('-v, --verbose', 'Whether or not to use verbose output')

// @todo deprecate this option after the way models are parsed has been updated to automatically include other dependencies.
.option('-e, --exclude [model]', 'A comma-delimited list of model names to exclude from output', '')
.parse(process.argv);

// run the program
fakeit(program)
.then(() => {
// console.log('Data Generation Complete');
process.exit();
})
.catch((err) => {
console.error(err);
process.exit(1);
});

let output_options = [
'spacing',
'output',
'server',
'bucket',
'password',
'username',
'destination',
'archive',
];
const options = omit(program, output_options);
output_options = pick(program, output_options);

const fakeit = new Fakeit(options);
try {
await fakeit.generate(program.models, output_options);
process.exit();
} catch (err) {
console.error(err);
process.exit(1);
}
}

process.on('uncaughtException', (err) => {
console.error('An uncaughtException was found:', err);
process.exit(1);
});

export function code(...args) {
return to.flatten(args).map((str) => chalk.bold(str)).join(', ');
}

export function dim(...args) {
return to.flatten(args).map((str) => chalk.dim(str)).join(', ');
}
Loading

0 comments on commit 3efc1ec

Please sign in to comment.