Skip to content

Commit

Permalink
Merge pull request #25 from phrase/upgrade-deps-add-eslint-config
Browse files Browse the repository at this point in the history
feat: add eslint-phrase-config ad upgrade-deps
  • Loading branch information
Szymon-dziewonski authored Jul 21, 2020
2 parents e75035f + d23aff6 commit 0f7a343
Show file tree
Hide file tree
Showing 11 changed files with 579 additions and 714 deletions.
59 changes: 1 addition & 58 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,5 @@
"project": "./tsconfig.json",
"createDefaultProgram": true
},
"rules": {
"@typescript-eslint/ban-types": [
"error",
{
"types": {
"Object": "Use {} instead",
"String": {
"message": "Use string instead",
"fixWith": "string"
}
}
}
],
"@typescript-eslint/class-name-casing": [
"error"
],
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
"accessibility": "no-public"
}
],
"func-call-spacing": "off",
"@typescript-eslint/func-call-spacing": [
"error"
],
"@typescript-eslint/indent": [
"error",
4
],
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-unused-vars": [
"error",
{
"vars": "all",
"args": "none"
}
],
"@typescript-eslint/no-use-before-define": [
"error",
{
"functions": false,
"classes": false
}
],
"@typescript-eslint/no-var-requires": "warn",
"semi": "off",
"@typescript-eslint/semi": [
"error"
],
"@typescript-eslint/type-annotation-spacing": [
"error",
{
"before": false,
"after": true
}
]
}
"extends": "eslint-config-phrase"
}
20 changes: 10 additions & 10 deletions dist/angular-phrase.js

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

2 changes: 1 addition & 1 deletion dist/angular-phrase.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/angular-phrase.min.js

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

2 changes: 1 addition & 1 deletion dist/angular-phrase.min.js.map

Large diffs are not rendered by default.

