Skip to content

A CLI tool to read file content and assign it to a variable

License

Notifications You must be signed in to change notification settings

plantain-00/file2variable-cli

Repository files navigation

file2variable-cli

Dependency Status devDependency Status Build Status: Windows Github CI npm version Downloads type-coverage

A CLI tool to read file content and assign it to a variable

features

  • file content as string variable (*)
  • json file content as object variable (*.json --json)
  • protobuf file content as object variable (*.proto --protobuf)
  • html file minified (*.html --html-minify)
  • vue3 template precompile (* --vue3)
  • position for html file and vue template(<div data-_position="demo/baz.html:2:5"></div>)

install

npm i file2variable-cli

usage

file2variable-cli demo/*.html demo/*.json demo/*.proto -o demo/variables.js --html-minify --json --protobuf --base demo

file2variable-cli demo/*.html demo/*.json demo/*.proto -o demo/variables.js --html-minify --json --protobuf --base demo --watch

options

key description
--config config file
-w,--watch watch mode
-h,--help Print this message.
-v,--version Print the version

config file

file2variable-cli --config demo/file2variable.config.js or file2variable-cli --config demo/file2variable.config.ts

import { Configuration } from 'file2variable-cli'

module.exports = {
  base: 'demo',
  files: [
    'demo/*.txt',
    'demo/*.html',
    'demo/*.json',
    'demo/*.proto'
  ],
  handler: file => {
    if (file.endsWith('foo.html')) {
      return {
        type: 'vue3',
      }
    }
    if (file.endsWith('baz.html')) {
      return { type: 'html-minify' }
    }
    if (file.endsWith('.json')) {
      return { type: 'json' }
    }
    if (file.endsWith('.proto')) {
      return { type: 'protobuf' }
    }
    return { type: 'text' }
  },
  out: 'demo/variables.ts'
} as Configuration

About

A CLI tool to read file content and assign it to a variable

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published