Skip to content

fsy0718/autocommand-cli

 
 

Repository files navigation

autocommand-cli

autocommand的命令行版本,使用nodejs实现。

安装

npm install thinkjs/autocommand-cli -g

帮助

acmd --help

参考

生成配置文件

acmd config -i, --init [config]

测试配置文件是否正确

acmd config -t, --test [config]

执行命令

acmd run

扫描配置文件,根据配置文件的内容对匹配的文件执行指定命令

监听

acmd watch

配置

示例:

{
  // 侦听的文件
  "file": ["**/*.jade", "*.sass", "*.ls"],
  // 过滤
  "ignore": ["^_"],
  // 变量
  "variable": { },
  // 定义
  "define": {
    ".jade": {
      "file": "#{fileName}.html",
      "command": "jade -Po ./ #{fileName}.jade"
    },
    ".sass": {
      "command": "sass --sourcemap=none --style compact #{fileName}.sass ./#{fileName}.css"
    },
    ".ls": {
      "file": "#{fileName}.js",
      "command": "lsc -cbp ./#{fileName}.ls>./#{fileName}.js"
    },
    // 嵌套目录
    "jade/": {
      // ~代表baseDir
      // .代表当前
      "path": "~",
      ".jade": {
        "file": "#{fileName}.html",
        "command": "jade -Po ./ jade/#{fileName}.jade"
      }
    }
  },
  // browserSync配置
  "browserSync": {
    // 初始化配置
    "init": {
      "server": {
        "baseDir": "./"
      },
      "open": false
    },
    // 启动livereload
    "reload": true
  }
}

file

侦听的文件类型

  • 必选

示例:

{
  "file": ["*.sass", "coffee/*.coffee", "jade/**/*.jade"]
}

define

配置命令选项

  • 必选

针对指定文件配置:

{
  "define": {
    ".jade": {
      "file": "#{fileName}.html",
      "command": "jade -Po ./ #{fileName}.jade"
    }
  }
}
  • file键表示文件编译后的真实文件名,用来显示和发送给livereload函数
  • command代表要执行的命令,可以用数组传入多个命令
  • file和command可是支持变量

针对指定目录配置:

{
  "define": {
    // 嵌套目录
    "jade/": {
      // ~代表baseDir
      // .代表当前
      "path": "~",
      ".jade": {
        "file": "#{fileName}.html",
        "command": "jade -Po ./ jade/#{fileName}.jade"
      }
    }
  }
}
  • path 代表执行编译命令的路径,因某些项目需在固定路径编译

ignore

根据指定规则过滤文件,默认为正则表达式

  • 可选

示例:

{
    "ignore": "^_"
}

以为上过滤以_打头的文件名,可以用数组传入多个过滤规则

variable

自义变量,在command,file等选项中使用#{variableName}的形式使用

  • 可选 默认支持以下变量:
  • file 表示当前文件
  • fileName 表示当前文件名(不包含扩展名)
  • relativePath 当前文件相对于项目根目录的路径

browserSync

配置使用browserSync

  • 可选

About

前端自动编译工具

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 59.6%
  • TypeScript 33.6%
  • LiveScript 6.1%
  • HTML 0.7%