-
Notifications
You must be signed in to change notification settings - Fork 121
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
build: enable linking charts library to kibana #1164
Merged
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
bd9e935
build: enable linking charts library to kibana
nickofthyme 125e3de
fix: console flag statement
nickofthyme ee62e7a
fix: update target and tsc options
nickofthyme 5b3d6e0
refactor: use fs.promise over promisify
nickofthyme 33fd4d2
fix: promise refactor issues
nickofthyme 6bc3aee
chore: add debug flag and node version error handling
nickofthyme 2a614b8
fix: reject promise for stderrs
nickofthyme a9a93c0
Merge branch 'master' into link-script
nickofthyme b3f8f95
Merge branch 'master' into link-script
nickofthyme 409e5c6
chore: add last updated log
nickofthyme 55f4b5a
fix: build order before linking
nickofthyme 2be206f
Merge branch 'master' into link-script
nickofthyme 5a7ee10
fix: typo and last updated timestamp
nickofthyme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -468,5 +468,11 @@ module.exports = { | |
], | ||
}, | ||
}, | ||
{ | ||
files: ['packages/link_kibana/**/*.js'], | ||
rules: { | ||
'no-console': 0, | ||
}, | ||
}, | ||
], | ||
}; |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"name": "eslint-plugin-elastic-charts", | ||
"description": "Custom elastic-charts lint plugin", | ||
"license": "Apache-2.0", | ||
"version": "1.0.0", | ||
"main": "index.js" | ||
} |
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,22 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
const main = require('./main'); | ||
|
||
void main(); |
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,242 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
const path = require('path'); | ||
|
||
const chalk = require('chalk'); | ||
const inquirer = require('inquirer'); | ||
const ora = require('ora'); | ||
|
||
const { spawnWatch, exec } = require('./process_utils'); | ||
const { replaceModules } = require('./replace_modules'); | ||
const { | ||
getPackageInfo, | ||
getTempDir, | ||
getLinkInfo, | ||
writeLinkInfo, | ||
isLinked, | ||
linkPackage, | ||
unlinkPackage, | ||
} = require('./utils'); | ||
|
||
/** | ||
* This script is used to handling symlinking elastic charts to kibana. | ||
* The cli walks you through the require parameters and runs the build | ||
* in watch mode to facilitate the entire linking process. | ||
* | ||
* NOTE: This does **not** rebuild css files, only typescript files | ||
*/ | ||
module.exports = async () => { | ||
// child processes for cleanup | ||
const cps = []; | ||
const cleanExit = () => { | ||
cps.forEach((cp) => cp && cp.kill()); | ||
process.exit(); // eslint-disable-line unicorn/no-process-exit | ||
}; | ||
process.on('SIGINT', cleanExit); // catch ctrl-c | ||
process.on('SIGTERM', cleanExit); // catch kill | ||
|
||
const echDir = process.cwd(); | ||
const echPackageContent = await getPackageInfo(echDir); | ||
const packageName = echPackageContent.name; | ||
|
||
if (packageName !== '@elastic/charts') { | ||
if (packageName) throw new Error('This script is only designed for use with @elastic/charts'); | ||
throw new Error('No name defined in package.json'); | ||
} | ||
|
||
const tempDir = await getTempDir(echDir, packageName); | ||
const linkInfo = await getLinkInfo(tempDir); | ||
const linkedPackages = ['react', 'react-dom', 'redux', 'react-redux']; | ||
|
||
const { action } = await inquirer.prompt({ | ||
name: 'action', | ||
message: 'Select action', | ||
type: 'list', | ||
default: 'link', | ||
choices: ['Link', 'Unlink', 'Watch mode'], | ||
}); | ||
|
||
if (action === 'Link') { | ||
const { appLinkRelativePath } = await inquirer.prompt({ | ||
name: 'appLinkRelativePath', | ||
message: 'Enter path to applitcation directory to link', | ||
default: '../kibana', | ||
}); | ||
const kibanaPath = path.resolve(echDir, appLinkRelativePath); | ||
const kibanaPackageInfo = await getPackageInfo(kibanaPath); | ||
|
||
if (kibanaPackageInfo.name !== 'kibana') { | ||
console.log(` | ||
Expected app name to be ${chalk.cyan('kibana')}, found ${chalk.cyan(kibanaPackageInfo.name)}. | ||
|
||
to link charts with another application use ${chalk.cyan( | ||
'yarn link', | ||
)} (see https://classic.yarnpkg.com/en/docs/cli/link/) | ||
`); | ||
return; | ||
} | ||
|
||
if (linkInfo.path) { | ||
if (linkInfo.path !== kibanaPath) { | ||
console.log(`${chalk.cyan(packageName)} is already linked to ${linkInfo.path}. Please unlink and try again.`); | ||
} | ||
|
||
if (isLinked(path.join(kibanaPath, 'node_modules', packageName), echDir)) { | ||
ora( | ||
`Selected ${chalk.cyan(kibanaPackageInfo.name)} application already has ${chalk.cyan(packageName)} link`, | ||
).succeed(); | ||
console.log(` | ||
To remove this link run ${chalk.cyan('yarn link:charts')} and select the option to ${chalk.bold.underline( | ||
'Unlink', | ||
)}`); | ||
return; | ||
} | ||
} | ||
|
||
console.log(` | ||
Please ensure kibana is bootstrapped and running: | ||
cd ${kibanaPath} | ||
|
||
${chalk.dim('# start elasticsearch or configure kibana to point at remote elasticsearch cluster')} | ||
yarn es snapshot --license trial --password changeme -E node.attr.hot_node=true | ||
|
||
${chalk.dim('# boostrap and start kibana')} | ||
yarn kbn bootstrap --no-cache | ||
yarn start | ||
`); | ||
await writeLinkInfo(tempDir, { | ||
name: kibanaPackageInfo.name, | ||
path: kibanaPath, | ||
created: new Date(), | ||
}); | ||
const { isReady } = await inquirer.prompt({ | ||
name: 'isReady', | ||
message: `Press ${chalk.italic('Y')} to continue when kibana is running or ${chalk.italic('N')} to cancel.`, | ||
type: 'confirm', | ||
default: true, | ||
}); | ||
|
||
if (!isReady) { | ||
console.log('Please ensure kibana is running before linking charts'); | ||
return; | ||
} | ||
|
||
await linkPackage(echDir, kibanaPath, packageName); | ||
|
||
cps.push( | ||
await spawnWatch( | ||
'yarn build:watch --preserveWatchOutput --pretty --noUnusedLocals false --target ES2018 --noUnusedLocals false ', | ||
packageName, | ||
{ | ||
cwd: echDir, | ||
errorStr: 'error TS', | ||
stopStr: 'Found 0 errors. Watching for file changes', | ||
startStr: 'File change detected. Starting incremental compilation', | ||
onUpdate: () => replaceModules(echDir, kibanaPath, linkedPackages), | ||
}, | ||
), | ||
); | ||
|
||
const kbnSharedPackage = path.join(kibanaPath, 'packages/kbn-ui-shared-deps'); | ||
cps.push( | ||
await spawnWatch('yarn kbn:watch', '@kbn/ui-shared-dep', { | ||
cwd: kbnSharedPackage, | ||
errorStr: 'ERROR', | ||
stopStr: 'webpack completed', | ||
startStr: 'Running webpack compilation', | ||
}), | ||
); | ||
|
||
await writeLinkInfo(tempDir, { | ||
name: kibanaPackageInfo.name, | ||
path: kibanaPath, | ||
created: new Date(), | ||
}); | ||
|
||
console.log(` | ||
Link Successful, please keep this tab running to watch for file changes. | ||
Refresh kibana to see all new file changes, each time files are rebuilt. | ||
When finished end this process and run ${chalk.cyan( | ||
'yarn link:charts', | ||
)} and select the option to ${chalk.bold.underline('Unlink')} to cleanup link changes. | ||
`); | ||
} else { | ||
const kibanaPath = linkInfo.path; | ||
if (!kibanaPath) { | ||
ora(`No links found for ${chalk.cyan(packageName)}`).warn(); | ||
return; | ||
} | ||
|
||
if (action === 'Watch mode') { | ||
cps.push( | ||
await spawnWatch( | ||
'yarn build:watch --preserveWatchOutput --pretty --noUnusedLocals false --target ES2018', | ||
packageName, | ||
{ | ||
cwd: echDir, | ||
errorStr: ': error TS', | ||
stopStr: 'Found 0 errors. Watching for file changes', | ||
startStr: 'File change detected. Starting incremental compilation', | ||
onUpdate: () => replaceModules(echDir, kibanaPath, linkedPackages), | ||
}, | ||
), | ||
); | ||
|
||
const kbnSharedPackage = path.join(kibanaPath, 'packages/kbn-ui-shared-deps'); | ||
cps.push( | ||
await spawnWatch('yarn kbn:watch', '@kbn/ui-shared-dep', { | ||
cwd: kbnSharedPackage, | ||
errorStr: 'ERROR', | ||
stopStr: 'webpack completed', | ||
startStr: 'Running webpack compilation', | ||
}), | ||
); | ||
|
||
return; | ||
} | ||
|
||
await exec('yarn build', `Restoring build ${chalk.dim(packageName)}`, { cwd: echDir, errorStr: ': error TS' }); | ||
const chartsFileRestored = await unlinkPackage(linkInfo.path, packageName); | ||
|
||
await writeLinkInfo(tempDir, {}); | ||
|
||
if (chartsFileRestored) { | ||
try { | ||
const kbnSharedPackage = path.join(kibanaPath, 'packages/kbn-ui-shared-deps'); | ||
await exec('yarn build --dev', `Restoring build ${chalk.dim('@kbn/ui-shared-dep')}`, { | ||
errorStr: 'ERROR', | ||
cwd: kbnSharedPackage, | ||
}); | ||
|
||
console.log(` | ||
Unlink Successful. Kibana has been restored to the pre-linked state. | ||
Please refresh kibana to see restored state.`); | ||
return; | ||
} catch { | ||
// fallthrough | ||
} | ||
} | ||
|
||
console.log(` | ||
Unlink Complete. Kibana was ${chalk.underline('not')} restored to the pre-linked state. Please run ${chalk.cyan( | ||
'yarn kbn bootstrap --no-cache', | ||
)}`); | ||
} | ||
}; |
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,14 @@ | ||
{ | ||
"name": "link-kibana", | ||
"description": "Utility to aid in linking charts to kinana", | ||
"license": "Apache-2.0", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"dependencies": { | ||
"chalk": "^4.1.1", | ||
"change-case": "^4.1.2", | ||
"glob": "^7.1.7", | ||
"inquirer": "^8.0.0", | ||
"ora": "^5.4.0" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo