Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ node_js:
- "node"
os:
- linux
- osx
install:
- npm install
- npm run build-cli
- npm link
script:
- node --harmony bin/index.js build
- node --harmony bin/index.js test
test-production:
- npm unlink
- npm install -g rimraf
- rimraf node_modules
- npm install --production
- node --harmony bin/index.js --help
after_success:
- bash <(curl -s https://codecov.io/bash)
28 changes: 1 addition & 27 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1 @@
version: 1.0.{build}
environment:
matrix:
- nodejs_version: "6.5.0"
platform:
- x86
- x64
pull_requests:
do_not_increment_build_number: true
skip_branch_with_pr: true
install:
- ps: Install-Product node $env:nodejs_version $env:platform
build_script:
- cmd: >-
npm install

npm run build-cli

npm link

tyche build
test_script:
- cmd: >-
tyche test

bash <(curl -s https://codecov.io/bash)
deploy: off
version: 1.0.{build}environment: matrix: - nodejs_version: "6.5.0"platform: - x86 - x64pull_requests: do_not_increment_build_number: trueskip_branch_with_pr: trueinstall: - ps: Install-Product node $env:nodejs_version $env:platformbuild_script:- cmd: >- npm install npm run build-cli npm link tyche buildtest_script:- cmd: >- tyche test npm install -g rimraf npm unlink rimraf node_modules npm install --production npm link --production tyche --helpdeploy: off
Expand Down
2 changes: 1 addition & 1 deletion docs/js/highlight.pack.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/js/jquery-2.x.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/themes/hugo-theme-learn/static/js/highlight.pack.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/themes/hugo-theme-learn/static/js/jquery-2.x.min.js

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@
"cli-logger": "^0.5.40",
"cli-spinner": "0.2.5",
"commander": "2.9.0",
"glob": "^7.0.6",
"glob": "^7.1.0",
"lokijs": "1.4.1",
"promisify-node": "^0.4.0",
"semver": "^5.3.0"
},
"devDependencies": {
"babel-cli": "6.14.0",
"babel-eslint": "6.1.2",
"babel-jest": "^15.0.0",
"babel-cli": "^6.16.0",
"babel-eslint": "^7.0.0",
"babel-jest": "^16.0.0",
"babel-plugin-module-resolver": "^2.2.0",
"babel-polyfill": "6.13.0",
"babel-preset-es2015": "6.14.0",
"babel-preset-es2016": "6.11.3",
"babel-preset-es2017": "6.14.0",
"babel-preset-stage-3": "6.11.0",
"eslint": "^3.5.0",
"babel-polyfill": "^6.16.0",
"babel-preset-es2015": "^6.16.0",
"babel-preset-es2016": "^6.16.0",
"babel-preset-es2017": "^6.16.0",
"babel-preset-stage-3": "^6.17.0",
"eslint": "^3.7.1",
"eslint-import-resolver-babel-module": "2.0.1",
"eslint-plugin-import": "^1.15.0",
"eslint-plugin-import": "^2.0.0",
"eslint-plugin-jasmine": "1.8.1",
"jest-cli": "15.1.1"
"jest-cli": "^16.0.0"
},
"bin": {
"tyche": "./bin/index.js"
Expand Down
201 changes: 22 additions & 179 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,186 +1,29 @@
#!/usr/bin/env node --harmony
import path from 'path';
import program from 'commander';
import { Spinner } from 'cli-spinner';
import Config from 'lib/config';
import {dbFile, configPath} from 'lib/config/paths';
import TycheDb from 'lib/database';
import ToolMachine from 'lib/tool';
import Hooks from 'lib/hooks';
import Logger from 'lib/logger';
import semver from 'semver';

const Log = Logger.child({
component: 'Main'
});
import input from 'lib/parser/inputStream';
import tokens from 'lib/parser/tokenStream';
import util from 'util';
import TaskEnvironment, {EvaluateAST} from 'lib/parser/task';
import parser from 'lib/parser/parser';
import fs from 'fs';

program.version(require(path.normalize(`${__dirname}/../package.json`)).version);
const file = fs.readFileSync('./tyche.tasks', {encoding: 'utf8'});

Spinner.setDefaultSpinnerString(21);
const spinner = new Spinner('Loading...');
spinner.start();
console.log(file);

async function getAppDb(dbFile) {
const database = new TycheDb(dbFile);
await database.initializeDb();
return database;
let inp = new input(file);
let toks = new tokens(inp);
while(!toks.eof()) {
console.log(toks.next());
}

function getConfig(database) {
return Config.loadConfig(path.normalize(`${configPath()}/./tyche.json`), database);
}

function generateCommands(config, vars) {
for (const command of config.tasks.tasks) {
const name = command.name;
if (name === 'bump') {
continue; // bump is reserved
}
const description = command.description || 'run task';
const subCommands = command.children().join('|');

program.command(`${name} [${subCommands}]`)
.description(description)
.option('-t, --tool <tool>', 'use the default tool')
.option('-d, --dry', 'Show all the commands the tool is about to run')
.action((subcommand, options) => {
if (typeof subcommand === 'object') {
options = subcommand;
subcommand = null;
}

while(process.argv[0].indexOf('tyche') < 0) {
process.argv.shift();
}
process.argv.shift(); // remove the tyche command
process.argv.shift(); // remove the command
if (subcommand) process.argv.shift(); // remove the subcommand

vars.command = command;
vars.tool = options.tool;
vars.subcommand = subcommand;
vars.dry = options.dry;
});
}
}

async function tyche() {
//todo: Read repo state

const vars = {
command: null,
tool: null,
subcommand: null,
dry: false,
force: false
};

// manually search for this parameter, because we want it defined, first thing
for(const param of process.argv) {
if (param === '-v' || param === '--verbose') {
Logger.level(Logger.TRACE);
}
}

program.option('-v, --verbose', 'Turn on verbose logging', () => {});

const database = await getAppDb(dbFile);
const config = getConfig(database);

generateCommands(config, vars);

program.command('init')
.description('Initialize the tool in this repository')
.action(async () => {
const hook = new Hooks(await configPath());
await hook.install('pre-commit');
await hook.install('pre-push');
await hook.install('post-checkout');
await hook.install('post-merge');
});

program.command('bump')
.description('Bump the build number +1')
.option('--set <number>', 'set the build number to a specific value')
.option('-i, --level [level]', 'if you are using semver, this is one of major, minor, patch, premajor, preminor, prepatch, or prerelease. Default level is patch.')
.option('-p, --preid <identifier>', 'if you are using semver, used to prefix premajor, preminor, prepatch or prerelease version increments.')
.action(async (options) => {
const prevVersion = database.buildNumber;
let newVersion = prevVersion;
if (semver.valid(prevVersion)) {
const level = options.level || 'patch';
const preid = options.preid || null;
newVersion = semver.inc(prevVersion, level, preid);
if (prevVersion[0] == 'v') {
newVersion = `v${newVersion}`;
}
}
else if (Number.parseInt(newVersion)) {
newVersion = prevVersion + 1;
}
else {
Logger.error(`I don't know how to increment ${prevVersion} -- try calling with '--set' to bump the version`);
}
if (options.set) {
newVersion = options.set;
}
if (options.level) {
if (semver.valid(newVersion)) {
semver.inc()
}
}
database.buildNumber = newVersion;
console.log(`Version set ${prevVersion} --> ${newVersion}`);
const bump_task = config.tasks.search('bump');
if (bump_task) {
// we have to reload the config (this is ugly)
const config = Config.loadConfig(path.normalize(`${configPath()}/./tyche.json`), database);
const bump_task = config.tasks.search('bump');
await bump_task.execute(ToolMachine(config.defaultTool));
}
});

spinner.stop();
program.parse(process.argv);

if (vars.command) {
let doit = 'execute';
if (vars.dry) {
doit = 'dry';
}

let preferredToolString = config.defaultTool;
if (vars.tool) {
preferredToolString = vars.tool;
}

Log.trace(`Preferred Tool: ${preferredToolString}`);

let command = vars.command;
if (vars.subcommand) {
command = command.tasks.find((e) => e.name === vars.subcommand);
}

command.reduce();

//todo: A proper output
console.log(await command[doit](ToolMachine(preferredToolString)));
}

// I've seen this event fire more than once, so we only really care about the first time.
// This also prevents us from saving the database state if the process exits unexpectedly
let exiting = false;
process.on('beforeExit', () => exiting ? null : exiting = true && database.finish());
};

async function main() {
try {
await tyche();
console.log("May fortune find you!");
} catch(err) {
console.error(err);
process.exit(1);
}
};

main();
inp = new input(file);
toks = new tokens(inp);
console.log("\n**********\n");
const ast = new parser(toks);
const parsed = ast.parse();
console.log(util.inspect(parsed, false, null));
console.log("\n**********\n");
const top = new TaskEnvironment();
const evaluated = EvaluateAST(parsed, top);
console.log(util.inspect(evaluated, false, null));
2 changes: 1 addition & 1 deletion src/lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Log from 'cli-logger';

const logger = Log({
src: true,
level: process.env.NODE_ENV == 'test' ? Log.TRACE : Log.WARN,
level: process.env.NODE_ENV == 'test' ? Log.TRACE : Log.TRACE,
console: false,
prefix: function(record) {
return `${new Date()} (${record.component || 'Main'}) [${this.names(record.level)}] <${record.src.file || ''}:${record.src.line || ''}>: `;
Expand Down
36 changes: 36 additions & 0 deletions src/lib/parser/__tests__/inputStream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import stream from 'lib/parser/inputStream';

const file = `abcd

123`;

describe('inputStream', () => {
it('returns something', () => {
expect(new stream(file)).toBeDefined();
});

it('can peek', () => {
const s = new stream(file);
expect(s.peek()).toBe('a');
});
it('can read a file', () => {
const r = [];
const s = new stream(file);
while(!s.eof()) {
r.push(s.next());
}
expect(r.join('')).toBe(file);
});
it('will fail when told to', () => {
const s = new stream(file);
expect(s.die).toThrow();
});
it('can handle empty files', () => {
const s = new stream('');
expect(s.eof()).toBe(true);
});
it('can handle null files', () => {
const s = new stream();
expect(s.eof()).toBe(true);
})
});
Loading