Skip to content

Commit d8635a8

Browse files
authored
Merge pull request #26 from raisely/qa-fixes
Qa fixes
2 parents 482474b + 81a6e8d commit d8635a8

20 files changed

Lines changed: 787 additions & 778 deletions

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ insert_final_newline = true
88

99
# Matches multiple files with brace expansion notation
1010
# Set default charset
11-
[*.{js,jsx,html,sass,less,jade,pug,json,css}]
11+
[*.{js,jsx,html,scss,sass,less,jade,pug,json,css}]
1212
charset = utf-8
1313
indent_style = tab
1414
indent_size = 4

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11

2+
# 1.7.0
3+
- Now requires node v14+ LTS (esm no longer required)
4+
- Added better command-line experience (more logs)
5+
- Updated commander.js
6+
- Implemented dynamic imports for commands (faster, only load modules when needed for each command)
7+
- Applied code formatting to match internal development standards
8+
29
# 1.6.5
310

411
- Fixed win32 filesystem handling

bin/raisely.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#!/usr/bin/env node
22

3-
// require = require("esm")(module);
4-
// require("../src/cli.js").cli(process.argv);
5-
import { cli } from "../src/cli.js";
3+
import { cli } from '../src/cli.js';
64
cli(process.argv);

package.json

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@raisely/cli",
3-
"version": "1.6.5",
3+
"version": "1.7.0",
44
"description": "Raisely CLI for local development",
55
"main": "./src/cli.js",
66
"type": "module",
@@ -10,6 +10,9 @@
1010
"scripts": {
1111
"test": "echo \"Error: no test specified\" && exit 1"
1212
},
13+
"engines": {
14+
"node": ">=14"
15+
},
1316
"author": "Raisely",
1417
"license": "SEE LICENSE IN LICENSE.md",
1518
"dependencies": {
@@ -18,13 +21,11 @@
1821
"@babel/preset-env": "^7.16.11",
1922
"@babel/preset-react": "^7.16.7",
2023
"chalk": "^2.4.2",
21-
"commander": "^2.20.0",
22-
"esm": "^3.2.25",
24+
"commander": "^9.2.0",
2325
"express": "^4.17.3",
2426
"folder-hash": "^4.0.2",
2527
"glob": "^7.1.6",
2628
"glob-promise": "^3.4.0",
27-
"global": "^4.4.0",
2829
"http-proxy-middleware": "^2.0.4",
2930
"inquirer": "^6.3.1",
3031
"jwt-decode": "^3.0.0-beta.2",
@@ -35,7 +36,9 @@
3536
"open": "^8.4.0",
3637
"ora": "^3.4.0"
3738
},
38-
"devDependencies": {},
39+
"devDependencies": {
40+
"prettier": "^2.6.2"
41+
},
3942
"repository": {
4043
"type": "git",
4144
"url": "git+https://github.com/raisely/cli.git"
@@ -47,5 +50,14 @@
4750
"bugs": {
4851
"url": "https://github.com/raisely/cli/issues"
4952
},
50-
"homepage": "https://github.com/raisely/cli#readme"
53+
"homepage": "https://github.com/raisely/cli#readme",
54+
"prettier": {
55+
"trailingComma": "es5",
56+
"singleQuote": true,
57+
"useTabs": true,
58+
"tabWidth": 4,
59+
"arrowParens": "always",
60+
"quoteProps": "consistent",
61+
"bracketSpacing": true
62+
}
5163
}

src/actions/api.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import fetch from "node-fetch";
2-
import https from "https";
3-
import { loadConfig, defaults } from "../config.js";
1+
import fetch from 'node-fetch';
2+
import https from 'https';
3+
import { loadConfig, defaults } from '../config.js';
44

