Browse Source

Remember the configuration again

master
Leo Lamprecht 8 years ago
parent
commit
98a654ab67
  1. 13
      src/describe-project.js
  2. 12
      src/now.js
  3. 7
      src/resolvers/fs.js
  4. 13
      src/serverless/builders/nodejs.js

13
src/describe-project.js

@ -1,5 +1,8 @@
// Native
const { join, basename } = require('path')
const { exists, stat, readFile } = require('fs-extra-promise')
// Packages
const { existsSync, stat, readFile } = require('fs-extra-promise')
const describeProject = async path => {
let nowJSON = null
@ -14,13 +17,13 @@ const describeProject = async path => {
const nowJSONPath = join(path, 'now.json')
if (await exists(nowJSONPath)) {
if (existsSync(nowJSONPath)) {
nowJSON = JSON.parse(await readFile(nowJSONPath))
}
const packageJSONPath = join(path, 'package.json')
if (await exists(packageJSONPath)) {
if (existsSync(packageJSONPath)) {
packageJSON = JSON.parse(await readFile(packageJSONPath))
}
@ -42,7 +45,7 @@ const describeProject = async path => {
// npm has a convention that `npm start`, if not defined,
// will invoke `node server.js`
const hasServerJSFile = await exists(join(path, 'server.js'))
const hasServerJSFile = existsSync(join(path, 'server.js'))
// we support explicit definition of nodejs as a type, or we
// guess it based on `package.json` or
@ -67,7 +70,7 @@ const describeProject = async path => {
type: nowJSON.type,
nowJSON
}
} else if (await exists(join(path, 'main.go'))) {
} else if (existsSync(join(path, 'main.go'))) {
return {
name: getName(path, nowJSON),
description: getDescription(nowJSON),

12
src/now.js

@ -7,7 +7,7 @@ const { join } = require('path')
// Packages
const debug = require('debug')('now:main')
const { exists } = require('fs-extra-promise')
const { existsSync } = require('fs-extra-promise')
const mkdirp = require('mkdirp-promise')
const mri = require('mri')
@ -63,7 +63,7 @@ const main = async (argv_): Promise<number> => {
let nowDirExists
try {
nowDirExists = await exists(NOW_DIR)
nowDirExists = existsSync(NOW_DIR)
} catch (err) {
console.error(
error(
@ -92,7 +92,7 @@ const main = async (argv_): Promise<number> => {
let configExists
try {
configExists = await exists(NOW_CONFIG_PATH)
configExists = existsSync(NOW_CONFIG_PATH)
} catch (err) {
console.error(
error(
@ -151,7 +151,7 @@ const main = async (argv_): Promise<number> => {
let authConfigExists
try {
authConfigExists = await exists(NOW_AUTH_CONFIG_PATH)
authConfigExists = existsSync(NOW_AUTH_CONFIG_PATH)
} catch (err) {
console.error(
error(
@ -281,7 +281,7 @@ const main = async (argv_): Promise<number> => {
if (targetOrSubcommand && targetOrSubcommand in providers) {
debug('user supplied a known provider')
const targetPath = join(process.cwd(), targetOrSubcommand)
const targetPathExists = await exists(targetPath)
const targetPathExists = existsSync(targetPath)
if (targetPathExists) {
console.error(
@ -339,7 +339,7 @@ const main = async (argv_): Promise<number> => {
// we check if we are deploying something
if (targetOrSubcommand) {
const targetPath = join(process.cwd(), targetOrSubcommand)
const targetPathExists = await exists(targetPath)
const targetPathExists = existsSync(targetPath)
const subcommandExists =
GLOBAL_COMMANDS.has(targetOrSubcommand) ||

7
src/resolvers/fs.js

@ -1,9 +1,12 @@
const { exists } = require('fs-extra-promise')
// Native
const { resolve } = require('path')
// Packages
const { existsSync } = require('fs-extra-promise')
const fsResolver = async (param, { cwd = process.cwd() } = {}) => {
const resolved = resolve(cwd, param)
if (await exists(resolved)) {
if (existsSync(resolved)) {
return resolved
} else {
return null

13
src/serverless/builders/nodejs.js

@ -1,12 +1,15 @@
// Native
const { tmpdir } = require('os')
const { join } = require('path')
const { mkdir, stat, link, exists, readdir } = require('fs-extra-promise')
const uid = require('uid-promise')
const { exec: exec_ } = require('child_process')
const exec = require('util').promisify(exec_)
// Packages
const { mkdir, stat, link, existsSync, readdir } = require('fs-extra-promise')
const uid = require('uid-promise')
const { toBuffer } = require('convert-stream')
const archiver = require('archiver')
const debug = require('debug')('now:serverless:builders:nodejs')
const exec = require('util').promisify(exec_)
const nodejsBuilder = async (dir, desc, { overrides = {} } = {}) => {
const files = await readdir(dir)
@ -32,9 +35,9 @@ const nodejsBuilder = async (dir, desc, { overrides = {} } = {}) => {
if (desc.packageJSON) {
let buildCommand = ''
if (await exists(join(targetPath, 'package-lock.json'))) {
if (existsSync(join(targetPath, 'package-lock.json'))) {
buildCommand = 'npm install'
} else if (await exists(join(targetPath, 'yarn.lock'))) {
} else if (existsSync(join(targetPath, 'yarn.lock'))) {
buildCommand = 'yarn install'
} else {
buildCommand = 'npm install'

Loading…
Cancel
Save