@architect/create
Advanced tools
Comparing version 4.1.4 to 4.2.0-RC.0
@@ -5,2 +5,15 @@ # Architect Create changelog | ||
## [4.2.0] 2023-04-10 | ||
### Added | ||
- Added support for create plugin API, namely: `create.register`, `create.handlers` | ||
### Changed | ||
- Updated dependencies | ||
--- | ||
## [4.1.4] 2023-01-18 | ||
@@ -7,0 +20,0 @@ |
{ | ||
"name": "@architect/create", | ||
"version": "4.1.4", | ||
"version": "4.2.0-RC.0", | ||
"description": "Idempotently initialize Architect projects", | ||
@@ -26,7 +26,7 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"@architect/inventory": "~3.4.0", | ||
"@architect/utils": "~3.1.2", | ||
"@architect/inventory": "~3.5.0-RC.1", | ||
"@architect/utils": "~3.1.6", | ||
"chalk": "4.1.2", | ||
"lambda-runtimes": "~1.1.3", | ||
"minimist": "~1.2.7" | ||
"lambda-runtimes": "~1.1.4", | ||
"minimist": "~1.2.8" | ||
}, | ||
@@ -36,4 +36,4 @@ "devDependencies": { | ||
"cross-env": "~7.0.3", | ||
"eslint": "~8.32.0", | ||
"fs-extra": "~11.1.0", | ||
"eslint": "~8.38.0", | ||
"fs-extra": "~11.1.1", | ||
"nyc": "~15.1.0", | ||
@@ -40,0 +40,0 @@ "proxyquire": "^2.1.3", |
@@ -69,4 +69,4 @@ let { sep } = require('path') | ||
// Print banner | ||
if (standalone) { | ||
// Print banner | ||
banner(version) | ||
@@ -100,3 +100,3 @@ } | ||
writeFunctions({ ...params, dirs, inventory }) | ||
await writeFunctions({ ...params, dirs, inventory }) | ||
writeStatic({ folder, inventory }) | ||
@@ -103,0 +103,0 @@ |
let writeTemplate = require('./write-template') | ||
let writeCode = require('./write-code') | ||
module.exports = function writeFunctions (params) { | ||
module.exports = async function writeFunctions (params) { | ||
let { dirs, inventory } = params | ||
@@ -10,12 +10,13 @@ let { lambdasBySrcDir } = inventory.inv | ||
dirs.forEach(({ pragma, src }) => { | ||
for (let dir of dirs) { | ||
let { pragma, src } = dir | ||
let lambda = lambdasBySrcDir[src] | ||
let template = templates?.[pragma] | ||
if (template) { | ||
writeTemplate(template, lambda) | ||
writeTemplate(lambda, template) | ||
} | ||
else { | ||
writeCode(lambda) | ||
await writeCode(lambda, inventory) | ||
} | ||
}) | ||
} | ||
} |
@@ -1,4 +0,5 @@ | ||
let { sep } = require('path') | ||
let { writeFileSync } = require('fs') | ||
let { aliases } = require('lambda-runtimes') | ||
let { dirname, join, sep } = require('path') | ||
let { existsSync, mkdirSync, writeFileSync } = require('fs') | ||
let { aliases, runtimes } = require('lambda-runtimes') | ||
let { deepFrozenCopy } = require('@architect/utils') | ||
let http = require('./templates/http') | ||
@@ -11,3 +12,5 @@ let events = require('./templates/events') | ||
module.exports = function writeCode (lambda) { | ||
module.exports = async function writeCode (lambda, inventory) { | ||
let { _project, plugins } = inventory.inv | ||
let { src, build, handlerFile, handlerModuleSystem, config, body } = lambda | ||
@@ -25,23 +28,60 @@ let { runtime, runtimeConfig } = config | ||
// TODO This is a bit hacky and needs some improvement; custom runtime plugins should write proper boilerplate code (see: `body` prop from Arc 9.x plugins) | ||
let configuredRuntime = runtimeConfig?.baseRuntime || aliases[runtime] || runtime | ||
let run | ||
if (configuredRuntime.startsWith('deno')) run = 'deno' | ||
if (configuredRuntime.startsWith('node')) run = 'node' | ||
if (configuredRuntime.startsWith('python')) run = 'python' | ||
if (configuredRuntime.startsWith('ruby')) run = 'ruby' | ||
if (!run) throw ReferenceError(`Valid runtime not found: ${configuredRuntime}`) | ||
// Create handlers for registered + custom runtimes | ||
let registered = plugins?._methods?.create?.register?.find(r => { | ||
// We find the exact specified runtime, easy | ||
if (r.includes(runtime)) return true | ||
// Otherwise, we have to search the array for aliased values that match the runtime, ew | ||
return r.find(i => runtimes[aliases[i]]?.includes(runtime)) | ||
}) | ||
if (_project.customRuntimes?.runtimes?.includes(runtime) || registered) { | ||
let runtimePlugin = _project.customRuntimes.runtimePlugins[runtime] || registered._plugin | ||
let createMethod = plugins[runtimePlugin]?.create?.handlers | ||
if (!createMethod) { | ||
throw ReferenceError(`No create.handlers method found for custom runtime plugin '${runtime}' (${runtimePlugin})`) | ||
} | ||
// Make sure the handler directory exists should plugin authors be relying on it | ||
mkdirSync(lambda.src, { recursive: true }) | ||
let types = { http, events, queues, ws, scheduled, 'tables-streams': tablesStreams, customLambdas: events } | ||
if (!body && pragma === 'http') { | ||
body = handlerModuleSystem | ||
? types[pragma][run][handlerModuleSystem](handler) | ||
: types[pragma][run](handler) | ||
let frozen = deepFrozenCopy(inventory) | ||
let { arc } = frozen.inv._project | ||
let args = { arc, inventory: frozen, lambda: deepFrozenCopy(lambda) } | ||
let result = await createMethod(args) | ||
if (result) { | ||
let files = Array.isArray(result) ? result : [ result ] | ||
for (let file of files) { | ||
let { filename, body } = file | ||
if (!filename || !body) throw ReferenceError(`Cannot create handler file without 'filename' and 'body' properties (${runtimePlugin})`) | ||
let path = join(src, filename) | ||
let dir = dirname(path) | ||
// Don't assume they requested the file to be in the root of the handler, eh? | ||
if (!existsSync(dir)) { | ||
mkdirSync(dir, { recursive: true }) | ||
} | ||
writeFileSync(path, body) | ||
} | ||
} | ||
} | ||
else if (!body) { | ||
body = handlerModuleSystem | ||
? types[pragma][run][handlerModuleSystem] | ||
: types[pragma][run] | ||
// Create handlers for built-in runtimes | ||
else { | ||
let configuredRuntime = runtimeConfig?.baseRuntime || aliases[runtime] || runtime | ||
let run | ||
if (configuredRuntime.startsWith('deno')) run = 'deno' | ||
if (configuredRuntime.startsWith('node')) run = 'node' | ||
if (configuredRuntime.startsWith('python')) run = 'python' | ||
if (configuredRuntime.startsWith('ruby')) run = 'ruby' | ||
if (!run) throw ReferenceError(`Valid runtime not found: ${configuredRuntime}`) | ||
let types = { http, events, queues, ws, scheduled, 'tables-streams': tablesStreams, customLambdas: events } | ||
if (!body && pragma === 'http') { | ||
body = handlerModuleSystem | ||
? types[pragma][run][handlerModuleSystem](handler) | ||
: types[pragma][run](handler) | ||
} | ||
else if (!body) { | ||
body = handlerModuleSystem | ||
? types[pragma][run][handlerModuleSystem] | ||
: types[pragma][run] | ||
} | ||
writeFileSync(filepath, body) | ||
} | ||
writeFileSync(filepath, body) | ||
} |
@@ -5,3 +5,3 @@ let { existsSync, readFileSync, writeFileSync } = require('fs') | ||
module.exports = function writeTemplate (template, lambda) { | ||
module.exports = function writeTemplate (lambda, template) { | ||
let { src, build, handlerFile } = lambda | ||
@@ -8,0 +8,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58295
1036
2
+ Added@architect/asap@6.0.6(transitive)
+ Added@architect/inventory@3.5.7(transitive)
- Removed@architect/asap@5.1.1(transitive)
- Removed@architect/inventory@3.4.3(transitive)
Updated@architect/utils@~3.1.6
Updatedlambda-runtimes@~1.1.4
Updatedminimist@~1.2.8