Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
feat: Set package.json defaults; init tslint, tsconfig, webpack, src,…
Browse files Browse the repository at this point in the history
… test

Squashed commit of the following:

commit 63c485f
Author: Arturas <a.molcanovas@gmail.com>
Date:   Tue Sep 25 01:31:05 2018 +0100

    Merge remote-tracking branch 'origin/master' into staging
    
    # Conflicts:
    #	yarn.lock

commit 1b36960
Merge: 1ad96b5 0a91c09
Author: Arturas <a.molcanovas@gmail.com>
Date:   Tue Sep 25 01:30:11 2018 +0100

    Merge branch 'staging' into pkg-json-defaults
    
    # Conflicts:
    #	yarn.lock

commit 1ad96b5
Author: Arturas <a.molcanovas@gmail.com>
Date:   Tue Sep 25 01:27:26 2018 +0100

    init tests

commit 7e03a9e
Author: Arturas <a.molcanovas@gmail.com>
Date:   Tue Sep 25 00:30:06 2018 +0100

    remote getter tests

commit ee7edd3
Author: Arturas <a.molcanovas@gmail.com>
Date:   Mon Sep 24 23:51:23 2018 +0100

    increase init test timeout & add alobuild to travis cache

commit efc393b
Author: Arturas <a.molcanovas@gmail.com>
Date:   Mon Sep 24 23:00:37 2018 +0100

    webpack config

commit 0b5b54b
Author: Arturas <a.molcanovas@gmail.com>
Date:   Mon Sep 24 22:40:26 2018 +0100

    fix exec local TS_NODE_TRANSPILE_ONLY env var

commit 3869141
Author: Arturas <a.molcanovas@gmail.com>
Date:   Mon Sep 24 22:40:13 2018 +0100

    ensure no duplicates are set in default deps

commit 447dc16
Author: Arturas <a.molcanovas@gmail.com>
Date:   Mon Sep 24 22:34:21 2018 +0100

    add test:watch script

commit 79c3c46
Author: Arturas <a.molcanovas@gmail.com>
Date:   Mon Sep 24 22:28:46 2018 +0100

    add typecheck scripts

commit 3689731
Author: Arturas <a.molcanovas@gmail.com>
Date:   Mon Sep 24 22:26:54 2018 +0100

    tslint

commit a132767
Author: Arturas <a.molcanovas@gmail.com>
Date:   Mon Sep 24 22:24:07 2018 +0100

    build scripts + tsc config

commit f212578
Author: Arturas <a.molcanovas@gmail.com>
Date:   Mon Sep 24 21:45:03 2018 +0100

    set typescript version to exact

commit a6ba7f4
Author: Arturas <a.molcanovas@gmail.com>
Date:   Mon Sep 24 21:37:27 2018 +0100

    add basic logging

commit 0bb8fc4
Author: Arturas <a.molcanovas@gmail.com>
Date:   Mon Sep 24 20:36:36 2018 +0100

    add tslib & types/node to default deps

commit f6ffa81
Author: Arturas <a.molcanovas@gmail.com>
Date:   Sat Sep 22 17:52:57 2018 +0100

    stub test case generation

commit ec30056
Author: Arturas <a.molcanovas@gmail.com>
Date:   Sat Sep 22 16:19:22 2018 +0100

    default scripts, deps

commit 78b49ee
Author: Arturas <a.molcanovas@gmail.com>
Date:   Sat Sep 22 15:58:01 2018 +0100

    pkg-version sync impl

commit ab6103e
Author: Arturas <a.molcanovas@gmail.com>
Date:   Sat Sep 22 15:46:03 2018 +0100

    get npm package version

commit aaffbf8
Merge: 1459cc1 a1e0916
Author: Arturas <a.molcanovas@gmail.com>
Date:   Sat Sep 22 11:45:31 2018 +0100

    Merge branch 'staging' into pkg-json-defaults

commit 1459cc1
Author: Arturas <a.molcanovas@gmail.com>
Date:   Wed Sep 19 21:48:12 2018 +0100

    base project init

commit 956a832
Merge: 0e4bc48 9d63a78
Author: Arturas <a.molcanovas@gmail.com>
Date:   Tue Sep 18 00:32:00 2018 +0100

    Merge branch 'staging' into pkg-json-defaults

commit 0e4bc48
Author: Arturas <a.molcanovas@gmail.com>
Date:   Tue Sep 18 00:31:41 2018 +0100

    tmp
  • Loading branch information
Alorel committed Sep 25, 2018
1 parent 0a91c09 commit bd68807
Show file tree
Hide file tree
Showing 37 changed files with 1,420 additions and 41 deletions.
11 changes: 8 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ before_install:

install: yarn install --check-files --ignore-engines

script: yarn run tslint && yarn run build --noEmit && yarn test --forbid-only --forbid-pending
script:
- yarn run tslint
- yarn run build --noEmit
- if [[ $GH_TOKEN ]]; then yarn test --forbid-only --forbid-pending; else yarn test --forbid-only; fi;

