Skip to content

Commit

Permalink
refactor: refresh version (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk authored Jun 29, 2020
1 parent f7bf2b2 commit 2570019
Show file tree
Hide file tree
Showing 20 changed files with 355 additions and 244 deletions.
17 changes: 17 additions & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries

# For the full list of supported browsers by the Angular framework, please see:
# https://angular.io/guide/browser-support

# You can see what browsers were selected by your queries by running:
# npx browserslist

last 1 Chrome version
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major version
last 2 iOS major versions
Firefox ESR
not IE 9-11 # For IE 9-11 support, remove 'not'.
67 changes: 67 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Ci

on: push

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master

- name: install
run: npm install

- name: run
run: |
npm run build
test:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master

- name: install
run: npm install

- name: run
run: |
npm run test
cat ./coverage/lcov.info | ./node_modules/.bin/codecov
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

lint:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master

- name: install
run: npm install

- name: run
run: |
npm run lint
site:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master

- name: install
run: npm install

- name: build
run: |
node --max_old_space_size=5120 ./node_modules/@angular/cli/bin/ng build --prod --base-href /ng-github-button/
cp ./dist/index.html ./dist/404.html
ls ./dist
- name: deploy-to-gh-pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
34 changes: 0 additions & 34 deletions .stylelintrc

This file was deleted.

32 changes: 0 additions & 32 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Unofficial GitHub buttons in Angular.

[![NPM version](https://img.shields.io/npm/v/ng-github-button.svg)](https://www.npmjs.com/package/ng-github-button)
[![Build Status](https://travis-ci.org/cipchk/ng-github-button.svg?branch=master)](https://travis-ci.org/cipchk/ng-github-button)
![Ci](https://github.com/cipchk/ng-github-button/workflows/Ci/badge.svg)

## Demo

Expand Down
20 changes: 15 additions & 5 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,32 @@ module.exports = function (config) {
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
require('@angular-devkit/build-angular/plugins/karma'),
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
jasmine: {
random: false,
},
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../coverage'),
dir: require('path').join(__dirname, 'coverage'), reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
dir: require('path').join(__dirname, 'coverage'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true,
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
customLaunchers: {
ChromeHeadlessCI: {
base: 'ChromeHeadless',
flags: ['--no-sandbox'],
},
},
singleRun: false,
});
};
9 changes: 9 additions & 0 deletions lib/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../publish",
"deleteDestPath": true,
"lib": {
"entryFile": "index.ts"
},
"whitelistedNonPeerDependencies": ["tslib", "angular"]
}
26 changes: 26 additions & 0 deletions lib/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "ng-github-button",
"version": "10.0.0",
"description": "Unofficial GitHub buttons in Angular.",
"author": "cipchk <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/cipchk/ng-github-button/issues"
},
"homepage": "https://cipchk.github.io/ng-github-button/",
"keywords": [
"angular",
"github",
"button",
"ng-github-button",
"ng2-github-button",
"angular-github-button",
"angular2-github-button",
"github-button",
"github button"
],
"repository": {
"type": "git",
"url": "git+https://github.com/cipchk/ng-github-button.git"
}
}
12 changes: 6 additions & 6 deletions lib/spec/component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, ViewChild, DebugElement } from '@angular/core';
import { ComponentFixture, TestBed, tick, fakeAsync } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';

import { GithubButtonModule } from '../src/module';
Expand All @@ -11,24 +11,24 @@ describe('github-button', () => {
let dl: DebugElement;
const win = window as any;
const oldXMLHttpRequest = win.XMLHttpRequest;
function genXhr(status: number, text: any) {
function genXhr(status: number, text: any): void {
spyOn(win, 'XMLHttpRequest').and.callFake(() => {
return {
responseText: JSON.stringify(text),
readyState: XMLHttpRequest.DONE,
status,
open() {},
send() {
open(): void {},
send(): void {
this.onreadystatechange();
},
abort() {},
abort(): void {},
};
});
}
function getCountEl(): HTMLElement {
return dl.query(By.css('.gh-count')).nativeElement as HTMLElement;
}
function getCount() {
function getCount(): number {
const value = getCountEl().textContent.trim();
return +value;
}
Expand Down
14 changes: 7 additions & 7 deletions lib/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,28 @@ export class GithubButtonComponent implements OnChanges, OnInit, OnDestroy {

// endregion

get repo_url() {
get repo_url(): string {
return `//github.com/${this.namespace}/${this.repo}/`;
}

get count_url() {
return `//github.com/${this.namespace}/${this.repo}/${this.typeToPath[
this.type
] || this.type}/`;
get count_url(): string {
return `//github.com/${this.namespace}/${this.repo}/${
this.typeToPath[this.type] || this.type
}/`;
}

constructor(
private srv: GithubButtonService,
private cdr: ChangeDetectorRef,
) {}

private setCount(data: any) {
private setCount(data: any): void {
this.count = data ? data[`${this.type}_count`] : 0;
this.cdr.detectChanges();
}

ngOnInit(): void {
this.notify$ = this.srv.notify.subscribe(res => this.setCount(res));
this.notify$ = this.srv.notify.subscribe((res) => this.setCount(res));
}

ngOnChanges(): void {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { BehaviorSubject, Observable } from 'rxjs';

@Injectable({ providedIn: 'root' })
export class GithubButtonService {
private cached: { [url: string]: any } = {};
private _notify = new BehaviorSubject<{ [url: string]: any }>(null);

get notify() {
get notify(): Observable<{ [url: string]: any }> {
return this._notify.asObservable();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';

declare const require: any;

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
platformBrowserDynamicTesting(),
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
Expand Down
9 changes: 3 additions & 6 deletions lib/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"extends": "../tsconfig.json",
"extends": "../tsconfig.base.json",
"compilerOptions": {
"target": "es2015",
"lib": ["es2018", "dom"],
"alwaysStrict": true,
"sourceMap": true,
"inlineSources": true,
Expand All @@ -11,9 +9,8 @@
"strictFunctionTypes": true,
"stripInternal": true
},
"files": [
"./index.ts"
],
"files": ["./src/module.ts"],
"include": ["**/*.ts"],
"angularCompilerOptions": {
"enableIvy": false
}
Expand Down
Loading

0 comments on commit 2570019

Please sign in to comment.