Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] Migrate storybook dependencies #165

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
"boxen": "^1.1.0",
"chalk": "^1.1.3",
"eslint": "^4.6.1",
"eslint-config-sanity": "^3.0.1",
"eslint-plugin-import": "^2.3.0",
"eslint-plugin-react": "^7.0.1",
"eslint-config-sanity": "^3.1.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-react": "^7.4.0",
"glob": "^7.1.2",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/check/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@sanity/generate-help-url": "^0.113.7",
"@sanity/resolver": "^0.113.7",
"chalk": "^1.1.3",
"fs-promise": "^2.0.0",
"fs-extra": "^4.0.2",
"in-publish": "^2.0.0",
"promise-props-recursive": "^1.0.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/check/src/bin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
/* eslint-disable no-console, no-process-env, no-process-exit */
const path = require('path')
const fsp = require('fs-promise')
const fse = require('fs-extra')
const chalk = require('chalk')
const publish = require('in-publish')
const sanityCheck = require('./sanityCheck')
Expand Down Expand Up @@ -39,7 +39,7 @@ if (showVersion) {
process.exit()
}

fsp.readJson(manifestDir)
fse.readJson(manifestDir)
.catch(err => {
console.error(chalk.red(
`${tag} Failed to read "${manifestDir}":\n${err.message}`
Expand Down
8 changes: 4 additions & 4 deletions packages/@sanity/check/src/sanityCheck.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path')
const fsp = require('fs-promise')
const fse = require('fs-extra')
const promiseProps = require('promise-props-recursive')
const generateHelpUrl = require('@sanity/generate-help-url')
const resolveParts = require('@sanity/resolver').resolveParts
Expand Down Expand Up @@ -56,7 +56,7 @@ function throwOnErrors(results, options) {
function getFolderContents(dirs) {
return promiseProps(dirs.reduce((folders, dir) => {
if (!folders[dir]) {
folders[dir] = fsp.readdir(dir).catch(() => [])
folders[dir] = fse.readdir(dir).catch(() => [])
}
return folders
}, {}))
Expand Down Expand Up @@ -106,7 +106,7 @@ function checkImplementationMsg(impl) {
}

function isFileOrDirectoryWithIndex(impl) {
return fsp.stat(impl.path).then(stats => {
return fse.stat(impl.path).then(stats => {
return stats.isDirectory()
? directoryHasIndex(impl)
: true
Expand All @@ -117,7 +117,7 @@ function isFileOrDirectoryWithIndex(impl) {
}

function directoryHasIndex(impl) {
return fsp.readdir(impl.path).then(dirContent => {
return fse.readdir(impl.path).then(dirContent => {
return includes(dirContent, 'index.js')
? true
: new Error(
Expand Down
4 changes: 1 addition & 3 deletions packages/@sanity/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@
"debug": "^2.6.3",
"deep-sort-object": "^1.0.1",
"execa": "^0.6.0",
"fs-promise": "^2.0.0",
"fs-extra": "^4.0.2",
"git-user-info": "^1.0.1",
"gitconfiglocal": "^2.0.1",
"github-url-to-object": "^3.0.0",
"inquirer": "^2.0.0",
"is-git-url": "^0.2.3",
"leven": "^2.0.0",
"lodash": "^4.17.4",
"minimist": "^1.2.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/@sanity/cli/src/actions/login/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path'
import http from 'http'
import open from 'opn'
import chalk from 'chalk'
import fsp from 'fs-promise'
import fse from 'fs-extra'
import {parseJson} from '@sanity/util/lib/safeJson'
import debug from '../../debug'
import getUserConfig from '../../util/getUserConfig'
Expand Down Expand Up @@ -107,7 +107,7 @@ function loginFlow({output, provider, apiClient}, resolve, reject) {
// Serve the "login successful"-page
debug('Token exchange complete, serving page')
res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8', Connection: 'close'})
const successPage = await fsp.readFile(path.join(__dirname, 'loginResponse.html'), 'utf8')
const successPage = await fse.readFile(path.join(__dirname, 'loginResponse.html'), 'utf8')
res.end(successPage, () => {
req.connection.unref()

Expand All @@ -130,7 +130,7 @@ function loginFlow({output, provider, apiClient}, resolve, reject) {

async function onTokenExchangeError(err, req, res) {
res.writeHead(500, {'Content-Type': 'text/html; charset=utf-8', Connection: 'close'})
const errorPage = await fsp.readFile(path.join(__dirname, 'loginError.html'), 'utf8')
const errorPage = await fse.readFile(path.join(__dirname, 'loginError.html'), 'utf8')

res.end(errorPage.replace(/%error%/g, err.message), 'utf8', () => {
debug('Error page served')
Expand Down
6 changes: 3 additions & 3 deletions packages/@sanity/cli/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import 'babel-polyfill'
import path from 'path'
import chalk from 'chalk'
import fsp from 'fs-promise'
import fse from 'fs-extra'
import resolveFrom from 'resolve-from'
import updateNotifier from 'update-notifier'
import {resolveProjectRoot} from '@sanity/resolver'
Expand Down Expand Up @@ -94,7 +94,7 @@ function checkCwdPresence() {
}

function hasDevMode() {
return fsp.existsSync(path.join(__dirname, '..', 'src'))
return fse.existsSync(path.join(__dirname, '..', 'src'))
}

function resolveRootDir(cwd) {
Expand All @@ -118,7 +118,7 @@ function getCoreModulePath(workDir) {
return pkgPath
}

const hasManifest = fsp.existsSync(path.join(workDir, 'sanity.json'))
const hasManifest = fse.existsSync(path.join(workDir, 'sanity.json'))
if (hasManifest && process.argv.indexOf('install') === -1) {
console.warn(chalk.yellow([
'@sanity/core not installed in current project',
Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/cli/src/commands/debug/printDebugInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import os from 'os'
import util from 'util'
import path from 'path'
import osenv from 'osenv'
import fsp from 'fs-promise'
import fse from 'fs-extra'
import xdgBasedir from 'xdg-basedir'
import promiseProps from 'promise-props-recursive'
import {pick, omit} from 'lodash'
Expand Down Expand Up @@ -111,7 +111,7 @@ async function gatherProjectConfigInfo(context) {
const configLocation = path.join(workDir, 'sanity.json')

try {
const config = await fsp.readJson(configLocation)
const config = await fse.readJson(configLocation)
if (!config.api || !config.api.projectId) {
throw new Error(`Project config (${configLocation}) does not contain required "api.projectId" key`)
}
Expand Down
10 changes: 5 additions & 5 deletions packages/@sanity/cli/src/commands/init/bootstrapPlugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path'
import fsp from 'fs-promise'
import fse from 'fs-extra'
import {partialRight} from 'lodash'
import promiseProps from 'promise-props-recursive'
import {
Expand Down Expand Up @@ -29,7 +29,7 @@ export default function bootstrapPlugin(data, opts = {}) {
})
}

return fsp.ensureDir(targetPath).then(() => promiseProps(collect))
return fse.ensureDir(targetPath).then(() => promiseProps(collect))
.then(templates => {
if (!data.createConfig) {
return templates
Expand Down Expand Up @@ -61,7 +61,7 @@ export default function bootstrapPlugin(data, opts = {}) {
return
}

fsp.ensureDir(path.join(targetPath, 'src')).then(() =>
fse.ensureDir(path.join(targetPath, 'src')).then(() =>
writeIfNotExists(
path.join(targetPath, 'src', 'MyComponent.js'),
"import React from 'react'\n\n"
Expand All @@ -73,11 +73,11 @@ export default function bootstrapPlugin(data, opts = {}) {
}

function readTemplate(file) {
return fsp.readFile(path.join(__dirname, 'templates', file))
return fse.readFile(path.join(__dirname, 'templates', file))
}

function writeFileIfNotExists(filePath, content, output) {
return fsp.writeFile(filePath, content, {flag: 'wx'})
return fse.writeFile(filePath, content, {flag: 'wx'})
.catch(err => {
if (err.code === 'EEXIST') {
output.print(`[WARN] File "${filePath}" already exists, skipping`)
Expand Down
6 changes: 3 additions & 3 deletions packages/@sanity/cli/src/commands/init/bootstrapTemplate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path'
import fsp from 'fs-promise'
import fse from 'fs-extra'
import {union} from 'lodash'
import debug from '../../debug'
import versionRanges from '../../versionRanges'
Expand All @@ -25,7 +25,7 @@ export default async (opts, context) => {
// Copy template files
debug('Copying files from template "%s" to "%s"', opts.template, outputDir)
let spinner = output.spinner('Bootstrapping files from template').start()
await fsp.copy(sourceDir, outputDir, {
await fse.copy(sourceDir, outputDir, {
overwrite: false,
errorOnExist: true
})
Expand Down Expand Up @@ -81,7 +81,7 @@ export default async (opts, context) => {
async function writeFileIfNotExists(fileName, content) {
const filePath = path.join(outputDir, fileName)
try {
await fsp.writeFile(filePath, content, {flag: 'wx'})
await fse.writeFile(filePath, content, {flag: 'wx'})
} catch (err) {
if (err.code === 'EEXIST') {
output.print(`[WARN] File "${filePath}" already exists, skipping`)
Expand Down
9 changes: 0 additions & 9 deletions packages/@sanity/cli/src/commands/init/createManifest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import ghUrl from 'github-url-to-object'
import sortObject from 'deep-sort-object'
import versionRanges from '../../versionRanges'

Expand Down Expand Up @@ -37,14 +36,6 @@ function getCommonManifest(data) {
}
}

const gh = (data.gitRemote || '').includes('github.com/') && ghUrl(data.gitRemote)
if (gh) {
Object.assign(pkg, {
homepage: `${gh.https_url}#readme`,
bugs: {url: `${gh.https_url}/issues`}
})
}

return pkg
}

Expand Down
43 changes: 13 additions & 30 deletions packages/@sanity/cli/src/commands/init/gatherInput.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os from 'os'
import path from 'path'
import fsp from 'fs-promise'
import fse from 'fs-extra'
import validateNpmPackageName from 'validate-npm-package-name'
import isGitUrl from 'is-git-url'

export default async function gatherInput(prompt, defaults, options = {}) {
const {isPlugin, workDir, sluggedName} = options
Expand All @@ -20,36 +19,20 @@ export default async function gatherInput(prompt, defaults, options = {}) {
return validForNewPackages ? true : errors[0]
}
})
}

answers.description = await prompt.single({
type: 'input',
message: `${thing} description:`,
default: defaults.description
})

answers.gitRemote = await prompt.single({
type: 'input',
message: 'Git repository URL:',
default: defaults.gitRemote,
validate: url => {
return (url ? isGitUrl(url) : true) || 'Invalid git url'
}
})

answers.author = await prompt.single({
type: 'input',
message: 'Author:',
default: defaults.author
})
answers.description = await prompt.single({
type: 'input',
message: `${thing} description:`,
default: defaults.description
})
}

answers.license = await prompt.single({
type: 'input',
message: 'License:',
default: 'UNLICENSED'
})
answers.description = answers.description || defaults.description
answers.gitRemote = defaults.gitRemote
answers.author = defaults.author
answers.license = 'UNLICENSED'

const workDirIsEmpty = (await fsp.readdir(workDir)).length === 0
const workDirIsEmpty = (await fse.readdir(workDir)).length === 0

if (!isPlugin) {
answers.outputPath = await prompt.single({
Expand Down Expand Up @@ -96,7 +79,7 @@ async function validateEmptyPath(dir) {
}

function pathIsEmpty(dir) {
return fsp.readdir(dir)
return fse.readdir(dir)
.then(content => content.length === 0)
.catch(err => {
if (err.code === 'ENOENT') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path'
import fsp from 'fs-promise'
import fse from 'fs-extra'
import semver from 'semver'
import {padStart} from 'lodash'
import readLocalManifest from '@sanity/util/lib/readLocalManifest'
Expand Down Expand Up @@ -57,14 +57,14 @@ export default async (args, context) => {

// Write new `package.json`
const manifestPath = path.join(context.workDir, 'package.json')
await fsp.writeJson(manifestPath, newManifest, {spaces: 2})
await fse.writeJson(manifestPath, newManifest, {spaces: 2})

// Delete `yarn.lock` to ensure we're getting new modules
// (workaround, shouldnt be needed in the future)
const yarnLockPath = path.join(context.workDir, 'yarn.lock')
const hasLockFile = fsp.existsSync(yarnLockPath) // eslint-disable-line no-sync
const hasLockFile = fse.existsSync(yarnLockPath) // eslint-disable-line no-sync
if (hasLockFile) {
await fsp.unlink(yarnLockPath)
await fse.unlink(yarnLockPath)
}

// Run `yarn install`
Expand Down
8 changes: 4 additions & 4 deletions packages/@sanity/cli/src/scripts/package-yarn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
import path from 'path'
import fsp from 'fs-promise'
import fse from 'fs-extra'
import simpleGet from 'simple-get'

const version = '1.0.2'
Expand All @@ -24,7 +24,7 @@ function download() {
throw err
}

res.pipe(fsp.createWriteStream(destination, writeFlags).on('close', writeHeader))
res.pipe(fse.createWriteStream(destination, writeFlags).on('close', writeHeader))
})
}

Expand All @@ -35,7 +35,7 @@ async function writeHeader() {
const wrappedLicense = `/*\n${commented}*/`

console.log('[package-yarn] Reading bundle')
const bundle = await fsp.readFile(destination, writeFlags)
const bundle = await fse.readFile(destination, writeFlags)
if (bundle[0] !== '#' && bundle[1] !== '!') {
throw new Error('[package-yarn] Expected bundle to start with a shebang (#!), but it did not')
}
Expand All @@ -44,7 +44,7 @@ async function writeHeader() {
const pkgDate = (new Date()).toISOString().substr(0, 10)
const versionString = `/* yarn v${version} - packaged ${pkgDate} */`
const licensed = bundle.replace(/^(#!.*\n)/, `$1${versionString}\n${wrappedLicense}\n\n`)
await fsp.writeFile(destination, licensed, writeFlags)
await fse.writeFile(destination, licensed, writeFlags)
}

download()
6 changes: 3 additions & 3 deletions packages/@sanity/cli/src/util/getProjectDefaults.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fsp from 'fs-promise'
import path from 'path'
import fse from 'fs-extra'
import gitConfigLocal from 'gitconfiglocal'
import gitUserInfo from 'git-user-info'
import promiseProps from 'promise-props-recursive'
Expand All @@ -25,7 +25,7 @@ export default (workDir, {isPlugin, context}) => {

const getGitConfig = thenify(gitConfigLocal)
function resolveGitRemote(cwd) {
return fsp.stat(path.join(cwd, '.git'))
return fse.stat(path.join(cwd, '.git'))
.then(() => getGitConfig(cwd))
.then(cfg => cfg.remote && cfg.remote.origin && cfg.remote.origin.url)
.catch(() => null)
Expand Down Expand Up @@ -65,7 +65,7 @@ async function getProjectDescription({isSanityRoot, isPlugin, outputDir}) {
// Try to grab a project description from a standard Github-generated readme
try {
const readmePath = path.join(outputDir, 'README.md')
const readme = await fsp.readFile(readmePath, {encoding: 'utf8'})
const readme = await fse.readFile(readmePath, {encoding: 'utf8'})
const match = readme.match(/^# .*?\n+(\w.*?)(?:$|\n)/)
return ((match && match[1]) || '').replace(/\.$/, '') || ''
} catch (err) {
Expand Down