Skip to content
Permalink
Browse files

feat: sync with tools

  • Loading branch information...
dariocravero committed Jun 21, 2019
1 parent fef400d commit 86b7df54b37a0a47f0c84f2806a6b79d159567a0
Showing with 50 additions and 166 deletions.
  1. +38 −2 cli.js
  2. +7 −4 ensure-flow.js
  3. +0 −73 hack-migration.js
  4. +1 −1 package.json
  5. +2 −1 process-files.js
  6. +2 −85 watch.js
40 cli.js
@@ -8,13 +8,17 @@ import path from 'path'
import pkg from './package.json'
import updateNotifier from 'update-notifier'
import watch from './watch.js'

let wait = time => new Promise(resolve => setTimeout(resolve, time))

;(async function() {
let {
_,
as,
clean,
help,
local,
tools,
track,
watch: shouldWatch,
verbose,
@@ -23,19 +27,24 @@ import watch from './watch.js'
alias: {
help: 'h',
},
booleans: ['clean', 'help', 'track', 'watch', 'version'],
booleans: ['clean', 'help', 'track', 'tools', 'watch', 'version'],

default: {
as: 'react-dom',
clean: false,
local: 'en',
tools: true,
track: false,
verbose: true,
version: false,
watch: false,
},
})

if (!shouldWatch && tools) {
tools = false
}

track = track === 'true'

if (help) {
@@ -46,6 +55,8 @@ import watch from './watch.js'
react-native
--clean clean the autogenerated .view.js files
--local default local language, defaults to English (en)
--tools use with Views Tools, defauls to true when
--watch is enabled, otherwise defaults to false
--track enable UI tracking, defaults to false
--verbose defaults to true
--version print the version
@@ -92,9 +103,33 @@ import watch from './watch.js'

console.log(
`\nWill morph files at "${chalk.green(input)}" as "${chalk.green(as)}" ${
track ? 'with tracking' : 'without tracking'
tools ? 'with Views Tools' : 'without Views Tools'
}`
)

if (!tools) {
console.log(
chalk.bgRed(' ')
)
console.log()
console.log(`🚨 You're missing out!!!`)
console.log(
chalk.bold(
'🚀 Views Tools can help you find product market\n fit before you run out of money.'
)
)
console.log()
console.log(
'✨ Find out how 👉',
chalk.bold(chalk.green('https://views.tools'))
)
console.log()
console.log(
chalk.bgRed(' ')
)
await wait(15000)
}

console.log(chalk.yellow('A'), '= Added')
console.log(chalk.green('M'), `= Morphed`)
console.log(chalk.blue('X'), `= Deleted`)
@@ -105,6 +140,7 @@ import watch from './watch.js'
local,
once: !shouldWatch,
src: input,
tools,
track,
verbose,
})
@@ -25,7 +25,7 @@ function getTopStory(flow) {
}
}

