Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feature/1.0.0/main structure #103

Merged
merged 50 commits into from
Dec 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e826eeb
added the ability to add documentation
tjbenton Nov 22, 2016
c1d19cf
removed Yarn for now
tjbenton Nov 22, 2016
e72acb2
Moved the cli to to be under `cli.js`
tjbenton Nov 22, 2016
0f1ccd9
Renamed `generator.js` to be `index.js`
tjbenton Nov 22, 2016
97ff8ea
added the Logger to the utils
tjbenton Nov 22, 2016
844b756
added documentation to the other util functions
tjbenton Nov 22, 2016
6b635ec
added support for ci testing
tjbenton Nov 22, 2016
3b21a49
added unit tests and bug fixes for `utils.js`
tjbenton Nov 22, 2016
c48203a
Merge branch 'release/1.0.0' of https://github.com/bentonam/fakeit in…
tjbenton Nov 22, 2016
c5b119b
syntax update
tjbenton Nov 22, 2016
c74b7e1
added `base.js` which will be the base for all the classes
tjbenton Nov 23, 2016
eb5f3ed
Merge branch 'release/1.0.0' of https://github.com/bentonam/fakeit in…
tjbenton Nov 23, 2016
3cd6cbc
added ability to pass a glob to `utils.findFiles`
tjbenton Nov 23, 2016
4c6b15e
updated the way models were parsed
tjbenton Nov 23, 2016
f660e79
added babel-external-helpers
tjbenton Nov 30, 2016
3e587c2
Updated input to be a class
tjbenton Nov 30, 2016
65bebcf
updated models to be a class
tjbenton Nov 30, 2016
19ad532
updated the main fakit function to be a class
tjbenton Nov 30, 2016
616a9fa
Updated the cli to only pass valid options.
tjbenton Nov 30, 2016
00f939d
Updated documents to be a class
tjbenton Nov 30, 2016
02dafad
Updated to return models as an array
tjbenton Nov 30, 2016
2f22e7d
Cleaned up the cli
tjbenton Dec 1, 2016
f7cbe49
replaced `--format` with `--spacing`
tjbenton Dec 1, 2016
981b403
Added the base for the new Output class
tjbenton Dec 2, 2016
621b442
Added the base functionality to the outputters
tjbenton Dec 2, 2016
e6d8881
Finished folder output
tjbenton Dec 2, 2016
dc1b6a2
added a pool utility function
tjbenton Dec 5, 2016
c3ad71a
updated archive option to be a filename
tjbenton Dec 5, 2016
0780d0d
added the zip output type
tjbenton Dec 6, 2016
f32e8a1
general cleanup
tjbenton Dec 6, 2016
bd15f84
removed the need for output document
tjbenton Dec 6, 2016
6801ed5
added the `key` generated document
tjbenton Dec 6, 2016
f46ea03
updated the way the setup function determins the outputter
tjbenton Dec 6, 2016
5dd2551
update the file generation for the zip test
tjbenton Dec 6, 2016
bf47fb7
added the base for `Output.output`
tjbenton Dec 7, 2016
5309c3b
added a few prepare tests for output
tjbenton Dec 7, 2016
ad71839
added the finalize function
tjbenton Dec 7, 2016
3c716f3
added the timeout option that's used for servers
tjbenton Dec 7, 2016
f2475f7
setup the rest of the sync-gateway output
tjbenton Dec 7, 2016
99713f4
setup the rest of couchbase output
tjbenton Dec 7, 2016
2e4d092
removed `object-path` in favor of lodash `set` and `get`
tjbenton Dec 7, 2016
921c484
cleaned up dependencies
tjbenton Dec 7, 2016
40a73ce
fixed bug with the verbose logging option
tjbenton Dec 8, 2016
9787b1c
Updated couchbase output to use `couchbase-promises`
tjbenton Dec 8, 2016
3ba07cd
Added a few tests for sync-gateway
tjbenton Dec 8, 2016
c7beb54
remove the Documents class because it's no longer needed
tjbenton Dec 9, 2016
2a6a2b1
Updated the main fakit class
tjbenton Dec 9, 2016
49e5c94
added nyc code coverage
tjbenton Dec 9, 2016
1a854af
added the basis for testing the data generation
tjbenton Dec 9, 2016
8921685
🗑removed the `output.js`
tjbenton Dec 12, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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