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

Add @sandbox-startup preferences support #538

Merged
merged 5 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,22 @@

## [-] 2021-01-01

### Added

- Added `@sandbox-startup` preferences support, fixes #1032; thanks @rbethel!


### Changed

- Deprecated the wonky and sometimes broken `@sandbox startup` setting (in favor of the above `@sandbox-startup` pragma)
- Make passing options object to Sandbox service methods, uh, optional
- The startup icon is now a Unicode heart


### Fixed

- Fixed false positive dependency warnings when Lambda treeshaking encounters a `shared` or `views` directory with its own package.json file and dependencies
- Fixed false positive dependency warnings when Lambda treeshaking encounters a `shared` or `views` directory with its own package.json file and dependencies; thanks @exalted
- Fixed optional log suppression on a couple startup prints; fixes #1045, thanks @mikemaccana!

---

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@architect/sandbox",
"version": "3.3.3",
"version": "3.3.4-RC.0",
"description": "Architect dev server: run full Architect projects locally & offline",
"main": "src/index.js",
"scripts": {
Expand All @@ -27,9 +27,9 @@
"@architect/asap": "~3.13.8",
"@architect/create": "~1.3.2",
"@architect/hydrate": "~1.9.0",
"@architect/inventory": "~1.2.1",
"@architect/inventory": "~1.2.2-RC.0",
"@architect/parser": "~3.0.1",
"@architect/utils": "~2.0.2",
"@architect/utils": "~2.0.4",
"@begin/hashid": "~1.0.0",
"aws-sdk": "~2.712.0",
"body-parser": "~1.19.0",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ npx arc sandbox

Sandbox is designed to be integrated into your application's test suite. In most cases you'll only need to make use of `sandbox.start()` and `sandbox.end()`. However, individual Sandbox services can also be individually started and stopped. ([See below](#individual-sandbox-services).)

All methods must be passed an options object that may containing the following parameters:
Methods may be passed an options object containing the following parameters:
- `port` - **String** - Manually specify HTTP port
- Defaults to `3333`
- `quiet` - **Boolean** - Disables (most) logging
Expand Down
8 changes: 3 additions & 5 deletions src/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = function createHttpServer (inventory) {

// Start the HTTP server
app.start = function start (options, callback) {
let { all, port, quiet, symlink = true, update } = options
let { all, port, symlink = true, update } = options

// Set up ports and HTTP-specific env vars
let { httpPort } = getPorts(port)
Expand Down Expand Up @@ -113,10 +113,8 @@ module.exports = function createHttpServer (inventory) {
function _started (err) {
if (err) callback(err)
else {
if (!quiet) {
let link = chalk.green.bold.underline(`http://localhost:${httpPort}\n`)
console.log(`\n ${link}`)
}
let link = chalk.green.bold.underline(`http://localhost:${httpPort}\n`)
update.raw(`\n ${link}`)
let msg = 'HTTP successfully started'
callback(null, msg)
}
Expand Down
2 changes: 1 addition & 1 deletion src/sandbox/_service-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = function serviceFactory (params) {
if (t('http')) init = _http
if (t('tables')) init = _tables
return {
start: function (options, callback) {
start: function (options = {}, callback) {
// Set up promise if there's no callback
let promise
if (!callback) {
Expand Down
15 changes: 7 additions & 8 deletions src/sandbox/_startup-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@ module.exports = function startupScripts (params, callback) {
let { preferences: prefs } = inventory.inv._project

if (prefs && prefs.sandbox && prefs.sandbox.startup) {
update.warn('The @sandbox scripts setting has been deprecated, please use the @sandbox-startup pragma')
callback()
}
else if (prefs && prefs['sandbox-startup']) {
let now = Date.now()
// let ARC_INV = JSON.stringify(inventory.inv) // TODO enable soon once Inventory settles
let ARC_RAW = JSON.stringify(inventory.inv._project.arc)
update.status('Running startup scripts')
let ops = Object.entries(prefs.sandbox.startup).map(([ cmd, args ]) => {
let ops = prefs['sandbox-startup'].map(cmd => {
return function (callback) {
if (!Array.isArray(args)) {
callback(Error(`Sandbox startup scripts must have at least one argument (or comment): ${args}`))
return
}
let command = `${cmd} ${args.join(' ')}`
let env = { /* ARC_INV, */ ARC_RAW, ...process.env }
exec(command, { env }, function (err, stdout, stderr) {
exec(cmd, { env }, function (err, stdout, stderr) {
if (err) callback(err)
else {
stdout = stdout ? stdout.toString() : ''
stderr = stderr ? stderr.toString() : ''
let output = `${stdout + stderr}`.split('\n').filter(Boolean)
update.status(command, ...output)
update.status(cmd, ...output)
callback()
}
})
Expand Down
17 changes: 7 additions & 10 deletions src/sandbox/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = function _start (params, callback) {
inventory,
// Settings
options,
quiet = false,
symlink = true,
// Everything else
update,
Expand Down Expand Up @@ -86,15 +85,13 @@ module.exports = function _start (params, callback) {
// Print startup time
function _ready (callback) {
let finish = Date.now()
if (!quiet) {
update.done(`Started in ${finish - start}ms`)
let isWin = process.platform.startsWith('win')
let ready = isWin
? chars.done
: chalk.green.dim('✈︎')
let readyMsg = chalk.white('Local environment ready!')
console.log(`${ready} ${readyMsg}\n`)
}
update.done(`Started in ${finish - start}ms`)
let isWin = process.platform.startsWith('win')
let ready = isWin
? chars.done
: chalk.green.dim('❤︎')
let readyMsg = chalk.white('Local environment ready!')
update.raw(`${ready} ${readyMsg}\n`)
callback()
},

Expand Down