{"size": 966, "ext": "js", "max_stars_repo_path": "update-resource-ids.js", "max_stars_repo_name": "alphagov-mirror/datagovuk-visual-regression-tests", "max_stars_repo_stars_event_min_datetime": "2021-03-09T15:20:40.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-09T15:20:40.000Z", "max_issues_repo_path": "update-resource-ids.js", "max_issues_repo_name": "alphagov-mirror/datagovuk-visual-regression-tests", "max_issues_repo_issues_event_min_datetime": "2020-08-19T18:11:51.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T11:37:37.000Z", "max_forks_repo_path": "update-resource-ids.js", "max_forks_repo_name": "alphagov-mirror/datagovuk-visual-regression-tests", "max_forks_repo_forks_event_min_datetime": "2020-05-26T09:31:14.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-10T20:13:58.000Z"}
{"max_stars_count": 1, "max_issues_count": 2, "max_forks_count": 4, "avg_line_length": 42.0, "max_line_length": 279, "alphanum_fraction": 0.7122153209}
require('dotenv').config();
const puppeteer = require('puppeteer');
const updateEnv = require('./ckan-setup/utils/update-env');

(async () => {
  console.log('This command will update the .env resource id values to ids generated by your local ckan instance. Please make sure that a local instance of ckan is running and that you have either run the VRT setup, datagovuk test data setup or manually applied the test data.');

  // Start puppeteer
  const browser = await puppeteer.launch();
  const page = await browser.newPage();

  try {
      await updateEnv(page, process.argv[2] ? process.argv[2] : false);
  } catch(e) {
      // This and the browser.close() statement below, outside the try catch, ensure that the puppeteer session always ends. Otherwise the cli will hang until it times out, eating into machine memory
      await browser.close();
      console.log(e);
  }

  console.log('Resource ids updated successfully!');

  await browser.close();
})();