@adobe/aio-cli-plugin-app 13.3.0 → 14.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,154 +0,0 @@
1
- /*
2
- Copyright 2020 Adobe. All rights reserved.
3
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License. You may obtain a copy
5
- of the License at http://www.apache.org/licenses/LICENSE-2.0
6
-
7
- Unless required by applicable law or agreed to in writing, software distributed under
8
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- OF ANY KIND, either express or implied. See the License for the specific language
10
- governing permissions and limitations under the License.
11
- */
12
-
13
- const path = require('path')
14
- const fs = require('fs-extra')
15
- const cloneDeep = require('lodash.clonedeep')
16
- const utils = require('./app-helper')
17
- const dedent = require('dedent-js')
18
- const rtLib = require('@adobe/aio-lib-runtime')
19
- const rtLibUtils = rtLib.utils
20
- const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:run-dev-local', { provider: 'debug' })
21
-
22
- const {
23
- OW_CONFIG_RUNTIMES_FILE,
24
- OW_JAR_URL, OW_JAR_PATH,
25
- OW_LOCAL_APIHOST,
26
- OW_LOCAL_NAMESPACE,
27
- OW_LOCAL_AUTH,
28
- OW_LOCAL_LOG_FILE
29
- } = require('../lib/owlocal')
30
-
31
- const OW_WAIT_INIT_TIME = 2000
32
- const OW_WAIT_PERIOD_TIME = 500
33
- const OW_TIMEOUT = 60000
34
-
35
- const LOCAL_RUNTIME = {
36
- namespace: OW_LOCAL_NAMESPACE,
37
- auth: OW_LOCAL_AUTH,
38
- apihost: OW_LOCAL_APIHOST
39
- }
40
-
41
- /**
42
- * @typedef {object} RunDevLocalObject
43
- * @property {string} config the modified dev config
44
- * @property {Function} cleanup callback function to cleanup available resources
45
- */
46
-
47
- /**
48
- * @typedef {object} RuntimeCredentials
49
- * @property {string} namespace the runtime namespace
50
- * @property {string} auth the runtime auth key
51
- * @property {string} apihost the runtime apihost
52
- */
53
-
54
- /**
55
- * Checks the system for pre-requisites to run local Openwhisk, then runs it.
56
- *
57
- * @param {object} config the app config
58
- * @param {object} dataDir global config folder to store the ow jar
59
- * @param {Function} [log] function to log application logs
60
- * @param {boolean} [verbose=false] set to true to have verbose logging (openwhisk)
61
- * @returns {RunDevLocalObject} the RunDevLocalObject
62
- */
63
- async function runDevLocal (config, dataDir, log = () => undefined, verbose = false) {
64
- const owJarFile = path.join(dataDir, OW_JAR_PATH)
65
- const devConfig = loadLocalDevConfig(config)
66
-
67
- // take following steps only when we have a backend
68
- log('checking if java is installed...')
69
- if (!await utils.hasJavaCLI()) {
70
- throw new Error('could not find java CLI, please make sure java is installed')
71
- }
72
-
73
- log('checking if docker is installed...')
74
- if (!await utils.hasDockerCLI()) {
75
- throw new Error('could not find docker CLI, please make sure docker is installed')
76
- }
77
-
78
- log('checking if docker is running...')
79
- if (!await utils.isDockerRunning()) {
80
- throw new Error('docker is not running, please make sure to start docker')
81
- }
82
-
83
- if (!fs.existsSync(owJarFile)) {
84
- log(`downloading OpenWhisk standalone jar from ${OW_JAR_URL} to ${owJarFile}, this might take a while... (to be done only once!)`)
85
- await utils.downloadOWJar(OW_JAR_URL, owJarFile)
86
- }
87
-
88
- log('starting local OpenWhisk stack...')
89
- const owLocalLogFile = OW_LOCAL_LOG_FILE || path.join(config.app.dist, 'openwhisk-local.log.txt')
90
- const owExecaOptions = {
91
- stdio: [
92
- null, // stdin
93
- verbose ? fs.openSync(owLocalLogFile, 'w') : null, // stdout
94
- 'inherit' // stderr
95
- ]
96
- }
97
- const res = await utils.runOpenWhiskJar(owJarFile, OW_CONFIG_RUNTIMES_FILE, OW_LOCAL_APIHOST, OW_WAIT_INIT_TIME, OW_WAIT_PERIOD_TIME, OW_TIMEOUT, owExecaOptions)
98
-
99
- log(`writing credentials to tmp wskdebug config '${devConfig.envFile}'`)
100
- await writeLocalEnvFile(devConfig, LOCAL_RUNTIME)
101
-
102
- const cleanup = () => {
103
- aioLogger.debug('stopping local OpenWhisk stack...')
104
- res.proc.kill()
105
-
106
- aioLogger.debug('removing wskdebug tmp .env file...')
107
- if (fs.existsSync(devConfig.envFile)) {
108
- fs.unlinkSync(devConfig.envFile)
109
- }
110
- }
111
-
112
- return {
113
- config: devConfig,
114
- cleanup
115
- }
116
- }
117
-
118
- /**
119
- * @param {object} config the app config
120
- * @param {Function} [log] function to log application logs
121
- * @returns {RunDevLocalObject} the RunDevLocalObject
122
- */
123
- function loadLocalDevConfig (config, log) {
124
- const devConfig = cloneDeep(config)
125
- devConfig.envFile = path.join(config.app.dist, '.env.local')
126
- log && log('setting local openwhisk credentials...')
127
- devConfig.ow = { ...devConfig.ow, ...LOCAL_RUNTIME }
128
- return devConfig
129
- }
130
-
131
- /**
132
- * Writes the local debugging .env file
133
- *
134
- * @param {object} appConfig the app config
135
- * @param {RuntimeCredentials} runtimeCredentials the runtime credentials
136
- */
137
- async function writeLocalEnvFile (appConfig, runtimeCredentials) {
138
- const { root, envFile } = appConfig
139
- const { dist } = appConfig.app
140
- const { namespace, auth, apihost } = runtimeCredentials
141
-
142
- fs.ensureDirSync(dist)
143
- const envFilePath = rtLibUtils._absApp(root, envFile)
144
-
145
- await fs.outputFile(envFilePath, dedent(`
146
- # This file is auto-generated, do not edit.
147
- # The items below are temporary credentials for local debugging
148
- OW_NAMESPACE=${namespace}
149
- OW_AUTH=${auth}
150
- OW_APIHOST=${apihost}
151
- `))
152
- }
153
-
154
- module.exports = { runLocalRuntime: runDevLocal, loadLocalDevConfig }
package/src/lib/vscode.js DELETED
@@ -1,85 +0,0 @@
1
- /*
2
- Copyright 2020 Adobe. All rights reserved.
3
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License. You may obtain a copy
5
- of the License at http://www.apache.org/licenses/LICENSE-2.0
6
-
7
- Unless required by applicable law or agreed to in writing, software distributed under
8
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- OF ANY KIND, either express or implied. See the License for the specific language
10
- governing permissions and limitations under the License.
11
- */
12
-
13
- const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:vscode', { provider: 'debug' })
14
- const rtLibUtils = require('@adobe/aio-lib-runtime').utils
15
- const fs = require('fs-extra')
16
- const path = require('path')
17
- const yeoman = require('yeoman-environment')
18
- const generators = require('@adobe/generator-aio-app')
19
-
20
- const LAUNCH_JSON_FILE = '.vscode/launch.json'
21
- const LAUNCH_JSON_FILE_BACKUP = '.vscode/launch.json.save'
22
-
23
- /** @private */
24
- function files (config) {
25
- return () => ({
26
- backupFile: rtLibUtils._absApp(config.root, LAUNCH_JSON_FILE_BACKUP),
27
- mainFile: rtLibUtils._absApp(config.root, LAUNCH_JSON_FILE)
28
- })
29
- }
30
-
31
- /** @private */
32
- function update (config) {
33
- const _files = files(config)
34
- return async (props) => {
35
- const { backupFile, mainFile } = _files()
36
-
37
- fs.ensureDirSync(path.dirname(mainFile))
38
- if (fs.existsSync(mainFile)) {
39
- if (!fs.existsSync(backupFile)) {
40
- fs.moveSync(mainFile, backupFile)
41
- }
42
- }
43
-
44
- const env = yeoman.createEnv()
45
- // by default yeoman runs the install, we control installation from the app plugin
46
- env.options = { skipInstall: true }
47
- const gen = env.instantiate(generators['add-vscode-config'], {
48
- options: {
49
- 'app-config': config,
50
- 'env-file': config.envFile,
51
- 'frontend-url': props.frontEndUrl,
52
- 'skip-prompt': true
53
- }
54
- })
55
- await env.runGenerator(gen)
56
- }
57
- }
58
-
59
- /** @private */
60
- function cleanup (config) {
61
- const _files = files(config)
62
- return () => {
63
- const { backupFile, mainFile } = _files()
64
-
65
- if (fs.existsSync(mainFile) && !fs.existsSync(backupFile)) {
66
- aioLogger.debug(`removing ${mainFile}...`)
67
- const vscodeDir = path.dirname(mainFile)
68
- fs.unlinkSync(mainFile)
69
- if (fs.readdirSync(vscodeDir).length === 0) {
70
- fs.rmdirSync(vscodeDir)
71
- }
72
- }
73
-
74
- if (fs.existsSync(backupFile)) {
75
- aioLogger.debug(`restoring previous ${mainFile}`)
76
- fs.moveSync(backupFile, mainFile, { overwrite: true })
77
- }
78
- }
79
- }
80
-
81
- module.exports = (config) => ({
82
- files: files(config),
83
- update: update(config),
84
- cleanup: cleanup(config)
85
- })