Skip to content

Commit 902c0a1

Browse files
committed
Merge branch 'develop'
2 parents 6f19589 + 6220c42 commit 902c0a1

File tree

12 files changed

+241
-134
lines changed

12 files changed

+241
-134
lines changed

.github/workflows/github-release.yaml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/version-bump.yaml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Bump Package Versions and Tag
1+
name: Bump Package Versions, Tag and Draft Release
22

33
on:
44
push:
@@ -33,10 +33,24 @@ jobs:
3333
- name: Install Dependencies
3434
run: yarn --immutable
3535
- name: Bump and Tag
36-
run: yarn bump
36+
run: |
37+
yarn bump
38+
echo "::set-output name=TAG_REF::`git describe --abbrev=0`"
39+
id: bump_tag
3740
- name: Merge Master -> Develop
3841
run: |
3942
git fetch
4043
git checkout develop
4144
git merge --no-ff master -m "Merge version bump into develop"
42-
git push origin master develop --follow-tags
45+
git push origin master develop --follow-tags
46+
- name: Create Draft Release
47+
id: create_release
48+
uses: actions/create-release@v1
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
with:
52+
tag_name: ${{ steps.bump_tag.outputs.TAG_REF }}
53+
release_name: Release ${{ steps.bump_tag.outputs.TAG_REF }}
54+
body: See CHANGELOG.md for changes
55+
draft: true
56+
prerelease: false

