-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the build / run / test process Windows-compatible by adding NPM …
…scripts for all the tasks. (#13536) * Make the build / run / test process Windows-compatible by adding NPM scripts for all the tasks. This PR keeps the Makefile and all its tasks intact. So now, both systems (NPM and make) work, but NPM is used everywhere (CircleCI, Dockerfile, css-hot-loader). To keep the PR reasonably small, I've ommited any documentation changes. cc/ @blowery @gziolo @gwwar @stephanethomas * Updated check-node-version and globby to the latest version * Reverted the Dockerfile to use the old, Makefile-based build system * Fixed the build (broken with the merge of the "notifications panel" stuff). * Updated shrinkwrap.
- Loading branch information
Showing
20 changed files
with
647 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Runs `eslint` only on the files the current branch modified. | ||
* Note that this has file-level granularity, so if you modified a | ||
* small bit of a big fail, you may get errors that weren't caused by you. | ||
*/ | ||
|
||
const path = require( 'path' ); | ||
const child_process = require( 'child_process' ); | ||
|
||
const eslintBin = path.join( '.', 'node_modules', '.bin', 'eslint' ); | ||
|
||
const branchName = child_process.execSync( 'git rev-parse --abbrev-ref HEAD' ).toString().trim(); | ||
const rev = child_process.execSync( 'git merge-base ' + branchName + ' master' ).toString().trim(); | ||
const files = child_process.execSync( 'git diff --name-only ' + rev + '..HEAD' ) | ||
.toString() | ||
.split( '\n' ) | ||
.map( ( name ) => name.trim() ) | ||
.filter( ( name ) => name.endsWith( '.js' ) || name.endsWith( '.jsx' ) ); | ||
|
||
const lintResult = child_process.spawnSync( eslintBin, [ '--cache', ...files ], { | ||
shell: true, | ||
stdio: 'inherit', | ||
} ); | ||
|
||
process.exit( lintResult.status ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Performs an `npm install`. Since that's a costly operation, | ||
* it will only perform it if needed, that is, if the packages | ||
* installed at `node_modules` aren't in sync over what | ||
* `npm-shrinkwrap.json` has. For that, modification times of both | ||
* files will be compared. If the shrinkwrap is newer, it means that | ||
* the packages at node_modules may be outdated. That will happen, | ||
* for example, when switching branches. | ||
*/ | ||
|
||
const fs = require( 'fs' ); | ||
const spawnSync = require( 'child_process' ).spawnSync; | ||
|
||
const needsInstall = () => { | ||
try { | ||
const shrinkwrapTime = fs.statSync( 'npm-shrinkwrap.json' ).mtime; | ||
const nodeModulesTime = fs.statSync( 'node_modules' ).mtime; | ||
return shrinkwrapTime - nodeModulesTime > 1000; // In Windows, directory mtime has less precision than file mtime | ||
} catch ( e ) { | ||
return true; | ||
} | ||
}; | ||
|
||
if ( needsInstall() ) { | ||
const installResult = spawnSync( 'npm', [ 'install' ], { | ||
shell: true, | ||
stdio: 'inherit', | ||
}); | ||
process.exit( installResult.status ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env node | ||
|
||
const execSync = require( 'child_process' ).execSync; | ||
const spawnSync = require( 'child_process' ).spawnSync; | ||
const chalk = require( 'chalk' ); | ||
|
||
console.log( '\nBy contributing to this project, you license the materials you contribute ' + | ||
'under the GNU General Public License v2 (or later). All materials must have ' + | ||
'GPLv2 compatible licenses — see .github/CONTRIBUTING.md for details.\n\n' ); | ||
|
||
// Make quick pass over config files on every change | ||
require( '../server/config/validate-config-keys' ); | ||
|
||
const files = execSync( 'git diff --cached --name-only' ) | ||
.toString() | ||
.split( '\n' ) | ||
.map( ( name ) => name.trim() ) | ||
.filter( ( name ) => name.endsWith( '.js' ) || name.endsWith( '.jsx' ) ); | ||
|
||
const lintResult = spawnSync( 'node', [ 'bin/run-lint', ...files, '--', '--diff=index' ], { | ||
shell: true, | ||
stdio: 'inherit', | ||
} ); | ||
|
||
if ( lintResult.status ) { | ||
console.log( chalk.red( 'COMMIT ABORTED:' ), 'The linter reported some problems. ' + | ||
'If you are aware of them and it is OK, ' + | ||
'repeat the commit command with --no-verify to avoid this check.' ); | ||
process.exit( 1 ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env node | ||
|
||
const execSync = require( 'child_process' ).execSync; | ||
const readline = require( 'readline-sync' ); | ||
|
||
console.log( '\nBy contributing to this project, you license the materials you contribute ' + | ||
'under the GNU General Public License v2 (or later). All materials must have ' + | ||
'GPLv2 compatible licenses — see .github/CONTRIBUTING.md for details.\n\n' ); | ||
|
||
const currentBranch = execSync( 'git rev-parse --abbrev-ref HEAD' ).toString().trim(); | ||
|
||
if ( 'master' === currentBranch ) { | ||
if ( ! readline.keyInYN( "You're about to push !!![ master ]!!!, is that what you intended?" ) ) { | ||
process.exit( 1 ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Simple script to remove files. Since this will be use to clean node_modules, | ||
* it can't have any dependency (except for the Node standard lib). | ||
* | ||
* Usage: | ||
* rm.js folder | ||
* Will delete "folder" and its contents, or do nothing if it doesn't exist | ||
* rm.js file.ext | ||
* Will delete the file, or do nothing if it doesn't exist | ||
* rm.js folder .ext1 .ext2 | ||
* Will delete all the files inside "folder" that end in the given extensions | ||
*/ | ||
|
||
const fs = require( 'fs' ); | ||
|
||
if ( process.argv.length < 3 ) { | ||
process.exit( 1 ); | ||
} | ||
|
||
const target = process.argv[ 2 ]; | ||
const extensions = process.argv.slice( 3 ); | ||
|
||
const deleteFolderRecursive = ( path ) => { | ||
fs.readdirSync( path ).forEach( ( file ) => { | ||
const curPath = path + '/' + file; | ||
if( fs.lstatSync( curPath ).isDirectory() ) { | ||
deleteFolderRecursive( curPath ); | ||
} else { | ||
fs.unlinkSync( curPath ); | ||
} | ||
} ); | ||
fs.rmdirSync( path ); | ||
}; | ||
|
||
const deleteFiles = ( path, extensions ) => { | ||
fs.readdirSync( path ).forEach( ( file ) => { | ||
if ( extensions | ||
.map( ( ext ) => file.endsWith( ext ) ) | ||
.filter( Boolean ) | ||
.length ) { | ||
fs.unlinkSync( path + '/' + file ); | ||
} | ||
} ); | ||
}; | ||
|
||
if( fs.existsSync( target ) ) { | ||
if( fs.lstatSync( target ).isDirectory() ) { | ||
if ( extensions.length ) { | ||
deleteFiles( target, extensions ); | ||
} else { | ||
deleteFolderRecursive( target ); | ||
} | ||
} else { | ||
fs.unlinkSync( target ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Removes the redundant fields on the npm-shrinkwrap.json file. | ||
* Similar to `shonkwrap`, but rewritten to be multiplatform. | ||
* It's plain JS with no external dependencies. | ||
*/ | ||
|
||
const fs = require( 'fs' ); | ||
const shrinkwrap = require( '../npm-shrinkwrap.json' ); | ||
|
||
function isGitDep( rep ) { | ||
return /^git/.test( rep ); | ||
} | ||
function replacer( key, val ) { | ||
if ( ! this.version ) { | ||
return val; | ||
} | ||
if ( key === "from" && ! isGitDep( this.resolved ) ) { | ||
return undefined; | ||
} | ||
if ( key === "resolved" && ! isGitDep( val ) && this.from !== val ) { | ||
return undefined; | ||
} | ||
return val; | ||
} | ||
|
||
fs.writeFileSync( __dirname + '/../npm-shrinkwrap.json', JSON.stringify( shrinkwrap, replacer, 2 ) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.