This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type ListZipper<T> = [T[], T[]]; | |
| function toListZipper<T>(list: T[]): ListZipper<T>; | |
| function toListZipper<T>(list: T[]) { | |
| return [[], list]; | |
| } | |
| function fromListZipper<T>(lz: ListZipper<T>): T[] | |
| function fromListZipper<T>([L, R]: ListZipper<T>) { | |
| return [...L.reverse(), ...R]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns listzip.core) | |
| (defn toListZipper | |
| "I don't do a whole lot." | |
| [lToLz] | |
| (list (list) lToLz)) | |
| (defn fromListZipper | |
| [lz] | |
| (let [left (first lz) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { GluegunToolbox, print } from 'gluegun' | |
| module.exports = { | |
| name: 'init', | |
| alias: ['init'], | |
| run: async (toolbox: GluegunToolbox) => { | |
| print.success('base command created with success'); | |
| }, | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type ExtractPromiseGeneric<P> = P extends Promise<infer T> ? T : never; | |
| const currentDirectory = fs.realpathSync(process.cwd()); | |
| function throwError(func: Function) { | |
| return func; | |
| } | |
| function CatchError(err: Function | Error) { | |
| if (typeof err === 'function') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as fse from 'fs-extra'; | |
| function checkIfNameExistsInDirectory(appDirectory) { | |
| return async () => { | |
| if (!(await fse.pathExists(appDirectory))) { | |
| return | |
| } | |
| throw throwError(() => { | |
| print.error('Invalid project name') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getNpmTemplatePackageName(templateName: string) { | |
| return async () => { | |
| if (templateName) { | |
| return `cra-clone-${templateName}-template`; | |
| } | |
| return 'cra-clone-template'; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { execSync } from 'child_process' | |
| async function getNpmPackageUrl( | |
| npmTemplatePackageName: ExtractPromiseGeneric< | |
| ReturnType<ReturnType<typeof getNpmTemplatePackageName>> | |
| > | |
| ) { | |
| return { | |
| npmTemplatePackageName, | |
| urlNpmPackage: execSync(`npm v ${npmTemplatePackageName} dist.tarball`) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as hyperquest from 'hyperquest' | |
| import { unpack } from 'tar-pack' | |
| function extractStream(stream, dest) { | |
| return new Promise((resolve, reject) => { | |
| stream.pipe( | |
| unpack(dest, err => { | |
| if (err) { | |
| reject(err) | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function copyTemplateToAppDirectory(tmpDir: string, appDirectory: string) { | |
| return async ( | |
| chainData: ExtractPromiseGeneric<ReturnType<typeof getNpmPackageUrl>> | |
| ) => { | |
| print.info(`copying template to ${appDirectory}`); | |
| await fse.copy(`${tmpDir}/template`, appDirectory, { | |
| overwrite: false, | |
| errorOnExist: true | |
| }); |