copy-www-build-step.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env node
  2. /*
  3. Licensed to the Apache Software Foundation (ASF) under one
  4. or more contributor license agreements. See the NOTICE file
  5. distributed with this work for additional information
  6. regarding copyright ownership. The ASF licenses this file
  7. to you under the Apache License, Version 2.0 (the
  8. "License"); you may not use this file except in compliance
  9. with the License. You may obtain a copy of the License at
  10. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing,
  12. software distributed under the License is distributed on an
  13. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. KIND, either express or implied. See the License for the
  15. specific language governing permissions and limitations
  16. under the License.
  17. */
  18. // This script copies the www directory into the Xcode project.
  19. // This script should not be called directly.
  20. // It is called as a build step from Xcode.
  21. var BUILT_PRODUCTS_DIR = process.env.BUILT_PRODUCTS_DIR,
  22. FULL_PRODUCT_NAME = process.env.FULL_PRODUCT_NAME,
  23. COPY_HIDDEN = process.env.COPY_HIDDEN,
  24. PROJECT_FILE_PATH = process.env.PROJECT_FILE_PATH;
  25. var path = require('path'),
  26. fs = require('fs'),
  27. shell = require('shelljs'),
  28. glob = require('glob'),
  29. srcDir = 'www',
  30. dstDir = path.join(BUILT_PRODUCTS_DIR, FULL_PRODUCT_NAME),
  31. dstWwwDir = path.join(dstDir, 'www');
  32. if(!BUILT_PRODUCTS_DIR) {
  33. console.error('The script is meant to be run as an Xcode build step and relies on env variables set by Xcode.');
  34. process.exit(1);
  35. }
  36. try {
  37. fs.statSync(srcDir);
  38. } catch (e) {
  39. console.error('Path does not exist: ' + srcDir);
  40. process.exit(1);
  41. }
  42. // Code signing files must be removed or else there are
  43. // resource signing errors.
  44. shell.rm('-rf', dstWwwDir);
  45. shell.rm('-rf', path.join(dstDir, '_CodeSignature'));
  46. shell.rm('-rf', path.join(dstDir, 'PkgInfo'));
  47. shell.rm('-rf', path.join(dstDir, 'embedded.mobileprovision'));
  48. // Copy www dir recursively
  49. if(!!COPY_HIDDEN) {
  50. shell.mkdir('-p', dstWwwDir);
  51. shell.cp('-r', glob.sync(srcDir + '/**', { dot: true }), dstWwwDir);
  52. } else {
  53. shell.cp('-r', srcDir, dstDir);
  54. }
  55. // Copy the config.xml file.
  56. shell.cp('-f', path.join(path.dirname(PROJECT_FILE_PATH), path.basename(PROJECT_FILE_PATH, '.xcodeproj'), 'config.xml'),
  57. dstDir);