build.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. Copyright 2013 Daniel Wirtz <dcode@dcode.io>
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. var MetaScript = require("metascript"),
  14. path = require("path"),
  15. fs = require("fs");
  16. var rootDir = path.join(__dirname, ".."),
  17. srcDir = path.join(rootDir, "src"),
  18. distDir = path.join(rootDir, "dist"),
  19. pkg = require(path.join(rootDir, "package.json")),
  20. filename;
  21. var scope = {
  22. VERSION: pkg.version, // Version
  23. DOTPROTO: true // Whether to include the ProtoBuf.DotProto package for .proto syntax support
  24. };
  25. // Make full build
  26. console.log("Building protobuf.js with scope", JSON.stringify(scope, null, 2));
  27. fs.writeFileSync(
  28. path.join(distDir, "protobuf.js"),
  29. MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "wrap.js")), filename, scope, srcDir)
  30. );
  31. // Make light build
  32. scope.DOTPROTO = false;
  33. console.log("Building protobuf-light.js with scope", JSON.stringify(scope, null, 2));
  34. fs.writeFileSync(
  35. path.join(distDir, "protobuf-light.js"),
  36. MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "wrap.js")), filename, scope, srcDir)
  37. );
  38. // Update bower.json
  39. scope = { VERSION: pkg.version };
  40. console.log("Updating bower.json with scope", JSON.stringify(scope, null, 2));
  41. fs.writeFileSync(
  42. path.join(rootDir, "bower.json"),
  43. MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "bower.json.in")), filename, scope, srcDir)
  44. );