Skip to content

Instantly share code, notes, and snippets.

🦍
Generating legacy code

Hector Zarco zzarcon

🦍
Generating legacy code
View GitHub Profile
View changedFiles.js
runWhen([{
changedFiles: () => Promise.resolve(['app/index.js', 'app/components/header.jsx']),
glob: ['app/components/**'],
task(paths) {}
}])
View force_colors.js
const subprocess = exec(command, {
env: {...process.env, FORCE_COLOR: true}
});
View stdout-pipe.js
const subprocess = exec(command);
subprocess.stdout.pipe(process.stdout);
subprocess.stderr.pipe(process.stdout);
subprocess.on('exit', code => process.exit(code));
View run-when-await.js
// Inline await to get the the user changed files
const filesToMatch = changedFiles ? await changedFiles() : files;
// Example of a test
test('should run command if glob files matches', async () => {
await modifyFixtures();
const {stdout} = await run(`'["__fixtures__/**"]' 'echo fixtures changed'`);
expect(stdout.trim()).toEqual('fixtures changed');
await restoreFixtures();
View custom_install.yml
install:
- git clone https://github.com/$TRAVIS_REPO_SLUG.git $TRAVIS_REPO_SLUG
- cd $TRAVIS_REPO_SLUG
- git checkout -qf $TRAVIS_COMMIT
View destructuring.js
const {2: serializedGlob = "['**']", 3: command} = process.argv;
console.log(serializedGlob, command)
View node-promisify.js
const {promisify} = require('util');
const exec = promisify(require('child_process').exec);
exec('git diff --name-only origin/master').then(({stdout}) => console.log(stdout))
View run-when1.js
import runWhen from 'run-when';
runWhen([
{
glob: ['app/components/index.js', 'app/__tests__/**'],
task(paths) {
console.log('This will be called!');
}
},
{
View imgDimensions.js
class ImgDimensions extends React.Component {
state = {width: 0, height: 0, errored: false};
constructor() {
this.onLoad = this.onLoad.bind(this);
this.onError = this.onError.bind(this);
}
onLoad({target: {height, width}}) {
this.setState({width, height});
@zzarcon
zzarcon / foo.js
Created Sep 10, 2017
Bind call to class property
View foo.js
// FROM:
class Foo {
constructor() {
this.bar = this.bar.bind(this);
}
bar() {
return 1;
}
}
You can’t perform that action at this time.