Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge 0bed031 into e8547f1
Browse files Browse the repository at this point in the history
  • Loading branch information
akameco committed Oct 3, 2017
2 parents e8547f1 + 0bed031 commit 758cf8d
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 48 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
"fmt": "prettier --write '**/*.{js,json}'",
"lint": "eslint .",
"prebuild": "rimraf ./packages/**/lib",
"prepublish": "yarn build",
"publish": "lerna publish",
"build": "lerna run build",
"prepare": "yarn build",
"postinstall": "yarn fmt"
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-s2s-action-root/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"babel-template": "^6.26.0",
"babel-types": "^6.26.0",
"globby": "^6.1.0",
"s2s-utils": "^0.0.0",
"s2s-babel-flow-types": "^0.1.0",
"slash": "^1.0.0",
"uppercamelcase": "^3.0.0"
}
}
17 changes: 2 additions & 15 deletions packages/babel-plugin-s2s-action-root/src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @flow
import { relative, normalize, dirname, extname } from 'path'
import { normalize, dirname } from 'path'
import flowSyntax from 'babel-plugin-syntax-flow'
import * as t from 'babel-types'
import template from 'babel-template'
import { removeFlowComment, addFlowComment } from 'babel-add-flow-comments'
import globby from 'globby'
import slash from 'slash'
import upperCamelCase from 'uppercamelcase'
import { getImportPath } from 's2s-utils'
import type { Path, State } from 's2s-babel-flow-types'

const babylonOpts = { sourceType: 'module', plugins: ['flow'] }
Expand All @@ -22,19 +22,6 @@ const createInitAction = wrapTemp(
`export type ReduxInitAction = { type: '@@INIT' }`,
)

function trimExtension(path: string, ext: string = '.js') {
return extname(path) === ext ? path.replace(ext, '') : path
}

function getImportPath(from: string, to: string): string {
const relativePath = slash(relative(dirname(from), to))
const fomattedPath = trimExtension(relativePath)
if (!/^\.\.?/.test(fomattedPath)) {
return `./${fomattedPath}`
}
return fomattedPath
}

function createActionName(path: string) {
const parentPath = normalize(dirname(path)).split('/')
return upperCamelCase(parentPath[parentPath.length - 1]) + 'Action'
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-s2s-reducer-root/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"babel-types": "^6.26.0",
"globby": "^6.1.0",
"s2s-babel-flow-types": "^0.1.0",
"slash": "^1.0.0",
"s2s-utils": "^0.0.0",
"uppercamelcase": "^3.0.0"
}
}
16 changes: 2 additions & 14 deletions packages/babel-plugin-s2s-reducer-root/src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @flow
import { relative, normalize, dirname, extname } from 'path'
import { normalize, dirname } from 'path'
import * as t from 'babel-types'
import template from 'babel-template'
import { removeFlowComment, addFlowComment } from 'babel-add-flow-comments'
import globby from 'globby'
import slash from 'slash'
import upperCamelCase from 'uppercamelcase'
import type { Path, State } from 's2s-babel-flow-types'
import { getImportPath } from 's2s-utils'

const wrapTemp = (tmpl: string) =>
template(tmpl, { sourceType: 'module', plugins: ['flow'] })
Expand All @@ -16,18 +16,6 @@ const builders = {
root: wrapTemp(`export default combineReducers(OBJ)`),
}

const trimExtension = (path: string, ext: string = '.js') =>
extname(path) === ext ? path.replace(ext, '') : path

function getImportPath(from: string, to: string): string {
const relativePath = slash(relative(dirname(from), to))
const fomattedPath = trimExtension(relativePath)
if (!/^\.\.?/.test(fomattedPath)) {
return `./${fomattedPath}`
}
return fomattedPath
}

function getParentDirName(path: string) {
const parentPath = normalize(dirname(path)).split('/')
return upperCamelCase(parentPath[parentPath.length - 1])
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-s2s-state-root/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"babel-types": "^6.26.0",
"globby": "^6.1.0",
"s2s-babel-flow-types": "^0.1.0",
"slash": "^1.0.0",
"s2s-utils": "^0.0.0",
"uppercamelcase": "^3.0.0"
}
}
16 changes: 2 additions & 14 deletions packages/babel-plugin-s2s-state-root/src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @flow
import { relative, normalize, dirname, extname } from 'path'
import { normalize, dirname } from 'path'
import * as t from 'babel-types'
import template from 'babel-template'
import { removeFlowComment, addFlowComment } from 'babel-add-flow-comments'
import globby from 'globby'
import slash from 'slash'
import upperCamelCase from 'uppercamelcase'
import type { Path, State } from 's2s-babel-flow-types'
import { getImportPath } from 's2s-utils'

const wrapTemp = (tmpl: string) =>
template(tmpl, { sourceType: 'module', plugins: ['flow'] })
Expand All @@ -16,18 +16,6 @@ const createObjectType = input =>
STATE: t.objectTypeAnnotation(input, null, null),
})

const trimExtension = (path: string, ext: string = '.js') =>
extname(path) === ext ? path.replace(ext, '') : path

function getImportPath(from: string, to: string): string {
const relativePath = slash(relative(dirname(from), to))
const fomattedPath = trimExtension(relativePath)
if (!/^\.\.?/.test(fomattedPath)) {
return `./${fomattedPath}`
}
return fomattedPath
}

function getParentDirName(path: string) {
const parentPath = normalize(dirname(path)).split('/')
return upperCamelCase(parentPath[parentPath.length - 1])
Expand Down
3 changes: 3 additions & 0 deletions packages/s2s-utils/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["env"]
}
17 changes: 17 additions & 0 deletions packages/s2s-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "s2s-utils",
"version": "0.0.0",
"description": "s2s utils",
"license": "MIT",
"repository": "akameco/s2s-plugins",
"author": "akameco <akameco.t@gmail.com>",
"main": "lib/index.js",
"files": ["lib"],
"scripts": {
"prepare": "npm run build",
"build": "babel src --ignore *.test.js -d lib "
},
"dependencies": {
"slash": "^1.0.0"
}
}
19 changes: 19 additions & 0 deletions packages/s2s-utils/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @flow
import { relative, dirname, extname } from 'path'
import slash from 'slash'

function trimExtension(path /* : string */, ext /* : string */ = '.js') {
return extname(path) === ext ? path.replace(ext, '') : path
}

export function getImportPath(
from /* : string */,
to /* : string */,
) /* : string */ {
const relativePath = slash(relative(dirname(from), to))
const fomattedPath = trimExtension(relativePath)
if (!/^\.\.?/.test(fomattedPath)) {
return `./${fomattedPath}`
}
return fomattedPath
}
17 changes: 17 additions & 0 deletions packages/s2s-utils/src/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @flow
import { getImportPath } from '.'

test('getImportPath same folder', () => {
const result = getImportPath('path/to/index.js', 'path/to/test.js')
expect(result).toBe('./test')
})

test('getImportPath same folder when not ext', () => {
const result = getImportPath('path/to/index', 'path/to/test')
expect(result).toBe('./test')
})

test('getImportPath parent folder', () => {
const result = getImportPath('path/to/nest/index.js', 'path/to/test.js')
expect(result).toBe('../test')
})

0 comments on commit 758cf8d

Please sign in to comment.