-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: macdonst <[email protected]>
- Loading branch information
Showing
5 changed files
with
116 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
module.exports = async function (params) { | ||
let { existsSync, writeFileSync } = require('fs') | ||
let { join, resolve } = require('path') | ||
|
||
let utils = require('../../lib') | ||
let { npmCommands: { initialInstall } } = utils | ||
let error = require('./errors')(params, utils) | ||
let _inventory = require('@architect/inventory') | ||
let c = require('@colors/colors/safe') | ||
|
||
let dest = resolve('.') | ||
|
||
// Error out if folder already exists and it has an arc project already | ||
if (existsSync(dest)) { | ||
let inventory = await _inventory({ cwd: dest }) | ||
let invalid = inventory.inv._project.manifest | ||
if (invalid) return error('project_found') | ||
} | ||
|
||
// write arc file | ||
writeFileSync(join(dest, '.arc'), | ||
`@app | ||
enhance-app | ||
@static | ||
prune true | ||
@plugins | ||
enhance/arc-plugin-enhance | ||
` | ||
) | ||
|
||
const pkgFilePath = join(dest, 'package.json') | ||
if (existsSync(pkgFilePath)) { | ||
const pkgFile = require(join(dest, 'package.json')) | ||
pkgFile.scripts.enhance = 'enhance' | ||
pkgFile.scripts.start = 'npx enhance dev' | ||
pkgFile.devDependencies['@enhance/cli'] = 'latest' | ||
pkgFile.devDependencies['@enhance/types'] = 'latest' | ||
pkgFile.dependencies['@enhance/arc-plugin-enhance'] = 'latest' | ||
|
||
writeFileSync( | ||
pkgFilePath, | ||
JSON.stringify(pkgFile, null, 2), | ||
) | ||
} | ||
else { | ||
writeFileSync( | ||
pkgFilePath, | ||
`{ | ||
"name": "enhance-app", | ||
"version": "0.0.1", | ||
"scripts": { | ||
"start": "npx enhance dev", | ||
"enhance": "enhance" | ||
}, | ||
"devDependencies": { | ||
"@enhance/cli": "latest", | ||
"@enhance/types": "latest" | ||
}, | ||
"dependencies": { | ||
"@enhance/arc-plugin-enhance": "latest" | ||
} | ||
} | ||
` | ||
) | ||
} | ||
|
||
// Need to install enhance/arc-plugin-enhance or 💥 | ||
await initialInstall(params, dest) | ||
|
||
// Success message | ||
console.error(`Project successfully initialized! To get started run: ${c.bold(c.green(`npx enhance dev`))}`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = function error (params, utils) { | ||
return function (err) { | ||
let { lang } = params | ||
let { backtickify, runtimes } = utils | ||
let errors = { | ||
en: { | ||
no_path: 'Project path not found, please run with -p or --path', | ||
project_found: 'Existing Enhance app already found in this directory', | ||
invalid_appname: `Invalid app name`, | ||
invalid_runtime: `Function runtime must be one of: ${backtickify(runtimes)}`, | ||
} | ||
} | ||
return Error(errors[lang][err]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
let names = { en: [ 'init' ] } | ||
let action = require('./action') | ||
|
||
module.exports = { | ||
names, | ||
action, | ||
help: () => { | ||
return { | ||
en: { | ||
usage: [ 'init' ], | ||
description: 'Initialize a new empty Enhance project', | ||
examples: [ | ||
{ | ||
name: 'Create a new project in the current folder', | ||
example: 'npx @enhance/cli init', | ||
}, | ||
] | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters