apiVersion: v1
kind: ConfigMap
metadata:
  name: nodejs-scripts
  namespace: argo
data:
  update-chart-version.js: |
    const yaml = require('js-yaml');
    const fs   = require('fs');

    try {
      const chartFilepath = process.argv.slice(2)[0]
      const chartVersion = process.argv.slice(2)[1]
      let doc = yaml.load(fs.readFileSync(chartFilepath, 'utf8'));
      doc.version = chartVersion
      console.log("set version to", doc.version);
      
      fs.writeFile(chartFilepath, yaml.dump(doc), err => {
        if (err) {
          console.error(err)
          return
        }
        console.log(yaml.dump(doc))
      })      
    } catch (e) {
      console.log(e);
    }
  get-chart-version.js: |
    const yaml = require('js-yaml');
    const fs   = require('fs');

    try {
      const chartFilepath = process.argv.slice(2)[0]
      const doc = yaml.load(fs.readFileSync(chartFilepath, 'utf8'));
      console.log(doc.version);
    } catch (e) {
      console.log(e);
    }
