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

Commit

Permalink
Merge ea45b7a into bd68807
Browse files Browse the repository at this point in the history
  • Loading branch information
Alorel committed Sep 28, 2018
2 parents bd68807 + ea45b7a commit de19d6a
Show file tree
Hide file tree
Showing 28 changed files with 1,791 additions and 72 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,6 +2,7 @@
/package-lock.json
/tmp.ts
/tmp.js
/tmp.sh
.idea/
node_modules/
dist/
Expand Down
2 changes: 1 addition & 1 deletion mocha.opts
Expand Up @@ -3,7 +3,7 @@
--full-trace
-r ts-node/register
-r source-map-support/register
-t 10000
-t 20000
--trace-deprecation
--trace-warnings
--throw-deprecation
Expand Down
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -38,6 +38,7 @@
"delete-empty": "^2.0.0",
"fs-extra": "^7.0.0",
"glob": "^7.0.0",
"js-base64": "^2.4.0",
"json-to-graphql-query": "^1.7.0",
"json5": "^2.0.0",
"lodash": "^4.17.0",
Expand All @@ -46,6 +47,7 @@
"reflect-metadata": "^0.1.12",
"request": "^2.88.0",
"request-promise": "^4.2.0",
"tmp": "~0.0.33",
"tslib": "^1.9.0",
"tslint": "5.11.0",
"typescript": "~3.0.0",
Expand All @@ -67,6 +69,7 @@
"@types/delete-empty": "~2.0.0",
"@types/fs-extra": "~5.0.4",
"@types/glob": "~7.1.0",
"@types/js-base64": "~2.3.1",
"@types/json5": "~0.0.30",
"@types/lodash": "~4.14.116",
"@types/log-symbols": "~2.0.0",
Expand All @@ -88,7 +91,6 @@
"rimraf": "~2.6.2",
"semantic-release": "~15.9.9",
"source-map-support": "~0.5.9",
"tmp": "~0.0.33",
"ts-node": "~7.0.1",
"uuid": "~3.3.2"
}
Expand Down
3 changes: 3 additions & 0 deletions src/alo.ts
Expand Up @@ -14,6 +14,9 @@ applyGlobalGroup(argv);
export function alo(args: string | string[]): Promise<string> {
return new Promise<string>((resolve, reject) => {
argv.parse(args, {}, (err, _argv, output) => {
if (args[0] === 'init') {
console.log(args);
}
if (err) {
process.stderr.write(output);
reject(err);
Expand Down
89 changes: 89 additions & 0 deletions src/commons/travisRelease.ts
@@ -0,0 +1,89 @@
import {values} from 'lodash';
import {Options} from 'yargs';
import {Obj} from '../interfaces/OptionsObject';

export enum TravisEndpoint {
ORG = 'org',
PRO = 'pro'
}

export interface HasTravisRelease {
ghEmail: string;

gpgKeyId: string;

gpgKeyPwd: string;

gpgPrivkey: string;

gpgPubkey: string;

releaseGhToken: string;

releaseNpmToken: string;

skipTravisRelease: boolean;

travisEndpoint: TravisEndpoint;

travisTokenOrg: string;

travisTokenPro: string;
}

export function addTravisRelease(opts: Obj<Options> = {}): Obj<Options> {
const gpg = ' for the GPG key used for signing release commits.';
const assigned: Obj<Options> = {
'gh-email': {
describe: 'Your GitHub email',
type: 'string'
},
'gpg-key-id': {
describe: `Key ID${gpg}`,
type: 'string'
},
'gpg-key-pwd': {
describe: `Password${gpg}`,
type: 'string'
},
'gpg-privkey': {
describe: `Private key contents${gpg}`,
type: 'string'
},
'gpg-pubkey': {
describe: `Public key contents${gpg}`,
type: 'string'
},
'release-gh-token': {
describe: 'GitHub token for making releases. This should differ from the gh-token parameter and be local to '
+ 'this repo.',
type: 'string'
},
'release-npm-token': {
describe: 'NPM token for making releases. This should be unique to this repo.',
type: 'string'
},
'skip-travis-release': {
default: false,
describe: 'Skip setting up a Travis release',
type: 'boolean'
},
'travis-endpoint': {
choices: values(TravisEndpoint),
default: TravisEndpoint.PRO,
describe: 'Travis endpoint to use',
type: 'string'
},
'travis-token-org': {
describe: `Travis token if using the ${TravisEndpoint.ORG} endpoint`,
type: 'string'
},
'travis-token-pro': {
describe: `Travis token if using the ${TravisEndpoint.PRO} endpoint`,
type: 'string'
}
};
Object.assign(opts, assigned);

return opts;
}
3 changes: 3 additions & 0 deletions src/const/Chmod.ts
@@ -0,0 +1,3 @@
export const enum Chmod {
C_755 = 0o755
}
13 changes: 13 additions & 0 deletions src/const/PKG_JSON.ts
@@ -0,0 +1,13 @@
import {cloneDeep} from 'lodash';
import {PackageJson} from '../interfaces/PackageJson';

// dev (ts-node) and prod (js) will have a different path

/** @internal */
export const PKG_JSON: PackageJson = cloneDeep((() => {
try {
return require('../package.json');
} catch {
return require('../../package.json');
}
})());
5 changes: 5 additions & 0 deletions src/const/TRAVIS_NODE_VERSIONS.ts
@@ -0,0 +1,5 @@
export const TRAVIS_NODE_VERSIONS: ReadonlyArray<string> = Object.freeze([
'stable',
'lts/carbon',
'lts/boron'
]);
19 changes: 19 additions & 0 deletions src/fixtures/init/.alobuild-prep-release.sh
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

PLAINTEXT_GPG=/tmp/alobuild-$(cat /proc/sys/kernel/random/uuid)

echo $BUILD_GPG_PUB_KEY | base64 -d > $PLAINTEXT_GPG
echo >> $PLAINTEXT_GPG
echo $BUILD_GPG_PRIV_KEY | base64 -d >> $PLAINTEXT_GPG
chmod 600 $PLAINTEXT_GPG
gpg --batch --yes --import $PLAINTEXT_GPG
rm -f $PLAINTEXT_GPG

PWD_GPG=/tmp/alobuild-$(cat /proc/sys/kernel/random/uuid)

echo '/usr/bin/gpg2 --passphrase ${BUILD_GPG_KEY_PWD} --batch --no-tty "$@"' > $PWD_GPG
chmod 700 $PWD_GPG

git config gpg.program $PWD_GPG
git config commit.gpgsign true
git config --global user.signingkey $BUILD_GPG_KEY_ID
15 changes: 15 additions & 0 deletions src/fixtures/init/.alobuild.yml
@@ -0,0 +1,15 @@
global:
dist-dirs: &distDirs dist

clean-pkg-json:
sort-scripts: true

copy-files:
from:
- package.json
- index.d.ts
- LICENSE
- CHANGELOG.md
- README.md
- src/fixtures
to: *distDirs
35 changes: 35 additions & 0 deletions src/fixtures/init/.releaserc.yml
@@ -0,0 +1,35 @@
branch: master
tagFormat: '${version}'

verifyConditions:
- path: &npm '@semantic-release/npm'
pkgRoot: '.'
- &gh '@semantic-release/github'

prepare:
- '@semantic-release/changelog'
- '@alorel-personal/semantic-release'
- *npm
- path: &exec '@semantic-release/exec'
cmd: yarn run doctoc
- path: *exec
cmd: alo copy-files
- path: *exec
cmd: alo clean-dist
- path: *exec
cmd: alo clean-pkg-json
- path: '@semantic-release/git'
message: 'chore(release): ${nextRelease.version}'
assets:
- CHANGELOG.md
- README.md
- package.json
- yarn.lock

publish:
- path: *npm
pkgRoot: './dist'
- *gh

generateNotes:
config: '@alorel-personal/conventional-changelog-alorel'
10 changes: 9 additions & 1 deletion src/interfaces/InitConf.ts
@@ -1,9 +1,17 @@
import {HasUmd} from '../commons/buildType';
import {HasEmail, HasGhRepo, HasGhToken, HasGhUser, HasName, HasUserWebsite} from '../commons/identity';
import {HasTravisRelease} from '../commons/travisRelease';
import {License} from '../inc/License';
import {PackageManager} from '../inc/PackageManager';

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

pkgMgr: PackageManager;
Expand Down
6 changes: 5 additions & 1 deletion src/lib/Fixture.ts
Expand Up @@ -2,6 +2,7 @@ import * as fs from 'fs-extra';
import {template} from 'lodash';
import {dirname, join} from 'path';
import {LazyGetter} from 'typescript-lazy-get-decorator';
import {Chmod} from '../const/Chmod';

const FIXTURE_DIR = join(__dirname, '..', 'fixtures');

Expand All @@ -18,8 +19,11 @@ export class Fixture {
return join(FIXTURE_DIR, this.feature);
}

public copy(from: string, to: string): void {
public copy(from: string, to: string, chmod?: Chmod): void {
fs.copySync(join(this.srcDir, from), to);
if (chmod !== undefined) {
fs.chmodSync(to, chmod);
}
}

public read(from: string): Buffer {
Expand Down
11 changes: 11 additions & 0 deletions src/lib/Git.ts
Expand Up @@ -18,4 +18,15 @@ export class Git {

return false;
}

public static cfg(key: string, val: string, global?: boolean): boolean {
const args: string[] = ['config'];
if (global) {
args.push('--global');
}
args.push(key, val);
const r = xSpawnSyncSafe('git', args);

return r.ok && r.result.status === 0;
}
}
26 changes: 20 additions & 6 deletions src/lib/ObjectWriter.ts
@@ -1,10 +1,12 @@
import * as fs from 'fs-extra';
import {get, has, noop, PropertyPath, set} from 'lodash';
import {LazyGetter} from 'typescript-lazy-get-decorator';
import * as YAML from 'yamljs';
import {AbstractReadWriter} from './AbstractReadWriter';

export const enum ObjectWriterFormat {
JSON
JSON,
YAML
}

interface Obj {
Expand All @@ -14,21 +16,33 @@ interface Obj {
export class ObjectWriter<T extends Obj = Obj> extends AbstractReadWriter {
private contents: T;

public constructor(path: string, _format: ObjectWriterFormat) {
public constructor(path: string, private readonly format: ObjectWriterFormat) {
super(path);
this.read();
}

@LazyGetter()
private get parseFn(): (v: string) => T {
//tslint:disable-next-line:no-unbound-method
return JSON.parse;
//tslint:disable:no-unbound-method
switch (this.format) {
case ObjectWriterFormat.YAML:
return YAML.parse.bind(YAML);
default:
return JSON.parse;
}
//tslint:enable:no-unbound-method
}

@LazyGetter()
private get stringifyFn(): (v: T) => string {
//tslint:disable-next-line:no-magic-numbers
return (v: T) => JSON.stringify(v, null, 2);
//tslint:disable:no-unbound-method no-magic-numbers
switch (this.format) {
case ObjectWriterFormat.YAML:
return YAML.stringify.bind(YAML);
default:
return (v: T) => JSON.stringify(v, null, 2);
}
//tslint:enable:no-unbound-method no-magic-numbers
}

public get(p: PropertyPath): any {
Expand Down

0 comments on commit de19d6a

Please sign in to comment.