Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. var fs = require('fs');
  21. var shell = require('shelljs');
  22. var path = require('path');
  23. var ROOT = path.join(__dirname, '..', '..');
  24. var events = require('cordova-common').events;
  25. var check_reqs = require('./check_reqs');
  26. // exported method to create a project, returns a promise that resolves with null
  27. module.exports.createProject = function (project_path, package_name, project_name) {
  28. /*
  29. // create the dest and the standard place for our api to live
  30. // platforms/platformName/cordova/Api.js
  31. */
  32. events.emit('log', 'Creating Cordova project for cordova-browser:');
  33. events.emit('log', '\tPath: ' + project_path);
  34. events.emit('log', '\tName: ' + project_name);
  35. // Set default values for path, package and name
  36. project_path = project_path || 'CordovaExample';
  37. // Check if project already exists
  38. if (fs.existsSync(project_path)) {
  39. events.emit('error', 'Oops, destination already exists! Delete it and try again');
  40. }
  41. // Check that requirements are met and proper targets are installed
  42. if (!check_reqs.run()) {
  43. // TODO: use events.emit
  44. events.emit('error', 'Please make sure you meet the software requirements in order to build a browser cordova project');
  45. }
  46. // copy template/cordova directory ( recursive )
  47. shell.cp('-r', path.join(ROOT, 'bin/template/cordova'), project_path);
  48. // copy template/www directory ( recursive )
  49. shell.cp('-r', path.join(ROOT, 'bin/template/www'), project_path);
  50. // recreate our node_modules structure in the new project
  51. let nodeModulesDir = path.join(ROOT, 'node_modules');
  52. if (fs.existsSync(nodeModulesDir)) shell.cp('-r', nodeModulesDir, path.join(project_path, 'cordova'));
  53. // copy check_reqs file
  54. shell.cp(path.join(ROOT, 'bin/lib/check_reqs.js'),
  55. path.join(project_path, 'cordova/lib'));
  56. var platform_www = path.join(project_path, 'platform_www');
  57. // copy cordova-js-src directory
  58. shell.cp('-rf', path.join(ROOT, 'cordova-js-src'), platform_www);
  59. // copy cordova js file to platform_www
  60. shell.cp(path.join(ROOT, 'cordova-lib', 'cordova.js'), platform_www);
  61. // copy favicon file to platform_www
  62. shell.cp(path.join(ROOT, 'bin/template/www/favicon.ico'), platform_www);
  63. // load manifest to write name/shortname
  64. var manifest = require(path.join(ROOT, 'bin/template/www', 'manifest.json'));
  65. manifest.name = project_name;
  66. manifest.short_name = project_name;
  67. // copy manifest file to platform_www
  68. fs.writeFileSync(path.join(platform_www, 'manifest.json'),
  69. JSON.stringify(manifest, null, 2), 'utf-8');
  70. return Promise.resolve();
  71. };