Skip to content

Instantly share code, notes, and snippets.

View thekip's full-sized avatar

Timofei Iatsenko thekip

View GitHub Profile
@thekip
thekip / migrate_lexical.ts
Created October 13, 2023 08:43
Migration script from payload-lexical-plugin to Payload 2.0
import { MigrateUpArgs, MigrateDownArgs } from '@payloadcms/db-mongodb';
import { Field, RichTextField, BlockField } from 'payload/dist/fields/config/types';
import { CollectionModel } from '@payloadcms/db-mongodb/dist/types';
/**
* Migration steps:
* 1. Go and change all your fields to `richText` instead of plugin's wrapper
* 2. Run a migration
*
* This migration supports:
@thekip
thekip / migrate.ts
Created June 23, 2023 09:27
Convert explicit ids from v3 catalogs to v4
# Run it in the place where is your `lingui.config` is located
# ts-node ./migrate.ts
import {
CatalogType,
ExtractedMessageType,
getConfig,
LinguiConfigNormalized,
MessageType,
} from "@lingui/conf"
const webpack = require('webpack');
const os = require('os');
const rimraf = require('rimraf');
const helpers = require('../helpers');
const gutil = require('gulp-util');
const argv = require('process').argv;
const fs = require('fs');
const path = require('path');
const {statsToString, statsErrorsToString, statsWarningsToString} = require('../stats');
const {getEmittedFiles} = require('@angular-devkit/build-webpack/src/utils');
@thekip
thekip / es5-classes-to-es6.js
Last active August 7, 2017 15:39
Codemod: rewrite ES5 classes to ES6.
'use strict';
module.exports = function (file, api, options) {
const j = api.jscodeshift;
const source = j(file.source);
const body = source.find(j.Program).get('body');
delete body.value[0].comments;
let jobDone = false;
const classConstructor = source.find(j.FunctionDeclaration,
@thekip
thekip / upgrade-old-services.js
Last active August 6, 2017 16:33
Codemod: Upgrade old Angular services to ES6 classes
'use strict';
module.exports = function (file, api) {
const j = api.jscodeshift;
const source = j(file.source);
const body = source.find(j.Program).get('body');
delete body.value[0].comments;
let jobDone = false;
const factoryCall = source.find(j.CallExpression, (node) => (
@thekip
thekip / react-template.js
Last active July 30, 2017 08:05
Webstorm React Component Template
#set($cmpName = "")
#foreach($str in $NAME.split("-"))
#set($str = $str.substring(0,1).toUpperCase()+$str.substring(1))
#set($cmpName = $cmpName + $str)
#end
import React, { Component } from 'react';
import PropTypes from 'prop-types';
export class ${cmpName} extends Component {
static propTypes = {
@thekip
thekip / import-module.js
Last active July 6, 2017 10:38
jscodeshift codemod
var path = require('path');
var fs = require('fs');
module.exports = function (file, api, options) {
const j = api.jscodeshift;
const ast = j(file.source);
const body = ast.find(j.Program).get('body');
// Find each angular.<method>() usage
var moduleUsages = ast.find(j.CallExpression, isModuleExpression)
@thekip
thekip / angular-import-codemod.js
Created July 3, 2017 08:52
jscodeshift codemod to add angular import statement
module.exports = function (file, api) {
const j = api.jscodeshift;
const ast = j(file.source);
const body = ast.find(j.Program).get('body');
// Find each angular.<method>() usage
var angularUsages = ast.find(j.MemberExpression, isAngularExpression);
if (angularUsages.length === 0) {
return null;
@thekip
thekip / remove-iife.js
Last active November 1, 2020 00:13
jscodeshift codemod to remove IIFE wrap
module.exports = function(fileInfo, { jscodeshift: j }) {
const ast = j(fileInfo.source);
const body = ast.find(j.Program).get("body");
const getFirstNode = () => ast.find(j.Program).get('body', 0).node;
// Save the comments attached to the first node
const firstNode = getFirstNode();
const { comments } = firstNode;
ast
#set($ctrlName = "")
#foreach($str in $NAME.split("-"))
#set($str = $str.substring(0,1).toUpperCase()+$str.substring(1))
#set($ctrlName = $ctrlName + $str)
#end
#set($ctrlName = $ctrlName.replaceFirst("\.component", ""))
#set($directiveName = $ctrlName.substring(0,1).toLowerCase()+$ctrlName.substring(1))
export default function(ngModule: ng.IModule) {
ngModule.component('${directiveName}', {
controllerAs: 'ctrl',