Skip to content

Commit

Permalink
feat(create): add create function (#24)
Browse files Browse the repository at this point in the history
This also upgrades all tooling to kcd-scripts

Closes #20
  • Loading branch information
Kent C. Dodds authored Sep 8, 2017
1 parent fa9ae8f commit 386f01b
Show file tree
Hide file tree
Showing 22 changed files with 105 additions and 254 deletions.
13 changes: 0 additions & 13 deletions .babelrc

This file was deleted.

3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

7 changes: 0 additions & 7 deletions .eslintrc

This file was deleted.

17 changes: 7 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ sudo: false
language: node_js
cache:
directories:
- node_modules
- ~/.npm
notifications:
email: false
node_js:
- '8'
script:
- npm start validate
node_js: '8'
install: npm install
script: npm run validate
after_success:
- npm install -g codecov semantic-release
- codecov
- npx codecov
# disable auto-releasing until we're ready for this thing to go live
# - semantic-release pre && npm publish && semantic-release post
# - npx -p semantic-release@7 -c "semantic-release pre && npm publish && semantic-release post"
branches:
only:
- master
only: master
4 changes: 0 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Contributing

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Thanks for being willing to contribute!

**Working on your first Pull Request?** You can learn how from this *free* series
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The MIT License (MIT)
Copyright (c) 2016 Kent C. Dodds
Copyright (c) 2017 Kent C. Dodds

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div align="center">
<h1>babel-macros 🎣</h1>

**Enables zero-config, importable babel plugins**
Enables zero-config, importable babel plugins

</div>

Expand All @@ -17,8 +17,6 @@
[![PRs Welcome][prs-badge]][prs]
[![Donate][donate-badge]][donate]
[![Code of Conduct][coc-badge]][coc]
[![Roadmap][roadmap-badge]][roadmap]
[![Examples][examples-badge]][examples]

[![Watch on GitHub][github-watch-badge]][github-watch]
[![Star on GitHub][github-star-badge]][github-star]
Expand Down Expand Up @@ -215,9 +213,9 @@ See the [testing snapshot](https://github.com/kentcdodds/babel-macros/blob/maste
All examples above were *explicit* - a macro was imported and then evaluated
with a specific AST node.

Completely different story are *implicit* babel plugins, like
Completely different story are *implicit* babel plugins, like
[transform-react-constant-elements](https://babeljs.io/docs/plugins/transform-react-constant-elements/),
which process whole AST tree.
which process whole AST tree.

Explicit is often a better pattern than implicit because it requires others to understand
how things are globally configured. This is in this spirit are `babel-macros` designed.
Expand Down Expand Up @@ -268,10 +266,6 @@ MIT
[donate]: http://kcd.im/donate
[coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square
[coc]: https://github.com/kentcdodds/babel-macros/blob/master/other/CODE_OF_CONDUCT.md
[roadmap-badge]: https://img.shields.io/badge/%F0%9F%93%94-roadmap-CD9523.svg?style=flat-square
[roadmap]: https://github.com/kentcdodds/babel-macros/blob/master/other/ROADMAP.md
[examples-badge]: https://img.shields.io/badge/%F0%9F%92%A1-examples-8C8E93.svg?style=flat-square
[examples]: https://github.com/kentcdodds/babel-macros/blob/master/other/EXAMPLES.md
[github-watch-badge]: https://img.shields.io/github/watchers/kentcdodds/babel-macros.svg?style=social
[github-watch]: https://github.com/kentcdodds/babel-macros/watchers
[github-star-badge]: https://img.shields.io/github/stars/kentcdodds/babel-macros.svg?style=social
Expand Down
1 change: 1 addition & 0 deletions create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist').createMacro
13 changes: 0 additions & 13 deletions other/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
# Contributor Covenant Code of Conduct

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**

- [Our Pledge](#our-pledge)
- [Our Standards](#our-standards)
- [Our Responsibilities](#our-responsibilities)
- [Scope](#scope)
- [Enforcement](#enforcement)
- [Attribution](#attribution)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
Expand Down
7 changes: 0 additions & 7 deletions other/EXAMPLES.md

This file was deleted.

12 changes: 0 additions & 12 deletions other/MAINTAINING.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
# Maintaining

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**

- [Code of Conduct](#code-of-conduct)
- [Issues](#issues)
- [Pull Requests](#pull-requests)
- [Release](#release)
- [Thanks!](#thanks)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

This is documentation for maintainers of this project.

## Code of Conduct
Expand Down
21 changes: 0 additions & 21 deletions other/ROADMAP.md

This file was deleted.

4 changes: 0 additions & 4 deletions other/USERS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Users

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<!-- END doctoc generated TOC please keep comment here to allow auto update -->

If you or your company uses this project, add your name to this list! Eventually
we may have a website to showcase these (wanna build it!?)

Expand Down
26 changes: 22 additions & 4 deletions other/docs/author.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,28 @@
## Writing a macro

A macro is a JavaScript module that exports a function. It can be published to
the npm registry (for generic macros, like a css-in-js library) or used locally
(for domain-specific macros, like handling some special case for your company's
localization efforts).
A macro is a JavaScript module that exports a function. Here's a simple example:

```javascript
const createMacro = require('babel-macros/create')

// `createMacros` is simply a function that ensures your macro is only
// called in the context of a babel transpilation and will throw an
// error with a helpful message if someone does not have babel-macros
// configured correctly
module.exports = createMacro(myMacro)

function myMacro({references, state, babel}) {
// state is the second argument you're passed to a visitor in a
// normal babel plugin. `babel` is the `babel-macros` module.
// do whatever you like to the AST paths you find in `renferences`
// read more below...
}
```

It can be published to the npm registry (for generic macros, like a css-in-js
library) or used locally (for domain-specific macros, like handling some special
case for your company's localization efforts).

> Before you write a custom macro, you might consider whether
> [`babel-plugin-preval`][preval] help you do what you want as it's pretty
Expand Down
4 changes: 0 additions & 4 deletions other/manual-releases.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# manual-releases

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<!-- END doctoc generated TOC please keep comment here to allow auto update -->

This project has an automated release set up. So things are only released when there are
useful changes in the code that justify a release. But sometimes things get messed up one way or another
and we need to trigger the release ourselves. When this happens, simply bump the number below and commit
Expand Down
67 changes: 0 additions & 67 deletions package-scripts.js

This file was deleted.

62 changes: 18 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,36 @@
"description": "Enables zero-config, importable babel plugins",
"main": "dist/index.js",
"scripts": {
"start": "nps",
"test": "nps test",
"precommit": "lint-staged && opt --in pre-commit --exec \"npm start validate\""
"add-contributor": "kcd-scripts contributors add",
"build": "kcd-scripts build",
"lint": "kcd-scripts lint",
"test": "kcd-scripts test",
"test:update": "npm test -- --updateSnapshot --coverage",
"validate": "kcd-scripts validate",
"precommit": "kcd-scripts precommit"
},
"files": [
"dist"
"files": ["dist", "create.js"],
"keywords": [
"babel-plugin",
"macros",
"macro",
"babel-macro",
"babel-plugin-macro"
],
"keywords": [],
"author": "Kent C. Dodds <[email protected]> (http://kentcdodds.com/)",
"license": "MIT",
"dependencies": {},
"devDependencies": {
"all-contributors-cli": "^4.3.0",
"ast-pretty-print": "^2.0.0",
"babel-cli": "^6.24.1",
"babel-core": "^6.25.0",
"babel-jest": "^20.0.3",
"babel-plugin-tester": "^3.2.2",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-env": "^1.5.1",
"babel-register": "^6.24.1",
"babel-types": "6.25.0",
"babylon": "6.17.4",
"doctoc": "^1.3.0",
"eslint": "^4.1.1",
"eslint-config-kentcdodds": "^12.4.0",
"husky": "^0.14.3",
"jest": "^20.0.4",
"lint-staged": "^4.0.1",
"nps": "^5.3.1",
"nps-utils": "^1.2.0",
"opt-cli": "^1.5.1",
"prettier-eslint-cli": "^4.0.2"
"kcd-scripts": "0.3.4"
},
"lint-staged": {
"*.js": [
"prettier-eslint --write",
"git add"
]
},
"jest": {
"testEnvironment": "node",
"testPathIgnorePatterns": [
"/node_modules/",
"/fixtures/"
],
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
}
"eslintConfig": {
"extends": "./node_modules/kcd-scripts/eslint.js"
},
"eslintIgnore": ["node_modules", "coverage", "dist"],
"repository": {
"type": "git",
"url": "https://github.com/kentcdodds/babel-macros.git"
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,5 @@ fakeMacro('hi')
fakeMacro('hi');
`;

exports[`throws error if it is not transpiled 1`] = `The macro you imported from "untranspiled.macro" is being executed outside the context of compilation with babel-macros. This indicates that you don't have the babel plugin "babel-macros" configured correctly. Please see the documentation for how to configure babel-macros properly: https://github.com/kentcdodds/babel-macros/blob/master/other/docs/user.md`;
Loading

0 comments on commit 386f01b

Please sign in to comment.