Skip to content
Permalink
Browse files

refactor: into esmodules

  • Loading branch information...
dariocravero committed May 23, 2019
1 parent 3951846 commit 79925af0c3dc4810c5d510ef2f4a37cc0770e92c
Showing with 47 additions and 122 deletions.
  1. +4 −4 clean.js
  2. +9 −11 cli.js
  3. +4 −4 ensure-flow.js
  4. +7 −2 ensure-local-container.js
  5. +2 −2 ensure-track-context.js
  6. +2 −2 package.json
  7. +0 −1 restricted-names.js
  8. +18 −18 watch.js
  9. +1 −78 yarn.lock
@@ -1,8 +1,8 @@
let glob = require('fast-glob')
let fs = require('fs')
let path = require('path')
import glob from 'fast-glob'
import fs from 'fs'
import path from 'path'

module.exports = async src => {
export default async function clean(src) {
let options = {
bashNative: ['linux'],
cwd: src,
20 cli.js
@@ -1,10 +1,12 @@
#!/usr/bin/env node
#!/usr/bin/env node --experimental-modules --experimental-json-modules

let { readFileSync, statSync } = require('fs')
let { morph, parse, pathToName } = require('./lib.js')
let chalk = require('chalk')
let cleanup = require('./clean.js')
let watch = require('./watch.js')
import { statSync } from 'fs'
import chalk from 'chalk'
import cleanup from './clean.js'
import minimist from 'minimist'
import watch from './watch.js'
import updateNotifier from 'update-notifier'
import pkg from './package.json'

let {
_,
@@ -16,7 +18,7 @@ let {
watch: shouldWatch,
verbose,
version,
} = require('minimist')(process.argv.slice(2), {
} = minimist(process.argv.slice(2), {
alias: {
help: 'h',
},
@@ -53,7 +55,6 @@ if (help) {
}

if (version) {
let pkg = require('./package.json')
console.log(`v${pkg.version}`)
process.exit()
}
@@ -72,9 +73,6 @@ if (clean) {
process.exit()
}

let updateNotifier = require('update-notifier')
let pkg = require('./package.json')

updateNotifier({ pkg }).notify()

console.log(`Views Tools morpher v${pkg.version}\n\n`)
@@ -1,5 +1,5 @@
let fs = require('mz/fs')
let prettier = require('prettier')
import fs from 'mz/fs.js'
import prettier from 'prettier'

let makeFlow = flow => `import React, { useCallback, useContext, useLayoutEffect, useState } from 'react'
@@ -48,8 +48,8 @@ Flow.defaultProps = {
}
`

module.exports = async (file, flow) => {
await fs.writeFile(
export default function ensureFlow(file, flow) {
return fs.writeFile(
file,
prettier.format(makeFlow(flow), {
parser: 'babel',
@@ -1,4 +1,4 @@
let fs = require('mz/fs')
import fs from 'mz/fs.js'

let GET_INITIAL_LANGUAGE = {
'react-dom': `export default supported => closest(navigator.language || navigator.browserLanguage, supported)
@@ -75,7 +75,12 @@ export default class LocalContainer extends Container {
}`,
}

module.exports = async ({ as, file, fileGetInitialLanguage, supported }) => {
export default async function ensureLocalContainer({
as,
file,
fileGetInitialLanguage,
supported,
}) {
if (!(await fs.exists(fileGetInitialLanguage))) {
await fs.writeFile(fileGetInitialLanguage, GET_INITIAL_LANGUAGE[as], {
encoding: 'utf8',
@@ -1,4 +1,4 @@
let fs = require('mz/fs')
import fs from 'mz/fs.js'

let TRACK_CONTEXT = `import React from 'react'
@@ -19,7 +19,7 @@ export class Track extends React.Component {
}
}`

module.exports = async ({ file }) => {
export default async function ensureTrackContext({ file }) {
if (!(await fs.exists(file))) {
await fs.writeFile(file, TRACK_CONTEXT, {
encoding: 'utf8',
@@ -2,7 +2,8 @@
"name": "@viewstools/morph",
"version": "19.0.0-alpha.11",
"description": "Views language morpher",
"main": "lib.js",
"main": "index.js",
"type": "module",
"bin": {
"views-morph": "./cli.js"
},
@@ -57,7 +58,6 @@
"mz": "^2.6.0",
"prettier": "^1.4.2",
"read-pkg-up": "^4.0.0",
"save": "^2.3.2",
"svgo": "^1.0.3",
"to-camel-case": "^1.0.0",
"to-pascal-case": "^1.0.0",
@@ -4,5 +4,4 @@ import reactNative from './morph/react-native/restricted-names.js'
export default {
'react-dom': reactDom,
'react-native': reactNative,
e2e: [],
}
@@ -1,20 +1,20 @@
let { exec } = require('child_process')
let { isViewNameRestricted, morph, morphFont, parse } = require('./lib.js')
let chalk = require('chalk')
let chokidar = require('chokidar')
let debounce = require('debounce')
let ensureFlow = require('./ensure-flow.js')
let ensureLocalContainer = require('./ensure-local-container.js')
let ensureTrackContext = require('./ensure-track-context.js')
let getLatestVersion = require('latest-version')
let flatten = require('flatten')
let fs = require('mz/fs')
let glob = require('fast-glob')
let hasYarn = require('has-yarn')
let path = require('path')
let toPascalCase = require('to-pascal-case')
let uniq = require('array-uniq')
let readPkgUp = require('read-pkg-up')
import { exec } from 'child_process'
import { isViewNameRestricted, morph, morphFont, parse } from './index.js'
import chalk from 'chalk'
import chokidar from 'chokidar'
import debounce from 'debounce'
import ensureFlow from './ensure-flow.js'
import ensureLocalContainer from './ensure-local-container.js'
import ensureTrackContext from './ensure-track-context.js'
import getLatestVersion from 'latest-version'
import flatten from 'flatten'
import fs from 'mz/fs.js'
import glob from 'fast-glob'
import hasYarn from 'has-yarn'
import path from 'path'
import toPascalCase from 'to-pascal-case'
import uniq from 'array-uniq'
import readPkgUp from 'read-pkg-up'

let FONT_TYPES = {
'.otf': 'opentype',
@@ -41,7 +41,7 @@ let relativise = (from, to) => {

let onMorph = ({ file, code }) => fs.writeFile(`${file}.js`, code)

module.exports = async function watch({
export default async function watch({
as = 'react-dom',
enableAnimated = true,
local = 'en',
@@ -1099,13 +1099,6 @@ async-limiter@~1.0.0:
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.0.tgz#78faed8c3d074ab81f22b4e985d79e8738f720f8"
integrity sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==

async@^2.6.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/async/-/async-2.6.2.tgz#18330ea7e6e313887f5d2f2a904bac6fe4dd5381"
integrity sha512-H1qVYh1MYhEEFLsP97cVKqCGo7KfCyTt6uEWqsTBr9SO84oK9Uwbyd/yCW+6rKJLHksBNUVWZDAjfS+Ccx0Bbg==
dependencies:
lodash "^4.17.11"

asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
@@ -1929,11 +1922,6 @@ duplexer3@^0.1.4:
resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2"
integrity sha1-7gHdHKwO08vH/b6jfcCo8c4ALOI=

duplexer@^0.1.1, duplexer@~0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.1.tgz#ace6ff808c1ce66b57d1ebf97977acb02334cfc1"
integrity sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=

ecc-jsbn@~0.1.1:
version "0.1.2"
resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz#3a83a904e54353287874c564b7549386849a98c9"
@@ -2168,19 +2156,6 @@ esutils@^2.0.2:
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b"
integrity sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=

event-stream@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/event-stream/-/event-stream-4.0.1.tgz#4092808ec995d0dd75ea4580c1df6a74db2cde65"
integrity sha512-qACXdu/9VHPBzcyhdOWR5/IahhGMf0roTeZJfzz077GwylcDd90yOHLouhmv7GJ5XzPi6ekaQWd8AvPP2nOvpA==
dependencies:
duplexer "^0.1.1"
from "^0.1.7"
map-stream "0.0.7"
pause-stream "^0.0.11"
split "^1.0.1"
stream-combiner "^0.2.2"
through "^2.3.8"

exec-sh@^0.3.2:
version "0.3.2"
resolved "https://registry.yarnpkg.com/exec-sh/-/exec-sh-0.3.2.tgz#6738de2eb7c8e671d0366aea0b0db8c6f7d7391b"
@@ -2438,11 +2413,6 @@ from2@^2.1.1:
inherits "^2.0.1"
readable-stream "^2.0.0"

from@^0.1.7:
version "0.1.7"
resolved "https://registry.yarnpkg.com/from/-/from-0.1.7.tgz#83c60afc58b9c56997007ed1a768b3ab303a44fe"
integrity sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4=

fs-minipass@^1.2.5:
version "1.2.6"
resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-1.2.6.tgz#2c5cc30ded81282bfe8a0d7c7c1853ddeb102c07"
@@ -3915,11 +3885,6 @@ locate-path@^3.0.0:
p-locate "^3.0.0"
path-exists "^3.0.0"

lodash.assign@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.assign/-/lodash.assign-4.2.0.tgz#0d99f3ccd7a6d261d19bdaeb9245005d285808e7"
integrity sha1-DZnzzNem0mHRm9rrkkUAXShYCOc=

lodash.sortby@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
@@ -4012,11 +3977,6 @@ map-cache@^0.2.2:
resolved "https://registry.yarnpkg.com/map-cache/-/map-cache-0.2.2.tgz#c32abd0bd6525d9b051645bb4f26ac5dc98a0dbf"
integrity sha1-wyq9C9ZSXZsFFkW7TyasXcmKDb8=

map-stream@0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/map-stream/-/map-stream-0.0.7.tgz#8a1f07896d82b10926bd3744a2420009f88974a8"
integrity sha1-ih8HiW2CsQkmvTdEokIACfiJdKg=

map-visit@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/map-visit/-/map-visit-1.0.0.tgz#ecdca8f13144e660f1b5bd41f12f3479d98dfb8f"
@@ -4103,11 +4063,6 @@ mimic-response@^1.0.0:
resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-1.0.1.tgz#4923538878eef42063cb8a3e3b0798781487ab1b"
integrity sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==

mingo@1:
version "1.3.3"
resolved "https://registry.yarnpkg.com/mingo/-/mingo-1.3.3.tgz#6922c4d147efc771a01425a2c4c8f7784478c546"
integrity sha1-aSLE0Ufvx3GgFCWixMj3eER4xUY=

minimatch@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
@@ -4681,13 +4636,6 @@ path-type@^3.0.0:
dependencies:
pify "^3.0.0"

pause-stream@^0.0.11:
version "0.0.11"
resolved "https://registry.yarnpkg.com/pause-stream/-/pause-stream-0.0.11.tgz#fe5a34b0cbce12b5aa6a2b403ee2e73b602f1445"
integrity sha1-/lo0sMvOErWqaitAPuLnO2AvFEU=
dependencies:
through "~2.3"

performance-now@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
@@ -5254,16 +5202,6 @@ sane@^4.0.3:
minimist "^1.1.1"
walker "~1.0.5"

save@^2.3.2:
version "2.4.0"
resolved "https://registry.yarnpkg.com/save/-/save-2.4.0.tgz#af93ff9b3d7a41d0aff49a23433870613a460f9b"
integrity sha512-wd5L2uVnsKYkIUaK6i8Ie66IOHaI328gMF0MPuTJtYOjXgUolC33LSIk7Qr8WVA55QHaGwfiVS8a7EFIeGOR3w==
dependencies:
async "^2.6.2"
event-stream "^4.0.1"
lodash.assign "^4.2.0"
mingo "1"

sax@^1.2.4, sax@~1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
@@ -5487,13 +5425,6 @@ split-string@^3.0.1, split-string@^3.0.2:
dependencies:
extend-shallow "^3.0.0"

split@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/split/-/split-1.0.1.tgz#605bd9be303aa59fb35f9229fbea0ddec9ea07d9"
integrity sha512-mTyOoPbrivtXnwnIxZRFYRrPNtEFKlpB2fvjSnCQUiAA6qAZzqwna5envK4uk6OIeP17CsdF3rSBGYVBsU0Tkg==
dependencies:
through "2"

sprintf-js@~1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
@@ -5542,14 +5473,6 @@ stealthy-require@^1.1.1:
resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b"
integrity sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=

stream-combiner@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/stream-combiner/-/stream-combiner-0.2.2.tgz#aec8cbac177b56b6f4fa479ced8c1912cee52858"
integrity sha1-rsjLrBd7Vrb0+kec7YwZEs7lKFg=
dependencies:
duplexer "~0.1.1"
through "~2.3.4"

strict-uri-encode@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz#279b225df1d582b1f54e65addd4352e18faa0713"
@@ -5764,7 +5687,7 @@ throat@^4.0.0:
resolved "https://registry.yarnpkg.com/throat/-/throat-4.1.0.tgz#89037cbc92c56ab18926e6ba4cbb200e15672a6a"
integrity sha1-iQN8vJLFarGJJua6TLsgDhVnKmo=

through@2, through@^2.3.6, through@^2.3.8, through@~2.3, through@~2.3.4:
through@^2.3.6:
version "2.3.8"
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=

0 comments on commit 79925af

Please sign in to comment.
You can’t perform that action at this time.