Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repos should identify when they support the output-js task family #1095

Closed
samreid opened this issue Sep 10, 2021 · 4 comments
Closed

Repos should identify when they support the output-js task family #1095

samreid opened this issue Sep 10, 2021 · 4 comments
Assignees

Comments

@samreid
Copy link
Member

samreid commented Sep 10, 2021

To support #1073 and perennial tools, we would like repos to identify when they support an output-js task. @jonathanolson and I discussed adding a package.json flag like so:

"phet":{
    "supportsOutputJS": true
}

We will need to mark this in many repos and will have problems if one is forgotten. Also, @jonathanolson what do you think about running grunt --help in a repo to see if it outputs a task name? That seems like less we have to maintain and less chances to get things wrong (unless the task name accidentally appears in the documentation), but it is also less direct and takes longer to compute each time (from grunt startup overhead, around 1 second on my side).

@jonathanolson we discussed adding the supportsOutputJS flag, but I wanted to get your opinion on that vs using grunt --help or something like that before I proceed. Can you please advise and reassign to me?

Here is my partial patch in case we proceed with the flag:

Index: main/perennial/js/common/ChipperVersion.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/main/perennial/js/common/ChipperVersion.js b/main/perennial/js/common/ChipperVersion.js
--- a/main/perennial/js/common/ChipperVersion.js	(revision 80d39e584823cfd631fe4572f26da2b0eb77928a)
+++ b/main/perennial/js/common/ChipperVersion.js	(date 1631309724317)
@@ -16,9 +16,9 @@
    * @param {number} major - The major part of the version (the 3 in 3.1.2)
    * @param {number} minor - The minor part of the version (the 1 in 3.1.2)
    * @param {number} maintenance - The maintenance part of the version (the 2 in 3.1.2)
-   * @param {boolean} outputJS - Flag that indicates whether grunt suppports the commands `output-js` and `output-js-all`
+   * @param {boolean} chipperSupportsOutputJSGruntTasks - Flag that indicates whether grunt suppports the family of commands `output-js` `output-js-project` and `output-js-all`
    */
-  function ChipperVersion( major, minor, maintenance, outputJS ) {
+  function ChipperVersion( major, minor, maintenance, chipperSupportsOutputJSGruntTasks ) {
 
     assert( typeof major === 'number' && major >= 0 && major % 1 === 0, 'major version should be a non-negative integer' );
     assert( typeof minor === 'number' && minor >= 0 && minor % 1 === 0, 'minor version should be a non-negative integer' );
@@ -28,7 +28,7 @@
     this.major = major;
     this.minor = minor;
     this.maintenance = maintenance;
-    this.outputJS = outputJS;
+    this.chipperSupportsOutputJSGruntTasks = chipperSupportsOutputJSGruntTasks;
   }
 
   // Can't rely on inherit existing
@@ -66,9 +66,9 @@
     const major = parseInt( matches[ 1 ], 10 );
     const minor = parseInt( matches[ 2 ], 10 );
     const maintenance = parseInt( matches[ 3 ], 10 );
-    const outputJS = packageJSON.phet && packageJSON.phet.outputJS;
+    const chipperSupportsOutputJSGruntTasks = packageJSON.phet && packageJSON.phet.chipperSupportsOutputJSGruntTasks;
 
-    return new ChipperVersion( major, minor, maintenance, outputJS );
+    return new ChipperVersion( major, minor, maintenance, chipperSupportsOutputJSGruntTasks );
   };
 
   return ChipperVersion;
Index: main/gravity-and-orbits/package.json
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/main/gravity-and-orbits/package.json b/main/gravity-and-orbits/package.json
--- a/main/gravity-and-orbits/package.json	(revision 70c8bfd8821b6dcafa0a929ca2186fcd512cc72c)
+++ b/main/gravity-and-orbits/package.json	(date 1631289405789)
@@ -25,7 +25,8 @@
     "phet-io": {
       "compareDesignedAPIChanges": true
     },
