Skip to content

Commit 735e840

Browse files
author
Elad Ben-Israel
committed
feat(cli): typescript - yarn run upgrade & upgrade:next
add some commands for upgrading your project
1 parent 7b15e3a commit 735e840

File tree

4 files changed

+40
-29
lines changed

4 files changed

+40
-29
lines changed

packages/cdk8s-cli/templates/typescript-app/.hooks.sscaff.js

+16-11
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,47 @@ const { execSync } = require('child_process');
22
const { readFileSync, symlinkSync, mkdirSync } = require('fs');
33
const path = require('path');
44

5+
const version = require('../../package.json').version;
6+
57
exports.pre = () => {
68
if (process.env.CLI_TEST) {
79
console.error(`CLI_TEST=1`);
810
}
911
};
1012

1113
exports.post = () => {
12-
const deps = [ '@aws-cdk/core', '@aws-cdk/cx-api', 'cdk8s' ];
13-
const devDeps = [ 'cdk8s-cli', '@types/node' ];
14-
15-
deps.forEach(d => installDep(d));
16-
devDeps.forEach(d => installDep(d, true));
14+
installDeps([ '@aws-cdk/core', '@aws-cdk/cx-api', `cdk8s@^${version}` ]);
15+
installDeps([ `cdk8s-cli@^${version}`, '@types/node' ], true);
1716

1817
// build to make sure all is good
1918
execSync('yarn build', { stdio: 'inherit' });
2019

21-
console.log(readFileSync('./help.txt', 'utf-8'));
20+
console.log(readFileSync('./help', 'utf-8'));
2221
};
2322

24-
function installDep(dep, isDev) {
25-
23+
function installDeps(deps, isDev) {
2624
// if we are in a CLI test, install the dependency from the local repo instead
2725
// of from the public registry.
2826
if (process.env.CLI_TEST) {
29-
installLocalDep(dep);
27+
for (const dep of deps) {
28+
installLocalDep(dep);
29+
}
3030
return;
3131
}
3232

3333
const devDep = isDev ? '-D' : '';
34-
execSync(`yarn add ${devDep} ${dep}`, { stdio: 'inherit' });
34+
execSync(`yarn add ${devDep} ${deps.join(' ')}`, { stdio: 'inherit' });
3535
}
3636

37-
function installLocalDep(dep) {
37+
function installLocalDep(depWithVer) {
38+
const dep = depWithVer.split('@')[0];
39+
3840
const pkgfile = require.resolve(`${dep}/package.json`);
3941
const target = path.dirname(pkgfile);
4042
const source = path.join('node_modules', dep);
4143
mkdirSync(path.dirname(source), { recursive: true });
44+
45+
console.error(`symlinking: ${source} => ${target}`);
4246
symlinkSync(target, source);
4347

4448
const pkg = JSON.parse(readFileSync(pkgfile, 'utf-8'));
@@ -49,6 +53,7 @@ function installLocalDep(dep) {
4953
const binsource = path.join(localbin, program);
5054
const bintarget = path.join(target, relpath);
5155

56+
console.error(`symlinking: ${binsource} => ${binsource}`);
5257
symlinkSync(bintarget, binsource);
5358
}
5459
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
========================================================================================================
2+
3+
Your cdk8s typescript project is ready!
4+
5+
cat help print this message
6+
7+
yarn run import import k8s api objects and store them under imports/k8s.ts
8+
yarn compile compile typescript code to javascript
9+
yarn watch watch for changes and compile typescript in the background
10+
yarn test run a very rigorous test suite (tbd)
11+
yarn synth synthesize k8s manifests from charts to dist/ (ready for 'kubectl apply -f')
12+
yarn build all together now: import + compile + test + synth
13+
14+
deploy:
15+
kubectl apply -f dist/*.k8s.yaml
16+
17+
upgrades:
18+
yarn run upgrade upgrade cdk8s modules to latest version
19+
yarn run upgrade:next upgrade cdk8s modules to latest "@next" version (last commit)
20+
21+
========================================================================================================

packages/cdk8s-cli/templates/typescript-app/help.txt

-17
This file was deleted.

packages/cdk8s-cli/templates/typescript-app/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"test": "echo ok",
1212
"synth": "cdk8s synth --app 'node main.js'",
1313
"build": "yarn run import && yarn compile && yarn test && yarn synth",
14-
"watch": "tsc -w"
14+
"watch": "tsc -w",
15+
"upgrade": "yarn upgrade -L cdk8s cdk8s-cli",
16+
"upgrade:next": "yarn upgrade -L cdk8s@next cdk8s-cli@next"
1517
}
1618
}

0 commit comments

Comments
 (0)