after_script: if [[ $GH_TOKEN ]]; then greenkeeper-lockfile-upload; fi;
after_success: cat ./coverage/lcov.info | coveralls

cache:
yarn: true
directories:
- /home/travis/.cache/alobuild

stages:
- Test
Expand All @@ -32,8 +37,8 @@ jobs:
- npm i -g yarn
- *prepKey
before_script:
- yarn run build
- node dist/alo copy-files
- yarn run build
- node dist/alo copy-files
script: semantic-release
after_success: []
after_script: []
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@
"delete-empty": "^2.0.0",
"fs-extra": "^7.0.0",
"glob": "^7.0.0",
"json-to-graphql-query": "^1.7.0",
"json5": "^2.0.0",
"lodash": "^4.17.0",
"log-symbols": "^2.2.0",
"readline-sync": "^1.4.0",
"reflect-metadata": "^0.1.12",
"request": "^2.88.0",
"request-promise": "^4.2.0",
"tslib": "^1.9.0",
"tslint": "5.11.0",
"typescript": "~3.0.0",
"typescript-lazy-get-decorator": "^1.2.0",
"yamljs": "^0.3.0",
"yargs": "^12.0.0"
Expand All @@ -64,9 +69,12 @@
"@types/glob": "~7.1.0",
"@types/json5": "~0.0.30",
"@types/lodash": "~4.14.116",
"@types/log-symbols": "~2.0.0",
"@types/mocha": "~5.2.5",
"@types/node": "~10.11.0",
"@types/readline-sync": "~1.4.3",
"@types/request": "~2.47.1",
"@types/request-promise": "~4.1.42",
"@types/tmp": "~0.0.33",
"@types/uuid": "~3.4.4",
"@types/yamljs": "~0.2.30",
Expand All @@ -82,7 +90,6 @@
"source-map-support": "~0.5.9",
"tmp": "~0.0.33",
"ts-node": "~7.0.1",
"typescript": "~3.0.1",
"uuid": "~3.3.2"
}
}
}
2 changes: 1 addition & 1 deletion src/commands/cfg/clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {cmdName} from '../../fns/cmdName';
import {ConfigWriter} from '../../lib/ConfigWriter';

function prompt(): boolean {
return readline.keyInYNStrict('Are you sure you want to remove shared config?');
return readline.keyInYNStrict('Are you sure you want to remove shared config? ');
}

const cmd: CommandModule = {
Expand Down
15 changes: 15 additions & 0 deletions src/commons/buildType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {Options} from 'yargs';
import {Obj} from '../interfaces/OptionsObject';

export interface HasUmd {
umd: string;
}

export function addUmd(opts: Obj<Options> = {}): Obj<Options> {
opts.umd = {
describe: 'UMD name of the library',
type: 'string'
};

return opts;
}
12 changes: 12 additions & 0 deletions src/commons/identity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Options} from 'yargs';
import {Obj} from '../interfaces/OptionsObject';
import {Colour} from '../lib/Colour';

export interface HasName {
name: string;
Expand All @@ -17,6 +18,10 @@ export interface HasGhUser {
ghUser: string;
}

export interface HasGhToken {
ghToken: string;
}

export interface HasGhRepo {
ghRepo: string;
}
Expand Down Expand Up @@ -51,6 +56,13 @@ export function addGhRepo(opts: Obj<Options>): void {
};
}

export function addGhToken(opts: Obj<Options>): void {
opts['gh-token'] = {
describe: `Your ${Colour.bold('global')} GitHub token used only by this CLI tool.`,
type: 'string'
};
}

