Skip to content

Commit

Permalink
🏷️ (mario) built-use typo
Browse files Browse the repository at this point in the history
  • Loading branch information
JiangWeixian committed May 28, 2023
1 parent 9fcdb34 commit 180ab76
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 48 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"cSpell.words": [
"Listr",
"postgenerate"
]
],
"typescript.tsdk": "node_modules/typescript/lib"
}
8 changes: 4 additions & 4 deletions packages/mario/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import typescript from 'rollup-plugin-typescript2'
import { externals } from 'rollup-plugin-node-externals'
import bundleSize from 'rollup-plugin-size'
import { defineConfig } from 'rollup'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import { defineConfig } from 'rollup'
import multiple from 'rollup-plugin-multi-input'
import { externals } from 'rollup-plugin-node-externals'
import bundleSize from 'rollup-plugin-size'
import typescript from 'rollup-plugin-typescript2'

export default defineConfig([
// CommonJS (for Node) and ES module (for bundlers) build.
Expand Down
7 changes: 5 additions & 2 deletions packages/mario/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { createWorkflow, readWorkflowSchema, CreateWorkflowOptions } from './workflow'
import { pick } from 'lodash-es'
import { Workflow } from './interface'

import { createWorkflow, readWorkflowSchema } from './workflow'

import type { Workflow } from './interface'
import type { CreateWorkflowOptions } from './workflow'

export { hooks } from './utils/hooks'
// export { LogLevel } from 'consola'
Expand Down
6 changes: 3 additions & 3 deletions packages/mario/src/interface/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type Debug from 'debug'

export type WebhookEvent = string

export type Step = {
export interface Step {
/**
* A name for your step to display on GitHub.
*/
Expand Down Expand Up @@ -52,7 +52,7 @@ export type Step = {
/**
* Each job must have an id to associate with the job. The key job_id is a string and its value is a map of the job's configuration data. You must replace <job_id> with a string that is unique to the jobs object. The <job_id> must start with a letter or _ and contain only alphanumeric characters, -, or _.
*/
export type Job = {
export interface Job {
/**
* The name of the job displayed on GitHub.
*/
Expand Down Expand Up @@ -81,7 +81,7 @@ export interface Workflow {
jobs?: Record<string, Job>
}

export type Context = {
export interface Context {
cwd: string
debug: Debug.Debugger
variables?: Record<string, any>
Expand Down
9 changes: 5 additions & 4 deletions packages/mario/src/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Workflow } from '../interface'
import Observable from 'zen-observable'

import { LIFE_CYCLES } from '../constants'
import { hooks } from './hooks'

import Observable from 'zen-observable'
import type Listr from 'listr'
import { LIFE_CYCLES } from '../constants'
import type { Workflow } from '../interface'

/**
* @description convert schema to listr
Expand All @@ -14,7 +15,7 @@ export const toListr = (schema: Workflow) => {
return {
title: taskName,
task: () => {
let ob: ZenObservable.SubscriptionObserver<any>
let ob: Observable.SubscriptionObserver<any>
const OB = new Observable<any>((observer) => {
ob = observer
})
Expand Down
19 changes: 13 additions & 6 deletions packages/mario/src/workflow/factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { templateSettings, template, mapValues, isObject, isString } from 'lodash-es'
import { Action, Context } from '../interface'
import {
isObject,
isString,
mapValues,
template,
templateSettings,
} from 'lodash-es'

import type { Action, Context } from '../interface'

templateSettings.interpolate = /\${{([\s\S]+?)}}/g

Expand All @@ -19,13 +26,13 @@ export const mapValuesDeep = (
callback: (value: string) => any,
): Record<string, any> =>
Array.isArray(v)
? v.map((v) => mapValuesDeep(v, callback))
? v.map(v => mapValuesDeep(v, callback))
: isObject(v)
? mapValues(v, (v) => mapValuesDeep(v, callback))
: callback(v)
? mapValues(v, v => mapValuesDeep(v, callback))
: callback(v)

export const wrapOptions = (options: Record<string, any>, variables: Context['variables']) => {
return mapValuesDeep(options, (v) => tpl(v, variables))
return mapValuesDeep(options, v => tpl(v, variables))
}

export const factory = (action: Action<any>): Action<any> => {
Expand Down
26 changes: 17 additions & 9 deletions packages/mario/src/workflow/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
import consola from 'consola'
import gulp from 'gulp'
import consola, { Consola } from 'consola'
import filter from 'gulp-filter'
import gulpDebug from 'gulp-debug'
import filter from 'gulp-filter'
import readYaml from 'read-yaml-file'

import { hooks } from '../utils/hooks'
import { Workflow, Job, Context, Step } from '../interface'
import { LIFE_CYCLES } from '../constants'
import { builtInUses } from './uses'
import { run, RunOptions } from './run'
import { hooks } from '../utils/hooks'
import { debug, prefix } from '../utils/logger'
import { run } from './run'
import { builtInUses } from './uses'

import type { Consola } from 'consola'
import type {
Context,
Job,
Step,
Workflow,
} from '../interface'
import type { RunOptions } from './run'

export const readWorkflowSchema = async (filepath: string) => {
const workflow = await readYaml<Workflow>(filepath)
return workflow
}

type CreateJobOptions = {
interface CreateJobOptions {
runAction: (id: string, args: any, options: Step, ctx: Context) => any
runShell: (args: RunOptions, options: Step, ctx: Context) => any
// job name fallback
Expand Down Expand Up @@ -66,7 +74,7 @@ export const createJob = async ({ job, key, ...options }: CreateJobOptions) => {
}
const cbs = Array.isArray(cb) ? cb : [cb]
cbs.forEach((cb) => {
stream = stream.pipe(cb).on('error', function (this: any, error: Error) {
stream = stream.pipe(cb).on('error', (error: Error) => {
if (!extra['continue-on-error']) {
hooks.callHook(taskName, { job: taskName, error })
stream.emit('error')
Expand Down Expand Up @@ -126,7 +134,7 @@ const runShell: CreateJobOptions['runShell'] = (args, options, ctx) => {
return run({ ...args, ignoreErrors: options['continue-on-error'] }, ctx)
}

export type CreateWorkflowOptions = {
export interface CreateWorkflowOptions {
schema: Workflow
cwd?: CreateJobOptions['cwd']
logLevel?: Consola['level']
Expand Down
5 changes: 3 additions & 2 deletions packages/mario/src/workflow/run.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Shell from 'gulp-shell'
import { Action } from '../interface'

export type RunOptions = {
import type { Action } from '../interface'

export interface RunOptions {
commands?: string[] | string
quiet?: boolean
ignoreErrors?: boolean
Expand Down
5 changes: 3 additions & 2 deletions packages/mario/src/workflow/uses/clean.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import del from 'del'
import { Action } from '../../interface'

type CleanOptions = {
import type { Action } from '../../interface'

export interface CleanOptions {
paths?: string[]
}

Expand Down
9 changes: 5 additions & 4 deletions packages/mario/src/workflow/uses/copy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import CopyTo from 'gulp-copy'
import path from 'node:path'

import gulp from 'gulp'
import CopyTo from 'gulp-copy'
import rename from 'gulp-rename'
import path from 'path'

import { Action } from '../../interface'
import type { Action } from '../../interface'

type CopyOptions = {
export interface CopyOptions {
output: string
'keep-depth'?: boolean
}
Expand Down
14 changes: 9 additions & 5 deletions packages/mario/src/workflow/uses/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { replace } from './replace'
import { factory } from '../factory'
import { clean } from './clean'
import { copy } from './copy'
import { jsonEditor } from './json-editor'
import { clean } from './clean'
import { factory } from '../factory'
import { replace } from './replace'

import type { Action } from '../../interface'
import type { CleanOptions } from './clean'
import type { CopyOptions } from './copy'

export const builtInUses = {
replace: factory(replace),
copy,
clean,
copy: copy as Action<CopyOptions>,
clean: clean as Action<CleanOptions>,
'json-editor': factory(jsonEditor),
}
6 changes: 3 additions & 3 deletions packages/mario/src/workflow/uses/json-editor.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import JsonEditor from 'gulp-json-editor'
import { set } from 'lodash-es'

import { Action } from '../../interface'
import type { Action } from '../../interface'

type JsonEditorOptions = {
interface JsonEditorOptions {
content: Record<string, any>
pairs: {
path: string
Expand All @@ -12,7 +12,7 @@ type JsonEditorOptions = {
}

export const jsonEditor: Action<JsonEditorOptions> = (options) => {
return JsonEditor(function (json: Record<string, any>) {
return JsonEditor((json: Record<string, any>) => {
const next = Object.assign(json, options.content)
if (options.pairs) {
options.pairs.forEach((pair) => {
Expand Down
7 changes: 4 additions & 3 deletions packages/mario/src/workflow/uses/replace.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import Replace from 'gulp-replace'
import { Action } from '../../interface'

type Pattern = {
import type { Action } from '../../interface'

interface Pattern {
match: string
replacement: string
}

type ReplaceOptions = {
interface ReplaceOptions {
match: string
replacement: string
pairs?: Pattern[]
Expand Down

0 comments on commit 180ab76

Please sign in to comment.