You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2020/12/01 09:21:58 UTC

[cordova-js] branch master updated: build: improve cordova-js version ID in built file (#230)

This is an automated email from the ASF dual-hosted git repository.

raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-js.git


The following commit(s) were added to refs/heads/master by this push:
     new ad5b74a  build: improve cordova-js version ID in built file (#230)
ad5b74a is described below

commit ad5b74ad1c173c30bf8dc9f7b70cfe3d7122877e
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Tue Dec 1 10:21:49 2020 +0100

    build: improve cordova-js version ID in built file (#230)
    
    - uses `git describe` instead of `git rev-parse HEAD`
    - fallback to version from package.json if not in a cordova-js repo
    - rename and factor out buildId
---
 build-tools/{build.js => build-id.js} | 31 +++++++++++++------------------
 build-tools/build.js                  | 13 ++++---------
 build-tools/bundle.js                 |  4 ++--
 3 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/build-tools/build.js b/build-tools/build-id.js
similarity index 58%
copy from build-tools/build.js
copy to build-tools/build-id.js
index b2aded3..8143990 100644
--- a/build-tools/build.js
+++ b/build-tools/build-id.js
@@ -17,26 +17,21 @@
  * under the License.
  */
 
+const fs = require('fs');
+const path = require('path');
 const execa = require('execa');
-const bundle = require('./bundle');
-const scripts = require('./scripts');
-const modules = require('./modules');
 const { pkgRoot } = require('./common');
 
-module.exports = function build (userConfig) {
-    const config = Object.assign({ preprocess: x => x }, userConfig);
-
-    return Promise.all([
-        scripts(config),
-        modules(config),
-        getCommitId()
-    ])
-        .then(([scripts, modules, commitId]) => {
-            Object.assign(config, { commitId });
-            return bundle(scripts, modules, config);
-        });
-};
+async function getBuildId () {
+    // Use git describe if in cordova-js repo, else use package version
+    return fs.existsSync(path.join(pkgRoot, '.git'))
+        ? describeGitRepo()
+        : require('../package').version;
+}
 
-function getCommitId () {
-    return execa('git', ['rev-parse', 'HEAD'], { cwd: pkgRoot }).then(data => data.stdout);
+async function describeGitRepo () {
+    const gitArgs = ['describe', '--always', '--tags', '--match=rel/*', '--dirty'];
+    return (await execa('git', gitArgs, { cwd: pkgRoot })).stdout;
 }
+
+module.exports = getBuildId;
diff --git a/build-tools/build.js b/build-tools/build.js
index b2aded3..32f1d6b 100644
--- a/build-tools/build.js
+++ b/build-tools/build.js
@@ -17,11 +17,10 @@
  * under the License.
  */
 
-const execa = require('execa');
 const bundle = require('./bundle');
 const scripts = require('./scripts');
 const modules = require('./modules');
-const { pkgRoot } = require('./common');
+const getBuildId = require('./build-id');
 
 module.exports = function build (userConfig) {
     const config = Object.assign({ preprocess: x => x }, userConfig);
@@ -29,14 +28,10 @@ module.exports = function build (userConfig) {
     return Promise.all([
         scripts(config),
         modules(config),
-        getCommitId()
+        getBuildId()
     ])
-        .then(([scripts, modules, commitId]) => {
-            Object.assign(config, { commitId });
+        .then(([scripts, modules, buildId]) => {
+            Object.assign(config, { buildId });
             return bundle(scripts, modules, config);
         });
 };
-
-function getCommitId () {
-    return execa('git', ['rev-parse', 'HEAD'], { cwd: pkgRoot }).then(data => data.stdout);
-}
diff --git a/build-tools/bundle.js b/build-tools/bundle.js
index 3a7b97a..bfebd02 100644
--- a/build-tools/bundle.js
+++ b/build-tools/bundle.js
@@ -27,14 +27,14 @@ module.exports = function bundle (scripts, modules, config) {
 };
 
 const bundleTemplate = ({
-    commitId,
+    buildId,
     platformName,
     platformVersion,
     includeScript,
     modules
 }) => `
 // Platform: ${platformName}
-// ${commitId}
+// cordova-js ${buildId}
 /*
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org