export function addUserWebsite(opts: Obj<Options>): void {
opts['user-website'] = {
alias: 'uwebsite',
Expand Down
11 changes: 11 additions & 0 deletions src/const/CACHE_DIR.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {mkdirpSync} from 'fs-extra';
import {homedir} from 'os';
import {join} from 'path';

export const CACHE_DIR = join(homedir(), '.cache', 'alobuild');

try {
mkdirpSync(CACHE_DIR);
} catch {
//noop
}
24 changes: 24 additions & 0 deletions src/fns/execLocal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {SpawnSyncOptions, SpawnSyncOptionsWithStringEncoding, SpawnSyncReturns} from 'child_process';
import {sync as xSpawn} from 'cross-spawn';
import {merge} from 'lodash';
import {ext} from '../const/ext';
import {getBin} from './getBin';

export function execLocal(path: string,
args: string[] = [],
opts?: SpawnSyncOptions): SpawnSyncReturns<string> {
args = [path].concat(args);
if (ext === 'ts') {
args = [getBin('ts-node', 'ts-node')].concat(args);
}

const defaultOpts: SpawnSyncOptionsWithStringEncoding = {
encoding: 'utf8',
env: Object.assign({}, process.env, {
TS_NODE_TRANSPILE_ONLY: '1'
})
};
const options: SpawnSyncOptionsWithStringEncoding = merge(defaultOpts, opts || {});

return xSpawn(process.execPath, args, options);
}
File renamed without changes.
11 changes: 9 additions & 2 deletions src/interfaces/InitConf.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import {HasEmail, HasGhRepo, HasGhUser, HasName, HasUserWebsite} from '../commons/identity';
import {HasUmd} from '../commons/buildType';
import {HasEmail, HasGhRepo, HasGhToken, HasGhUser, HasName, HasUserWebsite} from '../commons/identity';
import {License} from '../inc/License';
import {PackageManager} from '../inc/PackageManager';

export interface InitConf extends HasName, HasUserWebsite, HasEmail, HasGhUser, HasGhRepo {
export interface InitConf extends HasName, HasUmd, HasUserWebsite, HasEmail, HasGhToken, HasGhUser, HasGhRepo {
license: License;

pkgMgr: PackageManager;

projectDesc: string;

projectKeywords: string;

projectName: string;

skipCodeOwners: boolean;

skipGhIssueTpl: boolean;
Expand Down
50 changes: 33 additions & 17 deletions src/lib/ConfigWriter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'fs';
import {cloneDeep, isEmpty, merge, set, unset} from 'lodash';
import {cloneDeep, get, isEmpty, merge, set, unset} from 'lodash';
import {homedir} from 'os';
import {join} from 'path';
import * as YAML from 'yamljs';
Expand All @@ -9,68 +9,84 @@ const enum Conf {
DEFAULT_SCOPE = 'global'
}

export interface Data {
global?: { [k: string]: any };

[k: string]: any;
}

const _data: unique symbol = Symbol('data');

export class ConfigWriter {

public static readonly filepath: string = join(homedir(), defaultCfgName);

private data: { global?: { [k: string]: any }; [k: string]: any };
private [_data]: Data;

public constructor() {
public constructor(private readonly file: string = ConfigWriter.filepath) {
this.refresh();
}

public get data(): Data {
return this[_data];
}

/** This will automatically save */
public clear(): this {
this.data = {};
this[_data] = {};

return this.save();
}

public get<T = any>(key: string, scope: string = Conf.DEFAULT_SCOPE): T | null {
return get(this[_data], [scope, key], null);
}

public refresh(): this {
try {
const contents = fs.readFileSync(ConfigWriter.filepath, 'utf8');
const contents = fs.readFileSync(this.file, 'utf8');
const parsed = YAML.parse(contents);
this.data = isEmpty(parsed) ? {} : parsed;
this[_data] = isEmpty(parsed) ? {} : parsed;
} catch {
this.data = {};
this[_data] = {};
}

return this;
}

public refreshAndSave(): this {
const d = cloneDeep(this.data);
const d = cloneDeep(this[_data]);
this.refresh();
merge(this.data, d);
merge(this[_data], d);

return this.save();
}

public save(): this {
if (isEmpty(this.data)) {
if (isEmpty(this[_data])) {
try {
fs.unlinkSync(ConfigWriter.filepath);
fs.unlinkSync(this.file);
} catch {
//noop
}
} else {
//tslint:disable-next-line:no-magic-numbers
fs.writeFileSync(ConfigWriter.filepath, YAML.stringify(this.data, Number.MAX_VALUE, 2));
fs.writeFileSync(this.file, YAML.stringify(this[_data], Number.MAX_VALUE, 2));
}

return this;
}

public set(key: string, value: any, scope: string = Conf.DEFAULT_SCOPE): this {
set(this.data, [scope, key], value);
public set<T = any>(key: string, value: T, scope: string = Conf.DEFAULT_SCOPE): this {
set(this[_data], [scope, key], value);

return this;
}

public unset(key: string, scope: string = Conf.DEFAULT_SCOPE): this {
unset(this.data, [scope, key]);
if (isEmpty(this.data[scope])) {
delete this.data[scope];
unset(this[_data], [scope, key]);
if (isEmpty(this[_data][scope])) {
delete this[_data][scope];
}

return this;
Expand Down
26 changes: 26 additions & 0 deletions src/lib/Log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {noop} from 'lodash';
import * as symbols from 'log-symbols';

export class Log {
public static err(txt: string): void {
process.stderr.write(`${symbols.error} ${txt}\n`);
}

public static info(txt: string): void {
process.stdout.write(`${symbols.info} ${txt}\n`);
}

public static success(txt: string): void {
process.stdout.write(`${symbols.success} ${txt}\n`);
}

public static warn(txt: string): void {
process.stdout.write(`${symbols.warning} ${txt}\n`);
}
}

if (process.env.CI) {
for (const k of ['err', 'info', 'success', 'warn']) {
Log[k] = noop;
}
}
Loading

0 comments on commit bd68807

Please sign in to comment.