packages/base/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"eventemitter3": "^4.0.7",
2121
"execa": "^4.0.3",
2222
"get-port": "^5.1.1",
23+
"inquirer": "^7.3.3",
2324
"keypress": "^0.2.1",
2425
"listr": "^0.14.3",
2526
"multimatch": "^5.0.0",
@@ -67,6 +68,11 @@
6768
"main": "lib/index.js",
6869
"oclif": {
6970
"commands": "./lib/commands",
71+
"topics": {
72+
"make": { "description": "Commands to make new projects and assets." },
73+
"deploy": { "description": "Plugin commands to deploy on supported providers. E.g. `$ nitric plugins:install @nitric/plugin-aws`" },
74+
"down": { "description": "Plugin commands to tear down deployments on supported providers. E.g. `$ nitric plugins:install @nitric/plugin-aws`" }
75+
},
7076
"bin": "nitric",
7177
"plugins": [
7278
"@oclif/plugin-help",

packages/base/src/commands/build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ export function createBuildTasks(stack: NitricStack, directory: string, provider
3232
}
3333

3434
/**
35-
* Cloudless CLI build command
35+
* Nitric CLI build command
3636
* Will use docker to build the users application as a docker image
3737
* ready to be executed on a CaaS
3838
*/
3939
export default class Build extends Command {
40-
static description = 'Builds a nitric project';
40+
static description = 'Builds a project';
4141

4242
static examples = [`$ nitric build .`];
4343

packages/base/src/commands/create.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Command, flags } from '@oclif/command';
22

33
/**
4-
* Cloudless CLI create command
4+
* Nitric CLI create command
55
*/
66
export default class Create extends Command {
7-
static description = 'Creates a new cloudless project';
7+
static description = 'Creates a new project';
88

9-
static examples = [`$ cloudless create my-cloudless-project`];
9+
static examples = [`$ nitric create my-project`];
1010

1111
static flags = {
1212
help: flags.help({ char: 'h' }),
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { Command, flags } from '@oclif/command';
2+
import { wrapTaskForListr } from '@nitric/cli-common';
3+
import { MakeProject, MakeFunctionTask } from '../../tasks/make';
4+
import Listr, { ListrTask } from 'listr';
5+
import inquirer from 'inquirer';
6+
7+
const projectNameRegex = /^[a-z]+(-[a-z]+)*$/g;
8+
9+
export default class Project extends Command {
10+
static description = 'Creates a new Nitric project';
11+
12+
static examples = [`$ nitric make:function .`];
13+
14+
static flags = {
15+
help: flags.help({ char: 'h' }),
16+
force: flags.boolean(),
17+
};
18+
19+
static args = [
20+
{
21+
name: 'name',
22+
required: true,
23+
description: 'the name of the new project to create',
24+
},
25+
];
26+
27+
async run(): Promise<void> {
28+
const { args, flags } = this.parse(Project);
29+
const { name } = args;
30+
const { force } = flags;
31+
let commands: ListrTask[] = [];
32+
33+
let { example }: { example: string } = await inquirer.prompt([
34+
{
35+
name: 'example',
36+
message: 'Include an example function?',
37+
type: 'list',
38+
choices: [{ name: 'nodejs12' }, { name: 'python37' }, { name: 'none' }],
39+
},
40+
]);
41+
42+
if (!name.match(projectNameRegex)) {
43+
throw new Error(`project name must be formatted as ${projectNameRegex}`);
44+
}
45+
46+
if (example !== 'none') {
47+
const { functionName } = await inquirer.prompt([
48+
{
49+
name: 'functionName',
50+
message: 'Name for the example function?',
51+
type: 'input',
52+
},
53+
]);
54+
55+
// Create an example function to go along with the project
56+
commands = [
57+
wrapTaskForListr(
58+
new MakeFunctionTask({
59+
template: example,
60+
dir: `./${name}/`,
61+
name: functionName,
62+
}),
63+
),
64+
];
65+
}
66+
67+
await new Listr([wrapTaskForListr(new MakeProject(name, force)), ...commands]).run();
68+
}
69+
}

packages/base/src/commands/run.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ async function runContainers(stack: NitricStack, portStart: number, directory: s
7878
}
7979

8080
/**
81-
* Cloudless CLI run command
81+
* Nitric CLI run command
8282
* Extends the build command to run the built docker images locally for testing.
8383
*/
8484
export default class Run extends Command {
85-
static description = 'Builds and runs a cloudless project';
85+
static description = 'Builds and runs a project';
8686

87-
static examples = [`$ cloudless run .`];
87+
static examples = [`$ nitric run .`];
8888

8989
static args = [...Build.args];
9090

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { templateFunctionPath } from '../../common/paths';
2+
import { NitricRuntime, readNitricDescriptor, writeNitricDescriptor, Task } from '@nitric/cli-common';
3+
import { isTemplateAvailable } from '../../utils';
4+
5+
import tar from 'tar-fs';
6+
import path from 'path';
7+
import streamToPromise from 'stream-to-promise';
8+
import fs from 'fs';
9+
10+
interface MakeFunctionTaskOpts {
11+
template: string;
12+
dir: string;
13+
file?: string;
14+
name: string;
15+
}
16+
17+
export class MakeFunctionTask extends Task<void> {
18+
private functionName: string;
19+
private template: string;
20+
private file: string;
21+
private dir: string;
22+
23+
constructor({ template, name, file = './nitric.yaml', dir }: MakeFunctionTaskOpts) {
24+
super(`Making Function ${name}`);
25+
this.template = template;
26+
this.functionName = name;
27+
this.file = file;
28+
this.dir = dir;
29+
}
30+
31+
private async makeFunction(): Promise<string> {
32+
//TODO: validate inputs
33+
// Validate template is installed/exists
34+
//TODO: in future, we should attempt to download/install the template if possible
35+
if (!isTemplateAvailable(this.template)) {
36+
throw new Error(`Template ${this.template} is not available.`);
37+
}
38+
this.update(`${this.template} template available locally`);
39+
40+
const inPath = templateFunctionPath(this.template);
41+
//TODO: should probably do something to make sure the file exists
42+
// Make a copy of the function template, using the new name in the output directory
43+
const outPath = path.join(this.dir, this.functionName);
44+
if (fs.existsSync(outPath)) {
45+
throw new Error(`Function directory already exists: ${this.functionName}`);
46+
}
47+
48+
const outStream = tar.extract(outPath);
49+
tar.pack(inPath).pipe(outStream);
50+
this.update('creating function...');
51+
await streamToPromise(outStream);
52+
53+
return `Created function ${this.functionName} based on template ${this.template}`;
54+
}
55+
56+
async do(): Promise<void> {
57+
this.update('Checking stack descriptor');
58+
const nitricFile = path.join(this.dir, this.file);
59+
const stack = readNitricDescriptor(nitricFile);
60+
61+
const { functions = [] } = stack;
62+
63+
const funcDirName = this.functionName
64+
.toLowerCase()
65+
.replace(/ /g, '-')
66+
.replace(/[^-a-z\d]/g, '');
67+
68+
if (functions.find((func) => func.name === this.functionName) !== undefined) {
69+
throw new Error(`Function ${this.functionName} already defined in ${this.file}`);
70+
}
71+
72+
this.update('Start Make');
73+
74+
await this.makeFunction();
75+
//then
76+
77+
const functionFolder = path.join(this.dir, funcDirName);
78+
const nitricFileDir = path.dirname(nitricFile);
79+
80+
this.update(`Updating ${this.file}`);
81+
82+
stack.functions = [
83+
...functions,
84+
{
85+
name: this.functionName,
86+
path: path.relative(nitricFileDir, functionFolder),
87+
runtime: this.template as NitricRuntime,
88+
},
89+
];
90+
writeNitricDescriptor(stack, nitricFile);
91+
92+
this.update(`Updated ${this.file}`);
93+
}
94+
}

packages/base/src/tasks/make/index.ts

Lines changed: 2 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,2 @@
1-
import { templateFunctionPath } from '../../common/paths';
2-
import { isTemplateAvailable } from '../../utils';
3-
import { readNitricDescriptor, writeNitricDescriptor, NitricRuntime, Task } from '@nitric/cli-common';
4-
import tar from 'tar-fs';
5-
import path from 'path';
6-
import streamToPromise from 'stream-to-promise';
7-
import fs from 'fs';
8-
interface MakeFunctionTaskOpts {
9-
template: string;
10-
directory: string;
11-
file: string;
12-
name: string;
13-
}
14-
15-
export class MakeFunctionTask extends Task<string> {
16-
private functionName: string;
17-
private template: string;
18-
private file: string;
19-
private directory: string;
20-
21-
constructor({ template, name, file, directory }: MakeFunctionTaskOpts) {
22-
super(`Making Function ${name}`);
23-
this.template = template;
24-
this.functionName = name;
25-
this.file = file;
26-
this.directory = directory;
27-
}
28-
29-
private async makeFunction(): Promise<string> {
30-
const { directory, template, functionName } = this;
31-
//TODO: validate inputs
32-
// Validate template is installed/exists
33-
//TODO: in future, we should attempt to download/install the template if possible
34-
if (!isTemplateAvailable(template)) {
35-
throw new Error(`Template ${template} is not available.`);
36-
}
37-
this.update(`${template} template available locally`);
38-
39-
const inPath = templateFunctionPath(template);
40-
//TODO: should probably do something to make sure the file exists
41-
// Make a copy of the function template, using the new name in the output directory
42-
const outPath = path.join(directory, functionName);
43-
if (fs.existsSync(outPath)) {
44-
throw new Error(`Function directory already exists: ${functionName}`);
45-
}
46-
47-
const outStream = tar.extract(outPath);
48-
tar.pack(inPath).pipe(outStream);
49-
this.update('creating function...');
50-
await streamToPromise(outStream);
51-
52-
return `Created function ${functionName} based on template ${template}`;
53-
}
54-
55-
async do(): Promise<string> {
56-
const { file, directory, functionName } = this;
57-
58-
this.update('Checking stack descriptor');
59-
const nitricFile = path.join(directory, file);
60-
const stack = readNitricDescriptor(nitricFile);
61-
62-
const { functions = [] } = stack;
63-
64-
const functionDirectoryName = this.functionName
65-
.toLowerCase()
66-
.replace(/ /g, '-')
67-
.replace(/[^-a-z\d]/g, '');
68-
69-
if (functions.find((func) => func.name === functionName) !== undefined) {
70-
throw new Error(`Function ${functionName} already defined in ${file}`);
71-
}
72-
73-
this.update('Start Make');
74-
75-
await this.makeFunction();
76-
//then
77-
78-
const functionFolder = path.join(directory, functionDirectoryName);
79-
const nitricFileDirectory = path.dirname(nitricFile);
80-
81-
this.update(`Updating ${file}`);
82-
83-
stack.functions = [
84-
...functions,
85-
{
86-
name: this.functionName,
87-
path: path.relative(nitricFileDirectory, functionFolder),
88-
runtime: this.template as NitricRuntime,
89-
},
90-
];
91-
writeNitricDescriptor(stack, nitricFile);
92-
93-
this.update(`Updated ${file}`);
94-
return `Updated ${file}`;
95-
}
96-
}
1+
export * from './function';
2+
export * from './project';

0 commit comments

Comments
 (0)