Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env node
- var fs = require('fs');
- var path = require('path');
- console.log('Running hook...');
- // TARGET is the variable that you have to specify
- // If you run TARGET=prod cordova build
- // The hook will look for a file named prod.js inside the config directory
- if (process.env.TARGET) {
- var srcFile = path.join('config', process.env.TARGET + '.js');
- // Specify the files you would like to replace.
- // NOTE: The android path is for Cordova 7.
- // If you're running an older version, the path is:
- // "platforms/android/assets/www/index.html"
- var configFilesToReplace = {
- android: 'platforms/android/app/src/main/assets/www/js/defaults.js',
- ios: 'platforms/ios/www/js/defaults.js',
- };
- for (var platform in configFilesToReplace) {
- console.log(
- 'Modifying config for platform ' +
- platform +
- ', TARGET=' +
- process.env.TARGET
- );
- var destFile = path.join(configFilesToReplace[platform]);
- if (!fs.existsSync(srcFile)) {
- // Throw an error if the file does not exist
- throw 'Missing config file: ' + srcFile;
- } else {
- console.log('copying ' + srcFile + ' to ' + destFile);
- // The command that replaces the contents of the file
- fs.createReadStream(srcFile).pipe(fs.createWriteStream(destFile));
- }
- }
- } else {
- // If not target was specified, do nothing.
- console.log('TARGET environment variable is not set. Using default values.');
- }
Add Comment
Please, Sign In to add comment