Skip to content

Instantly share code, notes, and snippets.

View shaharkazaz's full-sized avatar

Shahar Kazaz shaharkazaz

View GitHub Profile
@shaharkazaz
shaharkazaz / has-feature-flag.ts
Created July 17, 2020 06:54
The hasFeatureFlag Transloco transpiler function definition
import { FFService } from './feature-flag.service';
import { TranslocoTranspilerFunction } from '@ngneat/transloco';
class FeatureFlagResolver implements TranslocoTranspilerFunction {
constructor(private featureFlagService: FFService) {}
transpile(...args: string[]): any {
const [flagName, trueValue, falseValue] = args;
return this.featureFlagService.hasFF(flagName) ? trueValue : falseValue;
@shaharkazaz
shaharkazaz / transloco-root.module.ts
Created July 17, 2020 06:53
adding the function transpiler
import { FunctionalTranspiler, TRANSLOCO_TRANSPILER } from '@ngneat/transloco';
@NgModule({
...
providers: [{
provide: TRANSLOCO_TRANSPILER,
useClass: FunctionalTranspiler
}]
})
export class TranslocoRootModule {}
const chalk = require('chalk');
const {exec} = require('./exec');
/* The flag commit hash 🚩 */
const stgUniqCommit = "s76o527m89e9h72619a827s9h038c029o8de";
const currentBranch = exec('git rev-parse --abbrev-ref HEAD');
/* Get all the branch names that have a commit with this hash */
const branchesWithStaging = exec(`git branch --contains ${stgUniqCommit}`);
if (branchesWithStaging.includes(currentBranch)) {
console.log(chalk.bgRed.black.bold(`Your branch contains commits from 'staging' branch.`));
const {exec} = require('./exec');
/* Update local branch from origin master */
exec('git pull origin master');
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const {exec} = require('./exec');
/* Branch Naming Convention */
...
/* Check Forbidden Tokens */
const FILES_REGEX = {ts: /\.ts$/, spec: /\.spec\.ts$/};
const chalk = require('chalk');
const {exec} = require('./exec');
const branchName = exec('git rev-parse --abbrev-ref HEAD', {trim: true});
// check if this branch already exists in the remote
const isInRemote = exec(`git show-branch remotes/origin/${branchName}`, {toString: false}).code === 0;
if (!isInRemote) {
const validBranchPrefix = 'feature|fix|hotfix|chore|tests|automation';
const validBranchesRegex = new RegExp(`^(${validBranchPrefix})\/[\\w.-]+$`);
const shell = require('shelljs');
function exec(cmd, options) {
const defaultOptions = {silent: true};
let output = shell.exec(cmd, {...defaultOptions, ...(options || {})});
if (options && options.toString !== false) {
output = output.toString();
output = options.trim ? output.trim() : output;
}
<ng-container *transloco="let t">
{{ t('profile.title') }}
{{ t('title') }}
</ng-container>
<ng-container *transloco="let t">
{{ t('userProfile.title') }}
{{ t('title') }}
</ng-container>
const routes: Routes = [
{
path: '',
component: UserProfileComponent
}
];
@NgModule({
declarations: [UserProfileComponent],
providers: [{provide: TRANSLOCO_SCOPE, useValue: 'user-profile'}],