New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@finclip/applet-builder-ci

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@finclip/applet-builder-ci

```js const { Project } = require('@finclip/applet-builder-ci')

  • 2.0.2
  • npm
  • Socket score

Version published
Weekly downloads
95
increased by955.56%
Maintainers
1
Weekly downloads
 
Created
Source

编译小程序

const { Project } = require('@finclip/applet-builder-ci')

(async () => {
  const project = new Project({
    appid: 'xxx',
    type: 'miniProgram',
    projectPath: 'the/project/path',
    output: '',
    userInfo: {
      openAPISecret: '',
      url: ''
    }
  })
  /**
   * 
   * @param {Object} options - 编译参数
   * @param {string} options.input - 小程序路径
   * @param {string} options.output - 输出路径
   * @param {boolean} options.zip - 是否输出 zip 包
   * @param {boolean} options.minify - 压缩小程序js
   * @param {boolean} options.obfuscate - 混淆小程序js
   * @param {boolean} options.DSL - 控制文件后缀名与前缀
   * @param {Object} options.compileSettings - 只有v2为true是生效
   * @param {boolean} v2 - 是否使用新编译库, 默认为 true, 现在已不支持旧版本编译库
   * @returns Promise
   */ 
  const builder = await project.build({
    input: '/path/to/miniprogram',
    output: '/path/to/output/dir',
    zip: true,
    minify: false,
    obfuscate: false,
    DSL: {
      alias: ['foo', 'bar'],
      prefix: 'ft', // wx.修改为ft
      wxml: 'fxml', // .wxml为.fxml
      wxss: 'ftss',
      wxs: 'fts',
      finClipConf: 'FinClipConf.js'
    },
    modifyCss: { // 替换全局样式: modifyCss.md
      builtCss: []
    }
    watch: {
      exclude: [], // watch需要忽略的目录与文件 支持glob与正则
    },
    exclude: [], //打包时需要忽略的目录与文件 支持glob与正则
    trimText: false,  //单行文本内容不换行
    compileSettings: {
      es6: true, // es6转es5
      minify: true, // 上传时自动压缩脚本
      minifyWXSS: true, // 上传时自动压缩样式
      autoPrefixWXSS: true, // 上传时样式自动补全
      sourceMap: true, // 开启 sourceMap
    }
  }, v2)
  if (watch) { // 是否开启watch
    builder.pause() //是否停止watch
    builder.resume() //是否重启watch
  }
})()

构建 npm

const { packNpm } = require('@finclip/applet-builder-ci')
(async () => {
 /**
   * 
   * @param {string} project - 小程序路径
   * @param {Object} options - 编译参数
   * @param {[string]} options.ignores - 指定构建npm需要排除的规则
   * @param {string} options.reporter - 构建回调信息
   * @returns Promise
   */ 
  // 在有需要的时候构建npm
  await packNpm(project, {
    ignores: ['pack_npm_ignore_list'],
    reporter: (infos) => { console.log(infos) }
  })
})()

自定义 node_modules 位置的构建 npm

const { packNpmManually } = require('@finclip/applet-builder-ci')
(async () => {
 /**
   * 
   * @param {Object} options - 编译参数
   * @param {string} options.packageJsonPath - 希望被构建的node_modules 对应的 package.json 的路径
   * @param {string} options.miniprogramNpmDistDir - 被构建 miniprogram_npm 的目标位置目标位置
   * @param {[string]} options.ignores - 指定需要排除的规则
   * @returns Promise
   */ 
  // 在有需要的时候构建npm
  await packNpmManually({
    packageJsonPath: './lib/package.json',
    miniprogramNpmDistDir: './miniprogram-project/miniprogram/'
  })
})()

上传小程序到服务端流程

  const { Project } = require('@finclip/applet-builder-ci')
  const project = new Project({
    appid: 'xxx',
    type: 'miniProgram',
    projectPath: 'the/project/path',
    output: '',
    userInfo: {
      openAPISecret: '',
      url: ''
    }
  })
  const version = '0.1.6'
  const desc = '版本描述' // desc 不能为空,否则会造成签名失败
  const uploadData = await project.upload(version, desc) // 上传小程序
  /**
   * 提交审核
   * @param {string} appId 版本号
   * @param {string} buildId 审核通过后自动上架
  */
  const submitAuditData = await project.submitAudit({ appId: uploadData.appId, buildId: uploadData.buildId })
  /**
   * 审核并发布
   * @param {string} sequence 编译序列号
   * @param {boolean} pass 是否通过
   * @param {string} reason 驳回原因
  */
  await project.audit(submitAuditData.sequence, pass, reason)

一键发布小程序

  const { Project } = require('@finclip/applet-builder-ci')
  const project = new Project({
    appid: 'xxx',
    type: 'miniProgram',
    projectPath: 'the/project/path',
    output: '',
    userInfo: {
      openAPISecret: '',
      url: ''
    }
  })
  /**
   * 提交审核
   * @param {string} version 版本号
   * @param {string} desc 描述
  */

  await project.publish(version, desc) //一键发布

获取小程序最新的版本号

  const { Project } = require('@finclip/applet-builder-ci')
  const project = new Project({
    appid: 'xxx',
    type: 'miniProgram',
    projectPath: 'the/project/path',
    output: '',
    userInfo: {
      openAPISecret: '',
      url: ''
    }
  })
  await project.getAppVersion()

ftpkg 打包 解包

/**
 * pack a folder to ftpkg
 * @param {string} src 打包的目录
 * @param {string} targetDir 打包产出物生成目录
 * @param {object} options 
 * @param {boolean} options.compress 是否压缩成 .ftpkg.z 格式,默认为 true
 * @param {string} options.tempPath 临时文件存放路径,默认为 os.tmpdir()
 * @param {string} options.name 打包产出物的名称,默认为 "${src目录名}.ftpkg.z"
 * @returns {string} target file path
 */
  packFtPackage('./src/applet', '/tmp', {
    compress: true,
  })
  // 生成 ftpkg 压缩包 文件地址: /tmp/applet.ftpkg.z
  packFtPackage('./src/applet', '/tmp', {
    compress: false,
    name: 'renamedPackage'
  })
  // 生成 ftpkg 包 文件地址: /tmp/renamedPackage.ftpkg

/**
 * unpack a ftpkg file
 * @param {string} src ftpkg 或 ftpkg.z 的路径
 * @param {string} targetDir 解压产出物生成路径
 * @param {object} options
 * @param {string} options.tempPath 临时文件存放路径,默认为 os.tmpdir()
 * @returns {string} target file path
*/
unpackFtPackage('/tmp/applet.ftpkg.z', '/tmp/applet')
// 将 /tmp/applet.ftpkg.z 解压到 /tmp/applet 目录下

FAQs

Package last updated on 10 Oct 2023

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