-    "typescript": true
+    "typescript": true,
+    "supportsOutputJS": true
   },
   "eslintConfig": {
     "extends": "../chipper/eslint/sim_eslintrc.js"
Index: main/perennial/js/common/outputJS.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/main/perennial/js/common/outputJS.js b/main/perennial/js/common/outputJS.js
--- a/main/perennial/js/common/outputJS.js	(revision 80d39e584823cfd631fe4572f26da2b0eb77928a)
+++ b/main/perennial/js/common/outputJS.js	(date 1631310858353)
@@ -8,28 +8,44 @@
  */
 
 const execute = require( '../dual/execute' );
+const fs = require( 'fs' );
 const gruntCommand = require( '../common/gruntCommand' );
 const winston = require( 'winston' );
 const ChipperVersion = require( '../common/ChipperVersion' );
+const loadJSON = require( '../common/loadJSON' );
 
 /**
  * Outputs JS for a directory
  * @public
  *
- * @param {string} cwd
+ * @param {string} repo
  * @returns {Promise}
  */
-module.exports = async function( cwd ) {
+module.exports = async function( repo ) {
 
   winston.info( 'running outputJS' );
 
   const chipperVersion = ChipperVersion.getFromRepository();
 
-  if ( chipperVersion.outputJS ) {
-    winston.info( 'running grunt output-js' );
-    await execute( gruntCommand, [ 'output-js' ], cwd );
+  let ranOutputJS = false;
+
+  // Not every version of chipper has the output-js task family.  Only proceed if it exists in this version of chipper.
+  if ( chipperVersion.chipperSupportsOutputJSGruntTasks ) {
+
+    const packageFilePath = `../${repo}/package.json`;
+    const exists = fs.existsSync( packageFilePath );
+    if ( exists ) {
+      const packageObject = await loadJSON( packageFilePath );
+
+      // Not every repo supports the output-js task, only proceed if it is supported
+      if ( packageObject.phet && packageObject.phet.supportsOutputJS ) {
+        winston.info( 'running grunt output-js' );
+        await execute( gruntCommand, [ 'output-js' ], `../${repo}` );
+        ranOutputJS = true;
+      }
+    }
   }
-  else {
+  if ( !ranOutputJS ) {
     winston.info( 'outputJS not detected, skipping...' );
   }
 };
\ No newline at end of file
Index: main/chipper/package.json
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/main/chipper/package.json b/main/chipper/package.json
--- a/main/chipper/package.json	(revision 095967ac58bc0b0e9ee7a2501c0d6c8ce40f1bac)
+++ b/main/chipper/package.json	(date 1631289981858)
@@ -7,7 +7,8 @@
     "url": "https://github.com/phetsims/chipper.git"
   },
   "phet": {
-    "outputJS": true
+    "chipperSupportsOutputJSGruntTasks": true,
+    "supportsOutputJS": true
   },
   "devDependencies": {
     "@babel/core": "^7.15.0",
@samreid samreid added this to the Basic Typescript Tooling milestone Sep 10, 2021
samreid added a commit to phetsims/perennial that referenced this issue Sep 11, 2021
samreid added a commit to phetsims/gravity-and-orbits that referenced this issue Sep 11, 2021
@samreid
Copy link
Member Author

samreid commented Sep 11, 2021

@zepumph and I discussed it and agreed to move forward with the package.json flag. Self-assigning to add the flag to all appropriate repos.

@samreid samreid assigned samreid and unassigned jonathanolson Sep 11, 2021
samreid added a commit to phetsims/area-model-decimals that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/area-model-common that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/acid-base-solutions that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/area-model-algebra that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/atomic-interactions that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/area-model-introduction that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/area-builder that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/balloons-and-static-electricity that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/balancing-chemical-equations that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/arithmetic that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/axon that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/balancing-act that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/bumper that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/curve-fitting that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/build-a-molecule that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/area-model-multiplication that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/bending-light that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/coulombs-law that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/collision-lab that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/circuit-construction-kit-ac-virtual-lab that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/blast that referenced this issue Sep 12, 2021
samreid added a commit to phetsims/reactants-products-and-leftovers that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/number-line-integers that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/resistance-in-a-wire that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/proportion-playground that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/tappi that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/ratio-and-proportion that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/states-of-matter-basics that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/rutherford-scattering that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/trig-tour that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/under-pressure that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/states-of-matter that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/unit-rates that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/sun that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/wave-on-a-string that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/vector-addition-equations that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/tambo that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/vibe that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/vegas that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/vector-addition that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/xray-diffraction that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/wilder that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/wave-interference that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/waves-intro that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/twixt that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/scenery-phet that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/simula-rasa that referenced this issue Oct 13, 2021
samreid added a commit to phetsims/ph-scale-basics that referenced this issue Oct 13, 2021
@samreid
Copy link
Member Author

samreid commented Oct 13, 2021

Pushed, re-closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants