Skip to content

Commit

Permalink
Update SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
kiootic committed Nov 13, 2019
2 parents 1909cf6 + 681d619 commit 7d3565d
Show file tree
Hide file tree
Showing 48 changed files with 792 additions and 784 deletions.
1 change: 0 additions & 1 deletion .prettierignore

This file was deleted.

4 changes: 1 addition & 3 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"singleQuote": true,
"trailingComma": "es5"
}
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"homepage": "https://skygear.io/",
"dependencies": {
"@babel/polyfill": "^7.4.4",
"@skygear/node-client": "2.0.0-alpha.15",
"@skygear/node-client": "2.0.0-alpha.16",
"@zeit/dockerignore": "0.0.5",
"chalk": "^2.4.2",
"cli-table3": "^0.5.1",
Expand Down
4 changes: 2 additions & 2 deletions src/@types/gunzip-maybe/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare module 'gunzip-maybe' {
import stream = require('stream');
declare module "gunzip-maybe" {
import stream = require("stream");

function gunzip(): stream.Transform;
export = gunzip;
Expand Down
8 changes: 4 additions & 4 deletions src/@types/tar-fs/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare module 'tar-fs' {
import fs = require('fs');
import stream = require('stream');
declare module "tar-fs" {
import fs = require("fs");
import stream = require("stream");

// Replace these return values with the value of tar-stream when it becomes available
export function pack(cwd: string, opts?: PackOptions): stream.Readable;
Expand Down Expand Up @@ -37,7 +37,7 @@ declare module 'tar-fs' {
mode: number;
mtime: Date;
size: number;
type: 'file' | 'directory' | 'link' | 'symlink';
type: "file" | "directory" | "link" | "symlink";
uid: number;
gid: number;
}
Expand Down
32 changes: 16 additions & 16 deletions src/commands/app.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Arguments, createCommand, getCommandGroupHelpMessage } from '../util';
import appCreate from './app/create';
import appList from './app/list';
import appDeploy from './app/deploy';
import appScaffold from './app/scaffold';
import viewUserConfig from './app/viewUserConfig';
import updateUserConfig from './app/updateUserConfig';
import addCollaborator from './app/addCollaborator';
import listCollaborator from './app/listCollaborator';
import removeCollaboartor from './app/removeCollaboartor';
import { Arguments, createCommand, getCommandGroupHelpMessage } from "../util";
import appCreate from "./app/create";
import appList from "./app/list";
import appDeploy from "./app/deploy";
import appScaffold from "./app/scaffold";
import viewUserConfig from "./app/viewUserConfig";
import updateUserConfig from "./app/updateUserConfig";
import addCollaborator from "./app/addCollaborator";
import listCollaborator from "./app/listCollaborator";
import removeCollaboartor from "./app/removeCollaboartor";

const subCommands = [
appCreate,
Expand All @@ -18,19 +18,19 @@ const subCommands = [
updateUserConfig,
addCollaborator,
removeCollaboartor,
listCollaborator
listCollaborator,
];

function run(_argv: Arguments) {
console.log(getCommandGroupHelpMessage('app', subCommands));
console.log(getCommandGroupHelpMessage("app", subCommands));
return Promise.resolve();
}

export default createCommand({
builder: (yargs) => {
builder: yargs => {
return subCommands.reduce((y, cmd) => y.command(cmd as any), yargs);
},
command: 'app',
describe: 'Skycli app commands',
handler: run
command: "app",
describe: "Skycli app commands",
handler: run,
});
28 changes: 14 additions & 14 deletions src/commands/app/addCollaborator.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import chalk from 'chalk';
import chalk from "chalk";

import { Arguments, createCommand } from '../../util';
import { requireApp, requireClusterConfig, requireUser } from '../middleware';
import { cliContainer } from '../../container';
import { Arguments, createCommand } from "../../util";
import { requireApp, requireClusterConfig, requireUser } from "../middleware";
import { cliContainer } from "../../container";

async function run(argv: Arguments) {
const appName = argv.context.app || '';
const appName = argv.context.app || "";
const email = argv.email as string;

if (!email) {
throw new Error('Email is required.');
throw new Error("Email is required.");
}

const invited = await cliContainer.addCollaborator(appName, email);
Expand All @@ -21,18 +21,18 @@ async function run(argv: Arguments) {
}

export default createCommand({
builder: (yargs) => {
builder: yargs => {
return yargs
.middleware(requireClusterConfig)
.middleware(requireUser)
.middleware(requireApp)
.demandOption(['email'])
.option('email', {
type: 'string',
describe: `Developer's email`
.demandOption(["email"])
.option("email", {
type: "string",
describe: `Developer's email`,
});
},
command: 'add-collaborator [email]',
describe: 'Add developer as collaborator by email',
handler: run
command: "add-collaborator [email]",
describe: "Add developer as collaborator by email",
handler: run,
});
68 changes: 34 additions & 34 deletions src/commands/app/create.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import chalk from 'chalk';
import inquirer from 'inquirer';
import chalk from "chalk";
import inquirer from "inquirer";

import { Arguments, createCommand } from '../../util';
import { requireClusterConfig, requireUser } from '../middleware';
import AppScaffoldCommand from './scaffold';
import { cliContainer } from '../../container';
import { Arguments, createCommand } from "../../util";
import { requireClusterConfig, requireUser } from "../middleware";
import AppScaffoldCommand from "./scaffold";
import { cliContainer } from "../../container";

const appNamePrompt: inquirer.Question = {
message: 'What is your app name?',
name: 'app',
type: 'input',
validate: (input) => {
if (input.trim() === '') {
return 'App name is required.';
message: "What is your app name?",
name: "app",
type: "input",
validate: input => {
if (input.trim() === "") {
return "App name is required.";
}
if (!input.match(/^[A-Za-z0-9]+$/i)) {
return 'Invalid app name, only alphabetical letters and numbers are allowed.';
return "Invalid app name, only alphabetical letters and numbers are allowed.";
}
return true;
}
},
};

function ask() {
return inquirer.prompt([appNamePrompt]).then((answers) => {
return inquirer.prompt([appNamePrompt]).then(answers => {
return {
...answers
...answers,
};
});
}
Expand All @@ -33,12 +33,12 @@ function confirmScaffoldApp() {
return inquirer.prompt([
{
message:
'Do you want to scaffold your app now? ' +
'Or you can do it later by `skycli app scaffold` command.\n' +
'Scaffold now?',
name: 'scaffoldNow',
type: 'confirm'
}
"Do you want to scaffold your app now? " +
"Or you can do it later by `skycli app scaffold` command.\n" +
"Scaffold now?",
name: "scaffoldNow",
type: "confirm",
},
]);
}

Expand All @@ -54,7 +54,7 @@ async function run(argv: Arguments) {
}

console.log(chalk`App name: {green ${appName}}.`);
console.log('Creating app...');
console.log("Creating app...");

const payload = await cliContainer.createApp(appName);
const userConfig = payload[1];
Expand All @@ -63,11 +63,11 @@ async function run(argv: Arguments) {

console.log(chalk`Your API endpoint: {green ${endpoint}}.`);
console.log(
chalk`Your API Key: {green ${firstClient ? firstClient.api_key : ''}}.`
chalk`Your API Key: {green ${firstClient ? firstClient.api_key : ""}}.`
);
console.log(chalk`Your Master Key: {green ${userConfig.master_key || ''}}.`);
console.log(chalk`Your Master Key: {green ${userConfig.master_key || ""}}.`);

console.log('Created app successfully! \n');
console.log("Created app successfully! \n");

const answers = await confirmScaffoldApp();
if (!answers.scaffoldNow) {
Expand All @@ -80,21 +80,21 @@ async function run(argv: Arguments) {
return AppScaffoldCommand.execute({
...argv,
app: appName,
dest: '.'
dest: ".",
});
}

export default createCommand({
builder: (yargs) => {
builder: yargs => {
return yargs
.middleware(requireClusterConfig)
.middleware(requireUser)
.option('app', {
desc: 'App name',
type: 'string'
.option("app", {
desc: "App name",
type: "string",
});
},
command: 'create',
describe: 'Create Skygear app',
handler: run
command: "create",
describe: "Create Skygear app",
handler: run,
});
56 changes: 28 additions & 28 deletions src/commands/app/deploy.test.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
import { createFolderToPathsMapForArchive } from './deploy';
import { createFolderToPathsMapForArchive } from "./deploy";

test('createFolderToPathsMapForArchive with template', async () => {
test("createFolderToPathsMapForArchive with template", async () => {
const result = await createFolderToPathsMapForArchive(
{
type: 'http-service',
context: 'fixture/deploy/user_code',
path: '',
port: 8000
type: "http-service",
context: "fixture/deploy/user_code",
path: "",
port: 8000,
},
'fixture/deploy/template'
"fixture/deploy/template"
);

for (const key of Object.keys(result)) {
result[key] = result[key].sort();
}

const expected = {
'fixture/deploy/user_code': ['.skyignore', 'src/index.js'],
'fixture/deploy/template': ['.dockerignore', 'Dockerfile']
"fixture/deploy/user_code": [".skyignore", "src/index.js"],
"fixture/deploy/template": [".dockerignore", "Dockerfile"],
};
expect(expected).toEqual(result);
});

test('createFolderToPathsMapForArchive should not provide .dockerignore with template', async () => {
test("createFolderToPathsMapForArchive should not provide .dockerignore with template", async () => {
await expect(
createFolderToPathsMapForArchive(
{
type: 'http-service',
context: 'fixture/deploy/user_code_with_dockerignore',
path: '',
port: 8000
type: "http-service",
context: "fixture/deploy/user_code_with_dockerignore",
path: "",
port: 8000,
},
'fixture/deploy/template'
"fixture/deploy/template"
)
).rejects.toThrow(
'.dockerignore is reserved file, please remove it from folder fixture/deploy/user_code_with_dockerignore'
".dockerignore is reserved file, please remove it from folder fixture/deploy/user_code_with_dockerignore"
);
});

test('createFolderToPathsMapForArchive without template', async () => {
test("createFolderToPathsMapForArchive without template", async () => {
const result = await createFolderToPathsMapForArchive(
{
type: 'http-service',
context: 'fixture/deploy/user_code_with_dockerignore',
path: '',
type: "http-service",
context: "fixture/deploy/user_code_with_dockerignore",
path: "",
port: 8000,
dockerfile: 'src/Dockerfile'
dockerfile: "src/Dockerfile",
},
null
);
Expand All @@ -56,13 +56,13 @@ test('createFolderToPathsMapForArchive without template', async () => {

// skycli will not read `.skyignore`, if deploying docker
const expected = {
'fixture/deploy/user_code_with_dockerignore': [
'.dockerignore',
'.skyignore',
'skyignored-file',
'src/Dockerfile',
'src/index.js'
]
"fixture/deploy/user_code_with_dockerignore": [
".dockerignore",
".skyignore",
"skyignored-file",
"src/Dockerfile",
"src/index.js",
],
};
expect(expected).toEqual(result);
});
Loading

0 comments on commit 7d3565d

Please sign in to comment.