let makeFlow = ({ viewsById, viewsToFiles }) => {
let makeFlow = ({ tools, viewsById, viewsToFiles }) => {
let flowMap = new Map()
let flowMapStr = []

@@ -76,6 +76,7 @@ let makeFlow = ({ viewsById, viewsToFiles }) => {
// https://github.com/viewstools/morph/blob/master/ensure-flow.js
import React, { useCallback, useContext, useEffect, useState } from 'react'
${tools ? "import useTools from './useTools.js'" : ''}
let GetFlow = React.createContext(new Set())
let SetFlow = React.createContext(() => {})
@@ -157,6 +158,7 @@ function getNextFlow(key, state) {
export function Flow(props) {
let [state, setState] = useState(props.initialState)
${tools ? 'let sendToTools = useTools(setState)' : ''}
let setFlow = useCallback(
id => {
@@ -178,8 +180,9 @@ export function Flow(props) {
useEffect(() => {
if (process.env.NODE_ENV === 'development') {
console.debug('flow', state)
${tools ? "sendToTools({ type: 'client:flow', flow: [...state] })" : ''}
}
}, [state])
}, [state${tools ? ', sendToTools' : ''}])
return (
<SetFlow.Provider value={setFlow}>
@@ -193,10 +196,10 @@ Flow.defaultProps = {
}`
}

export default function ensureFlow({ src, viewsById, viewsToFiles }) {
export default function ensureFlow({ src, tools, viewsById, viewsToFiles }) {
return fs.writeFile(
path.join(src, 'useFlow.js'),
prettier.format(makeFlow({ viewsById, viewsToFiles }), {
prettier.format(makeFlow({ tools, viewsById, viewsToFiles }), {
parser: 'babel',
singleQuote: true,
trailingComma: 'es5',

This file was deleted.

@@ -1,6 +1,6 @@
{
"name": "@viewstools/morph",
"version": "19.5.1",
"version": "19.6.0",
"description": "Views language morpher",
"main": "index.js",
"type": "module",
@@ -16,6 +16,7 @@ export default ({
as,
customFonts,
local,
tools,
track,
src,
verbose,
@@ -82,7 +83,7 @@ export default ({
})

await Promise.all([
ensureFlow({ src, viewsById, viewsToFiles }),
ensureFlow({ src, tools, viewsById, viewsToFiles }),
ensureIsBefore({ src }),
ensureIsMedia({ src }),
])
@@ -1,4 +1,3 @@
// import { exec } from 'child_process'
import {
getFilesView,
getFilesViewLogic,
@@ -14,22 +13,13 @@ import {
} from './watch-files.js'
import makeProcessFiles from './process-files.js'
import chalk from 'chalk'
// import debounce from 'debounce'
// import ensureLocalContainer from './ensure-local-container.js'
// import ensureTrackContext from './ensure-track-context.js'
// import getLatestVersion from 'latest-version'
// import hasYarn from 'has-yarn'
// import maybeMorph from './maybe-morph.js'
// import readPkgUp from 'read-pkg-up'
// import toPascalCase from 'to-pascal-case'

// import hackMigration from './hack-migration.js'

export default async function watch({
as = 'react-dom',
local = 'en',
once = false,
src,
tools = false,
track = false,
verbose = true,
}) {
@@ -41,6 +31,7 @@ export default async function watch({
as,
customFonts,
local,
tools,
track,
src,
verbose,
@@ -91,12 +82,6 @@ export default async function watch({
}
}

// hackMigration({
// src,
// viewsById,
// viewsToFiles,
// })

if (once) return

watchFilesView({
@@ -135,71 +120,3 @@ export default async function watch({
viewsToFiles,
})
}

// let maybeUpdateExternalDependencies = debounce(async function() {
// let pkg = await readPkgUp(src)

// if (!pkg.pkg) return

// if (!pkg.pkg.dependencies) {
// pkg.pkg.dependencies = {}
// }

// let cwd = path.dirname(pkg.path)
// let shouldUpdate = false

// for (let dep of instance.externalDependencies) {
// if (!(dep in pkg.pkg.dependencies)) {
// let version = await getLatestVersion(dep)
// pkg.pkg.dependencies[dep] = `^${version}`

// console.log(`⚙️ installing Views dependency ${dep} v${version}`)
// shouldUpdate = true
// }
// }

// if (shouldUpdate) {
// await fs.writeFile(pkg.path, JSON.stringify(pkg.pkg, null, 2))
// exec(hasYarn(cwd) ? 'yarn' : 'npm install')
// }
// }, 100)

// let maybeUpdateLocal = supported => {
// if (local) {
// if (supported) {
// supported.forEach(lang => {
// if (!instance.localSupported.includes(lang)) {
// instance.localSupported.push(lang)
// }
// })
// }

// if (instance.localSupported.length > 1) {
// ensureLocalContainer({
// as,
// file: path.join(src, instance.localContainer),
// fileGetInitialLanguage: path.join(
// src,
// instance.localContainerGetInitialLanguage
// ),
// supported: instance.localSupported,
// })
// }
// }
// }

// if (local) {
// instance.localContainer = 'LocalContainer.js'
// instance.localContainerGetInitialLanguage = 'get-initial-language.js'
// instance.localSupported = [local]

// maybeUpdateLocal()
// }

// if (track) {
// instance.trackContext = 'TrackContext.js'

// ensureTrackContext({
// file: path.join(src, instance.trackContext),
// })
// }

0 comments on commit 86b7df5

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