55
const devHttpsAgent = new https.Agent({
66
rejectUnauthorized: false,
@@ -15,7 +15,7 @@ function getResponseContentType(response) {
1515
export default async function api(options) {
1616
const config = await loadConfig({ allowEmpty: true });
1717
const isJson =
18-
!options.path.includes(".js") && !options.path.includes(".css");
18+
!options.path.includes('.js') && !options.path.includes('.css');
1919

2020
const fetchUrl = `${config.apiUrl}/v3${options.path}`;
2121

@@ -25,17 +25,17 @@ export default async function api(options) {
2525
headers: {
2626
...(isJson
2727
? {
28-
"Content-Type": "application/json",
28+
'Content-Type': 'application/json',
2929
}
3030
: {}),
3131
...(config.token
3232
? { Authorization: `Bearer ${config.token}` }
3333
: {}),
3434
...options.headers,
35-
"x-raisely-cli": true,
35+
'x-raisely-cli': true,
3636
},
3737
body:
38-
options.method !== "GET" && options.json
38+
options.method !== 'GET' && options.json
3939
? JSON.stringify(options.json)
4040
: undefined,
4141
agent: config.apiUrl ? devHttpsAgent : undefined,
@@ -53,9 +53,11 @@ export default async function api(options) {
5353
// Add extra line break before throwing error - for better visual grep
5454
console.error('');
5555

56-
const formattedError =
57-
`${fetchUrl} (${response.status}) failed with message: ${
58-
(responseIsJSON && formatted.detail) || response.statusText}`;
56+
const formattedError = `${fetchUrl} (${
57+
response.status
58+
}) failed with message: ${
59+
(responseIsJSON && formatted.detail) || response.statusText
60+
}`;
5961

6062
throw new Error(formattedError);
6163
}

src/actions/auth.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import jwtDecode from "jwt-decode";
2-
import inquirer from "inquirer";
3-
import ora from "ora";
1+
import jwtDecode from 'jwt-decode';
2+
import inquirer from 'inquirer';
3+
import ora from 'ora';
44

5-
import api from "./api.js";
6-
import { error, log } from "../helpers.js";
7-
import { doLogin } from "../login.js";
8-
import { updateConfig } from "../config.js";
5+
import api from './api.js';
6+
import { error, log } from '../helpers.js';
7+
import { doLogin } from '../login.js';
8+
import { updateConfig } from '../config.js';
99

1010
let token = null;
1111
let tokenExpiresAt = null;
@@ -37,15 +37,15 @@ function setTokenExpiresAt() {
3737
const decoded = jwtDecode(token);
3838
tokenExpiresAt = new Date(decoded.exp * 1000);
3939
} catch (e) {
40-
console.warn("Could not decode token, is it a JWT?");
40+
console.warn('Could not decode token, is it a JWT?');
4141
}
4242
}
4343
}
4444

4545
async function checkCorrectOrganisation(orgUuid, opts, currentOrganisation) {
4646
let organisationUuid = orgUuid;
4747
if (!organisationUuid) {
48-
const permChecker = ora("Checking campaign permissions...").start();
48+
const permChecker = ora('Checking campaign permissions...').start();
4949
try {
5050
const campaignUuid = opts.campaigns[0];
5151
const campaign = await api({
@@ -58,7 +58,7 @@ async function checkCorrectOrganisation(orgUuid, opts, currentOrganisation) {
5858
} catch (e) {
5959
error(e, permChecker);
6060
console.error(
61-
"Could not retrieve the campaign. Are you switched into the correct organisation?"
61+
'Could not retrieve the campaign. Are you switched into the correct organisation?'
6262
);
6363

6464
// A bit hacky, but saves a lot of conditional code all over or
@@ -69,28 +69,28 @@ async function checkCorrectOrganisation(orgUuid, opts, currentOrganisation) {
6969

7070
if (organisationUuid) {
7171
const authData = await api({
72-
path: "/authenticate",
72+
path: '/authenticate',
7373
});
7474
if (authData.organisationUuid !== organisationUuid) {
7575
log(
7676
`This configuration is for organisation ${organisationUuid} but you are currently in organisation ${authData.organisationUuid}`,
77-
"white"
77+
'white'
7878
);
7979
const response = await inquirer.prompt([
8080
{
81-
type: "confirm",
82-
name: "confirm",
81+
type: 'confirm',
82+
name: 'confirm',
8383
message: `Would you like to switch your account to ${organisationUuid} now?`,
8484
},
8585
]);
8686
if (response.confirm) {
8787
const loader = ora(
88-
"Switching to correct organisation ..."
88+
'Switching to correct organisation ...'
8989
).start();
9090
try {
9191
await api({
9292
path: `/users/${authData.userUuid}/move`,
93-
method: "PUT",
93+
method: 'PUT',
9494
json: {
9595
data: {
9696
organisationUuid,
@@ -109,8 +109,8 @@ async function checkCorrectOrganisation(orgUuid, opts, currentOrganisation) {
109109

110110
export async function login(body, opts = {}) {
111111
return await api({
112-
path: "/login",
113-
method: "POST",
112+
path: '/login',
113+
method: 'POST',
114114
json: body,
115115
});
116116
}
@@ -126,8 +126,7 @@ export async function getToken(program, opts, warnEarly) {
126126
}
127127
if (isTokenExpired(warnEarly)) {
128128
({ token } = await doLogin(
129-
program,
130-
"Your token has expired, please login again"
129+
'Your token has expired, please login again'
131130
));
132131
setTokenExpiresAt();
133132
await updateConfig({ token });

src/actions/campaigns.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
import glob from "glob-promise";
2-
import path from "path";
3-
import fs from "fs";
4-
import api from "./api.js";
1+
import glob from 'glob-promise';
2+
import path from 'path';
3+
import fs from 'fs';
4+
import api from './api.js';
55

66
export async function getCampaigns() {
77
return await api({
8-
path: "/campaigns",
9-
method: "GET",
8+
path: '/campaigns',
9+
method: 'GET',
1010
});
1111
}
1212

1313
export async function getCampaign({ uuid }) {
1414
return await api({
1515
path: `/campaigns/${uuid}`,
16-
method: "GET",
16+
method: 'GET',
1717
});
1818
}
1919

2020
export async function getBaseStyles({ uuid }) {
2121
return await api({
2222
path: `/campaigns/${uuid}/base.css?asSass=1`,
23-
method: "GET",
23+
method: 'GET',
2424
});
2525
}
2626

2727
export async function fetchStyles({ campaign, filename }) {
28-
const stylesDir = path.join(process.cwd(), "stylesheets");
28+
const stylesDir = path.join(process.cwd(), 'stylesheets');
2929
const filePath = campaign || filename.split(path.sep)[0];
3030

3131
const fullPath = path.join(stylesDir, filePath);
@@ -37,20 +37,20 @@ export async function fetchStyles({ campaign, filename }) {
3737
// `glob` above returns paths with forward slashes only,
3838
// so we need to replace potential Windows-style back slashes
3939
// before attempting to find and remove the full path.
40-
.replace(`${fullPath.replace(/\\/g, "/")}/`, "");
40+
.replace(`${fullPath.replace(/\\/g, '/')}/`, '');
4141

4242
// continue if this is the main stylesheet
4343

4444
if (fileName === `${filePath}.scss`) continue;
4545

46-
configFiles[fileName] = fs.readFileSync(file, "utf8");
46+
configFiles[fileName] = fs.readFileSync(file, 'utf8');
4747
}
4848

4949
return {
5050
configFiles,
5151
css: fs.readFileSync(
5252
path.join(stylesDir, filePath, `${filePath}.scss`),
53-
"utf8"
53+
'utf8'
5454
),
5555
};
5656
}
@@ -73,7 +73,7 @@ export async function uploadStyles(filename) {
7373

7474
const campaign = await api({
7575
path: `/campaigns/${campaignPath}?private=1`,
76-
method: "GET",
76+
method: 'GET',
7777
});
7878

7979
const { configFiles, css } = await fetchStyles({
@@ -87,7 +87,7 @@ export async function uploadStyles(filename) {
8787

8888
return await api({
8989
path: `/campaigns/${campaignPath}/config/css?private=1`,
90-
method: "PATCH",
90+
method: 'PATCH',
9191
json: { data },
9292
});
9393
}

0 commit comments

Comments
 (0)