32 changes: 17 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,29 @@
"author": "Manuel Boy <[email protected]> (https://phraseapp.com)",
"license": "MIT",
"devDependencies": {
"@types/angular": "^1.6.56",
"@types/angular": "^1.7.2",
"@types/angular-mocks": "^1.7.0",
"@types/jasmine": "^3.4.3",
"@typescript-eslint/eslint-plugin": "^2.3.3",
"@typescript-eslint/parser": "^2.3.3",
"@types/angular-translate": "^2.16.2",
"@types/jasmine": "^3.5.11",
"@typescript-eslint/eslint-plugin": "^3.6.1",
"@typescript-eslint/parser": "^3.6.1",
"angular": "^1.7.8",
"angular-mocks": "^1.7.8",
"angular-translate": "^2.18.1",
"eslint": "^6.5.1",
"karma": "^5.0.5",
"karma-chrome-launcher": "^2.0.0",
"angular-mocks": "^1.8.0",
"angular-translate": "^2.18.3",
"eslint": "^7.5.0",
"eslint-config-phrase": "git+https://github.com/phrase/eslint-config-phrase.git#v2",
"karma": "^5.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^1.2.0",
"karma-jasmine": "^3.1.1",
"karma-jasmine": "^3.3.1",
"karma-spec-reporter": "^0.0.32",
"karma-webpack": "^4.0.2",
"source-map-loader": "^0.2.4",
"terser-webpack-plugin": "^2.3.0",
"ts-loader": "^7.0.4",
"typescript": "^3.6.4",
"source-map-loader": "^1.0.1",
"terser-webpack-plugin": "^3.0.7",
"ts-loader": "^8.0.1",
"typescript": "^3.9.7",
"webpack": "^4.41.3",
"webpack-cli": "^3.3.10"
"webpack-cli": "^3.3.12"
},
"files": [
"dist",
Expand Down
27 changes: 20 additions & 7 deletions src/angular-phrase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ declare global {
const angular: ng.IAngularStatic;
}
import DataUtils from "./data-utils";

const phrase = angular.module("phrase", ['pascalprecht.translate', 'ng']);

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
interface ITranslateServiceExtend extends angular.translate.ITranslateService {
_instant: angular.translate.ITranslateService['instant']
}

phrase.value("phraseProjectId", "");
phrase.value("phraseEnabled", true);
phrase.value("phraseDecoratorPrefix", "{{__");
Expand All @@ -13,10 +17,19 @@ phrase.value("phraseAutoLowercase", true);

phrase.config(["$provide", ($provide: angular.auto.IProvideService) => {
return $provide.decorator("$translate", ["$delegate", "phraseEnabled", "phraseDecoratorPrefix", "phraseDecoratorSuffix",
($translate: any, phraseEnabled: boolean, phraseDecoratorPrefix: string, phraseDecoratorSuffix: string) => {
($translate: ITranslateServiceExtend, phraseEnabled: boolean, phraseDecoratorPrefix: string, phraseDecoratorSuffix: string) => {
if (phraseEnabled) {
$translate._instant = $translate.instant;
$translate.instant = translationId => `${phraseDecoratorPrefix}phrase_${translationId + phraseDecoratorSuffix}`;
$translate.instant = (translationId: string | string[]): any => {
if (typeof translationId === "object") {
return translationId.reduce<Record<string, string>>((prev, curr: string) => {
prev[curr] = `${phraseDecoratorPrefix}phrase_${curr as string}${phraseDecoratorSuffix}`;
return prev;
}, {});
}

return `${phraseDecoratorPrefix}phrase_${translationId as string}${phraseDecoratorSuffix}`;
};
}
return $translate;
}]);
Expand All @@ -36,7 +49,7 @@ phrase.config(["$compileProvider", ($compileProvider: angular.ICompileProvider)
compile: (elem, attr) => {
let translationId: string;
if (elem.attr("translate") != undefined) {
if (elem.attr("translate") !== ""){
if (elem.attr("translate") !== "") {
translationId = elem.attr("translate");
} else {
translationId = elem.text();
Expand All @@ -46,7 +59,7 @@ phrase.config(["$compileProvider", ($compileProvider: angular.ICompileProvider)
if (translationId) {
let decoratedTranslationId = `${phraseDecoratorPrefix}phrase_${translationId + phraseDecoratorSuffix}`;
if (attr.translateValues) {
decoratedTranslationId = `${decoratedTranslationId} (${attr.translateValues})`;
decoratedTranslationId = `${decoratedTranslationId} (${(attr.translateValues as string)})`;
}
elem.html(decoratedTranslationId);
elem.removeAttr("translate");
Expand All @@ -57,13 +70,13 @@ phrase.config(["$compileProvider", ($compileProvider: angular.ICompileProvider)
}]);

phrase.directive("phraseJavascript", ["phraseEnabled", "phraseProjectId", "phraseAutoLowercase", "$window",
(phraseEnabled: boolean, phraseProjectId: string, phraseAutoLowercase: boolean, $window: any) => {
(phraseEnabled: boolean, phraseProjectId: string, phraseAutoLowercase: boolean, $window: Window) => {
return {
restrict: "EA",
replace: true,
link: (): void => {
if (phraseEnabled) {
let url = `https://phraseapp.com/assets/in-context-editor/2.0/app.js?${new Date().getTime()}`;
const url = `https://phraseapp.com/assets/in-context-editor/2.0/app.js?${new Date().getTime()}`;
$window.PHRASEAPP_CONFIG = {
projectId: phraseProjectId,
autoLowercase: phraseAutoLowercase,
Expand Down
13 changes: 2 additions & 11 deletions src/data-utils.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
export default class DataUtils {
static getScript(source: string, callback?: Function): void {
let script = document.createElement('script') as any;
static getScript(source: string): void {
const script = document.createElement('script');
const prior = document.getElementsByTagName('script')[0];
script.async = true;

script.onload = script.onreadystatechange = function( _, isAbort ) {
if(isAbort || !(script as XMLHttpRequest).readyState || /loaded|complete/.test(script.readyState) ) {
script.onload = script.onreadystatechange = null;
script = undefined;

if(!isAbort && callback) setTimeout(callback, 0);
}
};

script.src = source;
prior.parentNode.insertBefore(script, prior);
}
Expand Down
4 changes: 1 addition & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,5 @@
"exclude": [
"node_modules"
],
"include": [
"src"
]
"include": ["src/**/*", "typings.d.ts"]
}
3 changes: 3 additions & 0 deletions typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Window {
PHRASEAPP_CONFIG: Record<string, unknown>
}
Loading

0 comments on commit 0f7a343

Please sign in to comment.