Skip to content

Commit

Permalink
Format JS
Browse files Browse the repository at this point in the history
  • Loading branch information
lipis committed Sep 28, 2018
1 parent 66606b0 commit 4eeaa6b
Show file tree
Hide file tree
Showing 57 changed files with 940 additions and 746 deletions.
2 changes: 1 addition & 1 deletion benchmarks/markdown/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
plugins: [`gatsby-transformer-remark`],
};
}
18 changes: 11 additions & 7 deletions examples/gatsbygram/scrape.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const bar = new ProgressBar(
mkdirp.sync(`./data/images`)

let posts = []
let userId
let userId

// Write json
const saveJSON = _ =>
Expand All @@ -45,16 +45,17 @@ const getPosts = maxId => {
let url = `https://www.instagram.com/${username}/?__a=1`
let url2 = `https://www.instagram.com/graphql/query/?query_hash=472f257a40c653c64c666ce877d59d2b`

if (maxId) url = url2 + `&variables={"id":"${userId}","first":12,"after":"${maxId}"}`
if (maxId)
url = url2 + `&variables={"id":"${userId}","first":12,"after":"${maxId}"}`

request(url, { encoding: `utf8` }, (err, res, body) => {
if (err) console.log(`error: ${err}`)
if (maxId) {
body = JSON.parse(body).data
body = JSON.parse(body).data
} else {
//This is the first request, lets get the userId
body = JSON.parse(body).graphql
userId = body.user.id
//This is the first request, lets get the userId
body = JSON.parse(body).graphql
userId = body.user.id
}
body.user.edge_owner_to_timeline_media.edges
.filter(({ node: item }) => item[`__typename`] === `GraphImage`)
Expand Down Expand Up @@ -85,7 +86,10 @@ const getPosts = maxId => {
posts.push(item)
})

const lastId = get(body, `user.edge_owner_to_timeline_media.page_info.end_cursor`)
const lastId = get(
body,
`user.edge_owner_to_timeline_media.page_info.end_cursor`
)
if (posts.length < 100 && lastId) getPosts(lastId)
else saveJSON()
})
Expand Down
14 changes: 7 additions & 7 deletions examples/gatsbygram/utils/download-file.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
var fs = require("fs")
var request = require("request")
var fs = require(`fs`)
var request = require(`request`)

module.exports = function(url, dest, cb) {
var file = fs.createWriteStream(dest)
var sendReq = request.get(url)

// verify response code
sendReq.on("response", function(response) {
sendReq.on(`response`, function(response) {
if (response.statusCode !== 200) {
return cb("Response status was " + response.statusCode)
return cb(`Response status was ` + response.statusCode)
}
})

// check for request errors
sendReq.on("error", function(err) {
sendReq.on(`error`, function(err) {
fs.unlink(dest)

if (cb) {
Expand All @@ -23,11 +23,11 @@ module.exports = function(url, dest, cb) {

sendReq.pipe(file)

file.on("finish", function() {
file.on(`finish`, function() {
file.close(cb) // close() is async, call cb after close completes.
})

file.on("error", function(err) {
file.on(`error`, function(err) {
// Handle errors
fs.unlink(dest)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default ({ data }) => {
return (
<div>
<h1>{blogPost.title}</h1>
<div>Posted at: {dateformat(blogPost.createdAt, "fullDate")}</div>
<div>Posted at: {dateformat(blogPost.createdAt, `fullDate`)}</div>
<ReactMarkdown source={blogPost.post} />
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion examples/using-gatsby-source-graphql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default ({ data }) => (
{data.cms.blogPosts.map((blog, i) => (
<a key={i} href={makeBlogPath(blog)}>
<h2>
{dateformat(blog.createdAt, "fullDate")} - {blog.title}
{dateformat(blog.createdAt, `fullDate`)} - {blog.title}
</h2>
</a>
))}
Expand Down
2 changes: 1 addition & 1 deletion examples/using-gatsby-source-graphql/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default ({ data }) => (
{data.cms.blogPosts.map((blog, i) => (
<a key={i} href={makeBlogPath(blog)}>
<h2>
{dateformat(blog.createdAt, "fullDate")} - {blog.title}
{dateformat(blog.createdAt, `fullDate`)} - {blog.title}
</h2>
</a>
))}
Expand Down
41 changes: 20 additions & 21 deletions infrastructure/build-site.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const shell = require("shelljs")
const { spawn } = require("child_process")
const path = require("path")
const GraphQLClient = require("graphql-request").GraphQLClient
const shell = require(`shelljs`)
const { spawn } = require(`child_process`)
const path = require(`path`)
const GraphQLClient = require(`graphql-request`).GraphQLClient
const queue = require(`async/queue`)
const s3 = require("s3")
const s3 = require(`s3`)

const commitId = process.env.CODEBUILD_SOURCE_VERSION

const s3Client = s3.createClient({
s3Options: {
accessKeyId: process.env.accessKeyId,
secretAccessKey: process.env.secretAccessKey,
region: "us-east-1",
endpoint: "s3.us-east-1.amazonaws.com",
region: `us-east-1`,
endpoint: `s3.us-east-1.amazonaws.com`,
},
})

const client = new GraphQLClient(
"https://api.graph.cool/simple/v1/cj8xuo77f0a3a0164y7jketkr",
`https://api.graph.cool/simple/v1/cj8xuo77f0a3a0164y7jketkr`,
{
headers: {
Authorization: `Bearer ${process.env.GRAPHCOOL_TOKEN}`,
Expand Down Expand Up @@ -58,8 +58,8 @@ function createLogLine(logLine, buildId, stderr = false) {
)
}

const getCommitObjectByHash = commitId => {
return client
const getCommitObjectByHash = commitId =>
client
.request(
`
{
Expand All @@ -72,7 +72,6 @@ const getCommitObjectByHash = commitId => {
`
)
.then(result => result.allCommits[0].id)
}

console.log(process.env)

Expand All @@ -82,7 +81,7 @@ var q = queue(function({ logLine, buildId, stderr }, callback) {

const Main = async () => {
if (!process.env.PATH_TO_SITE) {
console.log("Missing required environment variable PATH_TO_SITE")
console.log(`Missing required environment variable PATH_TO_SITE`)
process.exit(1)
}

Expand Down Expand Up @@ -123,23 +122,23 @@ const Main = async () => {
child.on(`error`, err => console.log(`err:`, err))
child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stderr)
child.stdout.on("data", data => {
child.stdout.on(`data`, data => {
// Create new logline
q.push({ logLine: data.toString("utf8"), buildId })
q.push({ logLine: data.toString(`utf8`), buildId })
})
child.stderr.on("data", data => {
child.stderr.on(`data`, data => {
// Create new logline
q.push({ logLine: data.toString("utf8"), buildId, stderr: true })
q.push({ logLine: data.toString(`utf8`), buildId, stderr: true })
})

// On end
child.on("exit", (code, signal) => {
child.on(`exit`, (code, signal) => {
console.log(
"child process exited with " + `code ${code} and signal ${signal}`
`child process exited with ` + `code ${code} and signal ${signal}`
)
// Gatsby build failed
if (code !== 0) {
updateBuild(buildId, "FAILURE")
updateBuild(buildId, `FAILURE`)
process.exit(code)
}
const publicDir = `${pathToSite}/public`
Expand All @@ -158,13 +157,13 @@ const Main = async () => {
)
upload.on(`error`, error => {
console.error(error)
updateBuild(buildId, "FAILURE").then(() => {
updateBuild(buildId, `FAILURE`).then(() => {
process.exit(code)
})
})
// 2. Write final status of build and exit.
upload.on(`end`, () => {
updateBuild(buildId, "SUCCESS").then(() => process.exit())
updateBuild(buildId, `SUCCESS`).then(() => process.exit())
})
})
}
Expand Down
20 changes: 11 additions & 9 deletions infrastructure/functions/onGithubWebhook/handler.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// handler.js

"use strict"
const axios = require("axios")
const Libhoney = require("libhoney").default
const flatten = require("flat")
const GraphQLClient = require("graphql-request").GraphQLClient
const axios = require(`axios`)
const Libhoney = require(`libhoney`).default
const flatten = require(`flat`)
const GraphQLClient = require(`graphql-request`).GraphQLClient

const hny = new Libhoney({
writeKey: process.env.HONEYCOMB_KEY,
dataset: "gatsbyjs-os.lambda.github-webhook",
dataset: `gatsbyjs-os.lambda.github-webhook`,
})

console.log(`env vars`, process.env)

const client = new GraphQLClient(
"https://api.graph.cool/simple/v1/cj8xuo77f0a3a0164y7jketkr",
`https://api.graph.cool/simple/v1/cj8xuo77f0a3a0164y7jketkr`,
{
headers: {
Authorization: `Bearer ${process.env.GRAPHCOOL_TOKEN}`,
Expand Down Expand Up @@ -61,9 +61,11 @@ const createCommit = (commit, branchId) => {
hny.sendNow(Object.assign({ createCommit: true, branchId: branchId }, commit))
return client.request(`
mutation {
createCommit(authorName: "${commit.author.name}",authorUsername: "${commit
.author.username}", authorEmail: "${commit.author
.email}", hash: "${commit.tree_id}", message: "${commit.message}", branchIds: ["${branchId}"]) {
createCommit(authorName: "${commit.author.name}",authorUsername: "${
commit.author.username
}", authorEmail: "${commit.author.email}", hash: "${
commit.tree_id
}", message: "${commit.message}", branchIds: ["${branchId}"]) {
id
}
}
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/gatsby-image/cypress/integration/fixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ describe(`fixed`, () => {
// TODO: figure out why these tests are failing
it(`applies 1x/2x/3x`, () => {
cy.getTestElement(fixedTestId)
.find('picture > source')
.should('have.attr', 'srcset')
.find(`picture > source`)
.should(`have.attr`, `srcset`)
.and(srcset => {
;[`1x`, `2x`, `3x`].forEach(size => {
expect(srcset).contains(size)
Expand Down
8 changes: 3 additions & 5 deletions integration-tests/gatsby-image/cypress/integration/traced.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ describe(`fixed`, () => {
.find(`.gatsby-image-wrapper > img`)
.should(`have.attr`, `src`)
.and(src => {
[
`data:image/svg+xml`,
`fill='white'`
]
.forEach(part => expect(src).to.include(part) )
;[`data:image/svg+xml`, `fill='white'`].forEach(part =>
expect(src).to.include(part)
)
})
})
})
34 changes: 17 additions & 17 deletions integration-tests/gatsby-image/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
const path = require('path');
const path = require(`path`)

module.exports = {
pathPrefix: '/blog',
pathPrefix: `/blog`,
siteMetadata: {
title: 'Gatsby Image e2e',
title: `Gatsby Image e2e`,
},
plugins: [
'gatsby-plugin-react-helmet',
`gatsby-plugin-react-helmet`,
{
resolve: 'gatsby-source-filesystem',
resolve: `gatsby-source-filesystem`,
options: {
name: 'images',
path: path.join(__dirname, 'content/images')
}
name: `images`,
path: path.join(__dirname, `content/images`),
},
},
'gatsby-transformer-sharp',
'gatsby-plugin-sharp',
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
{
resolve: `gatsby-plugin-manifest`,
options: {
name: 'gatsby-starter-default',
short_name: 'starter',
start_url: '/',
background_color: '#663399',
theme_color: '#663399',
display: 'minimal-ui',
icon: 'src/images/gatsby-icon.png', // This path is relative to the root of the site.
name: `gatsby-starter-default`,
short_name: `starter`,
start_url: `/`,
background_color: `#663399`,
theme_color: `#663399`,
display: `minimal-ui`,
icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
},
},
],
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/path-prefix/cypress/integration/navigate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ const { pathPrefix } = require(`../../gatsby-config`)

const withTrailingSlash = url => `${url}/`

describe('navigate', () => {
describe(`navigate`, () => {
beforeEach(() => {
cy.visit(`/`).waitForRouteChange()
})

it(`uses pathPrefix`, () => {
cy.getTestElement('page-2-button-link')
cy.getTestElement(`page-2-button-link`)
.click()
.location(`pathname`)
.should(`eq`, withTrailingSlash(`${pathPrefix}/page-2`))
})

it(`can navigate back after using`, () => {
cy.getTestElement('page-2-button-link')
cy.getTestElement(`page-2-button-link`)
.click()
.getTestElement('index-link')
.getTestElement(`index-link`)
.click()
.location(`pathname`)
.should(`eq`, withTrailingSlash(pathPrefix))
Expand Down
20 changes: 10 additions & 10 deletions integration-tests/path-prefix/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
module.exports = {
pathPrefix: '/blog',
pathPrefix: `/blog`,
siteMetadata: {
title: 'Gatsby Default Starter',
title: `Gatsby Default Starter`,
},
plugins: [
'gatsby-plugin-react-helmet',
`gatsby-plugin-react-helmet`,
{
resolve: `gatsby-plugin-manifest`,
options: {
name: 'gatsby-starter-default',
short_name: 'starter',
start_url: '/',
background_color: '#663399',
theme_color: '#663399',
display: 'minimal-ui',
icon: 'src/images/gatsby-icon.png', // This path is relative to the root of the site.
name: `gatsby-starter-default`,
short_name: `starter`,
start_url: `/`,
background_color: `#663399`,
theme_color: `#663399`,
display: `minimal-ui`,
icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
},
},
],
Expand Down
Loading

0 comments on commit 4eeaa6b

Please sign in to comment.