Skip to content

Instantly share code, notes, and snippets.

@junkycoder
Last active September 9, 2018 11:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junkycoder/5544e8338fc6a424ee010e1facb1c672 to your computer and use it in GitHub Desktop.
Save junkycoder/5544e8338fc6a424ee010e1facb1c672 to your computer and use it in GitHub Desktop.
Patch the `reactClassComponentPropTypes` snippet to define `propTypes` as static class property
#!/usr/bin/env node
/**
* Node.js script as patch method for vscode-react extension of 2.2.0 version.
*
* https://github.com/xabikos/vscode-react
* https://github.com/tc39/proposal-class-public-fields
*/
const fs = require('fs');
const { SNIPPETS_PATH, HOME } = process.env;
const PATH =
SNIPPETS_PATH ||
`${HOME}/.vscode/extensions/xabikos.reactsnippets-2.2.0/snippets/snippets.json`;
const SNIPPETS_PATCH = {
reactClassComponentPropTypes: {
prefix: 'rccp',
body:
"import React, { Component } from 'react';\nimport PropTypes from 'prop-types';\n\nclass ${1:${TM_FILENAME_BASE}} extends Component {\n\t\tstatic propTypes = {\n\n\t\t};\n\t\t\n\t\trender() {\n\t\t\treturn (\n\t\t\t\t<div>\n\t\t\t\t\t$0\n\t\t\t\t</div>\n\t\t\t);\n\t}\n}\n\nexport default ${1:${TM_FILENAME_BASE}};",
description:
'Creates a React component class with PropTypes as static property and ES6 module system',
},
};
try {
const snippets_original = JSON.parse(fs.readFileSync(PATH));
const snippets_patched = JSON.stringify({
...snippets_original,
...SNIPPETS_PATCH,
});
fs.writeFileSync(PATH, snippets_patched);
console.log('Patch success!');
} catch (error) {
console.error('Error while patcing vs-code-react extension.');
console.error(error);
console.error('Patch failed! No changes made.');
process.exit(0);
}
@junkycoder
Copy link
Author

Recommended Node.js version is v10.9.0.

You can execute this script right from your Terminal:

export SCRIPT_URL=https://gist.githubusercontent.com/junkycoder/5544e8338fc6a424ee010e1facb1c672/raw/c5f23a67abcfbd32badbccc277bbe9938571bc97/vscode-react-patch.js
node <(curl -s $SCRIPT_URL)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment