Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

file-lane

Package Overview
Dependencies
Maintainers
0
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-lane

File conversion tool, can be one-to-one, one to N, N to one

  • 2.0.2-beta.15
  • npm
  • Socket score

Version published
Weekly downloads
79
decreased by-78.88%
Maintainers
0
Weekly downloads
 
Created
Source

项目介绍

file-lane模块用于文件转换,可实现文件1对1的转换,也可实现1对多、多对1的文件转换。

安装使用

  • 安装

    npm i file-lane

  • 快速上手

    const { FileLane } = require('file-lane')
    const { UxLoader } = require('aiot-toolkit/aiotpack')
    const Path = require('path')
    
    const projectPath = Path.join(__dirname, '../testProject')
    
    // 定义项目转换的配置参数,output和module为必要配置内容
    const projectConfig = {
      // output指定转换后项目的存储位置
      get output() {
        const name = Path.basename(projectPath)
        const result = `../.temp_${name}`
        return result
      },
      // 转换过程中使用的转换模块配置
      module: {
        rules: [
          {
            test: [/.+\.ux$/],
            exclude: [/app\.ux/],
            loader: [UxLoader]
          }
        ]
      }
    }
    
    // 开始执行文件转换
    new FileLane(projectConfig).start()
    // 开启watch模式
    // new FileLane(projectConfig).start({ watch: true })
    

参数配置

  • 必填参数
    • output
    • module
  • 可选参数

output

描述: 输出目录

参数类型: string

示例:

'temp_project'

module

描述: 文件转换规则集

参数类型: { rules: IRule[] } // IRule:转换规则

interface IRule {
  // 配置文件
  test: MatchType

  // 文件的 Loader,从前向后依次执行,前一个 loader 结果做为后一个 loader 的入参
  loader: ILoaderClass[]
  exclude?: MatchType
  include?: MatchType
}

示例:

{
  rules: [
    {
      test: [/.+\.ux$/],
      exclude: [/app\.ux/],
      loader: [UxLoader]
    }
  ]
}

fileCollector

描述: 文件收集器,输入文件路径,返回待合并的文件路径,常用于多转1,默认值为直接使用源文件

参数类型:

(file: string) => string[]

示例:

// src/a.hml -->[src/a.hml, src/a.js, src/a.css]
(file: string) => {
  const fileList = [file]
  const { dir, name, ext } = path.parse(file)

  if (ext === '.hml') {
    ['.js', '.css'].map((item) => {
      const collectFile = path.join(dir, `${name}${item}`)
      // 若路径真实存在,则push到文件列表中
      if (fs.existsSync(collectFile)) {
        fileList.push(collectFile)
      }
    })
    return fileList
  }
}

include

描述: 指定文件范围

参数类型:

OneMatchType | OneMatchType[]

示例:

// 匹配包含有src字符串的文件
include = ['src']

exclude

描述: 需排除的文件范围

参数类型:

OneMatchType | OneMatchType[]

示例:

// 排除路径中包含有node_modules字符串的文件
exclude = [/node_modules/]

plugins

描述: 插件,在每个文件转换完成前后,所有文件转换完成前后,在打包完成前后会触发

参数类型:

IPlugin[]

示例:

preWorks

描述: 前置工作,所有文件转换前的工作

参数类型:

PreWork[]

示例:

preWorks = [validateManifest]

const validateManifest: PreWork<IJavascriptCompileOption>  = async (context) => {
  // 校验manifest.json文件的内容
}

followWorks

描述: 后续工作,所有文件转换后的工作

参数类型:

FollowWoker<O>[]

示例:

followWorks = [
  {
    worker: toRpk,
    workerDescribe: 'follow work'
  }
]

const toRpk: FollowWork<IJavascriptCompileOption> = async (context, config, compilerOption) => {
  // 生成rpk逻辑
}

watchIgnores

描述: 配置watch时忽略的文件或者文件夹

参数类型:

MatchType

示例:

watchIgnores = [/node_modules/, '/build/', '/dist/']

Keywords

FAQs

Package last updated on 29 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc