@webiny/cli 0.0.0-ee-vpcs.549378cf03
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/bin.js +38 -0
- package/cli.js +86 -0
- package/commands/index.js +20 -0
- package/commands/run/index.js +38 -0
- package/commands/telemetry/index.js +31 -0
- package/commands/upgrade/index.js +107 -0
- package/commands/wcp/hooks.js +133 -0
- package/commands/wcp/index.js +8 -0
- package/commands/wcp/login.js +228 -0
- package/commands/wcp/logout.js +28 -0
- package/commands/wcp/project.js +202 -0
- package/commands/wcp/utils/getProjectEnvironment.js +120 -0
- package/commands/wcp/utils/getUser.js +100 -0
- package/commands/wcp/utils/getWcpPat.js +5 -0
- package/commands/wcp/utils/index.js +17 -0
- package/commands/wcp/utils/setProjectId.js +44 -0
- package/commands/wcp/utils/setWcpPat.js +5 -0
- package/commands/wcp/utils/sleep.js +1 -0
- package/commands/wcp/utils/updateUserLastActiveOn.js +28 -0
- package/commands/wcp/whoami.js +43 -0
- package/context.js +137 -0
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/package.json +68 -0
- package/types.d.ts +113 -0
- package/utils/PluginsContainer.js +49 -0
- package/utils/createProjectApplicationWorkspace.js +16 -0
- package/utils/getApiProjectApplicationFolder.js +12 -0
- package/utils/getProject.js +48 -0
- package/utils/getProjectApplication.js +87 -0
- package/utils/importModule.js +43 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +26 -0
- package/utils/loadEnvVariables.js +46 -0
- package/utils/localStorage.js +44 -0
- package/utils/log.js +67 -0
- package/utils/sendEvent.js +15 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const { addHook } = require("pirates");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Add support for TS
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
addHook(
|
|
10
|
+
code => {
|
|
11
|
+
const ts = require("typescript");
|
|
12
|
+
const { outputText } = ts.transpileModule(code, {
|
|
13
|
+
compilerOptions: {
|
|
14
|
+
target: "es6",
|
|
15
|
+
allowJs: true,
|
|
16
|
+
allowSyntheticDefaultImports: true,
|
|
17
|
+
esModuleInterop: true,
|
|
18
|
+
outDir: "bin",
|
|
19
|
+
moduleResolution: "node",
|
|
20
|
+
module: "commonjs"
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return outputText;
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
exts: [".ts"],
|
|
28
|
+
matcher: () => true
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
module.exports.importModule = configPath => {
|
|
33
|
+
if (!fs.existsSync(configPath)) {
|
|
34
|
+
throw Error(`"${configPath}" does not exist!`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const extension = path.extname(configPath);
|
|
38
|
+
if (extension === ".ts") {
|
|
39
|
+
return require(configPath).default;
|
|
40
|
+
} else {
|
|
41
|
+
return require(configPath);
|
|
42
|
+
}
|
|
43
|
+
};
|
package/utils/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function getApiProjectApplicationFolder(project: Record<string, any>): boolean;
|
package/utils/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const { importModule } = require("./importModule");
|
|
2
|
+
const createProjectApplicationWorkspace = require("./createProjectApplicationWorkspace");
|
|
3
|
+
const getProject = require("./getProject");
|
|
4
|
+
const getProjectApplication = require("./getProjectApplication");
|
|
5
|
+
const getApiProjectApplicationFolder = require("./getApiProjectApplicationFolder");
|
|
6
|
+
const localStorage = require("./localStorage");
|
|
7
|
+
const log = require("./log");
|
|
8
|
+
const sendEvent = require("./sendEvent");
|
|
9
|
+
const PluginsContainer = require("./PluginsContainer");
|
|
10
|
+
|
|
11
|
+
const noop = () => {
|
|
12
|
+
// Do nothing.
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
createProjectApplicationWorkspace,
|
|
17
|
+
getApiProjectApplicationFolder,
|
|
18
|
+
getProject,
|
|
19
|
+
getProjectApplication,
|
|
20
|
+
importModule,
|
|
21
|
+
localStorage,
|
|
22
|
+
log,
|
|
23
|
+
noop,
|
|
24
|
+
sendEvent,
|
|
25
|
+
PluginsContainer
|
|
26
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const yargs = require("yargs");
|
|
3
|
+
const log = require("./log");
|
|
4
|
+
const getProject = require("./getProject");
|
|
5
|
+
const { boolean } = require("boolean");
|
|
6
|
+
|
|
7
|
+
// Load environment variables from following sources:
|
|
8
|
+
// - `webiny.project.ts` file
|
|
9
|
+
// - `.env` file
|
|
10
|
+
// - `.env.{PASSED_ENVIRONMENT}` file
|
|
11
|
+
|
|
12
|
+
const project = getProject();
|
|
13
|
+
|
|
14
|
+
// `webiny.project.ts` file.
|
|
15
|
+
// Environment variables defined via the `env` property.
|
|
16
|
+
if (project.config.env) {
|
|
17
|
+
Object.assign(process.env, project.config.env);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// `.env.{PASSED_ENVIRONMENT}` and `.env` files.
|
|
21
|
+
let paths = [path.join(project.root, ".env")];
|
|
22
|
+
|
|
23
|
+
if (yargs.argv.env) {
|
|
24
|
+
paths.push(path.join(project.root, `.env.${yargs.argv.env}`));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Let's load environment variables
|
|
28
|
+
for (let i = 0; i < paths.length; i++) {
|
|
29
|
+
const path = paths[i];
|
|
30
|
+
const { error } = require("dotenv").config({ path });
|
|
31
|
+
if (boolean(yargs.argv.debug)) {
|
|
32
|
+
if (error) {
|
|
33
|
+
log.debug(`No environment file found on ${log.debug.hl(path)}.`);
|
|
34
|
+
} else {
|
|
35
|
+
log.success(`Successfully loaded environment variables from ${log.success.hl(path)}.`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Feature flags defined via the `featureFlags` property.
|
|
41
|
+
// We set twice, to be available for both backend and frontend application code.
|
|
42
|
+
// TODO: one day we might want to sync this up a bit.
|
|
43
|
+
if (project.config.featureFlags) {
|
|
44
|
+
process.env.WEBINY_FEATURE_FLAGS = JSON.stringify(project.config.featureFlags);
|
|
45
|
+
process.env.REACT_APP_WEBINY_FEATURE_FLAGS = JSON.stringify(project.config.featureFlags);
|
|
46
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// This is a small class that enables us to store some useful
|
|
2
|
+
// data into the .webiny folder, located in the project root.
|
|
3
|
+
// For example, we are saving the path entered while creating
|
|
4
|
+
// GraphQL services, so that the user doesn't have to type
|
|
5
|
+
// the same paths over and over.
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
const path = require("path");
|
|
8
|
+
const getProject = require("./getProject");
|
|
9
|
+
|
|
10
|
+
module.exports = function (filename = "cli.json") {
|
|
11
|
+
const project = getProject();
|
|
12
|
+
const DOT_WEBINY = path.join(project.root, ".webiny");
|
|
13
|
+
const dataFilePath = path.join(DOT_WEBINY, filename);
|
|
14
|
+
|
|
15
|
+
let data = {};
|
|
16
|
+
if (fs.existsSync(dataFilePath)) {
|
|
17
|
+
try {
|
|
18
|
+
data = JSON.parse(fs.readFileSync(dataFilePath));
|
|
19
|
+
} catch (e) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`Could not parse Webiny CLI's locale storage data file located at ${dataFilePath}.`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
set(key, value) {
|
|
28
|
+
data[key] = value;
|
|
29
|
+
|
|
30
|
+
if (!fs.existsSync(DOT_WEBINY)) {
|
|
31
|
+
fs.mkdirSync(DOT_WEBINY);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
fs.writeFileSync(dataFilePath, JSON.stringify(data));
|
|
35
|
+
return data;
|
|
36
|
+
},
|
|
37
|
+
get(key) {
|
|
38
|
+
if (!key) {
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
41
|
+
return data[key];
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
};
|
package/utils/log.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const chalk = require("chalk");
|
|
2
|
+
|
|
3
|
+
const logColors = {
|
|
4
|
+
log: v => v,
|
|
5
|
+
info: chalk.blueBright,
|
|
6
|
+
error: chalk.red,
|
|
7
|
+
warning: chalk.yellow,
|
|
8
|
+
debug: chalk.gray,
|
|
9
|
+
success: chalk.green
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const colorizePlaceholders = (type, string) => {
|
|
13
|
+
return string.replace(/\%[a-zA-Z]/g, match => {
|
|
14
|
+
return logColors[type](match);
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const webinyLog = (type, ...args) => {
|
|
19
|
+
const prefix = `webiny ${logColors[type](type)}: `;
|
|
20
|
+
|
|
21
|
+
const [first, ...rest] = args;
|
|
22
|
+
if (typeof first === "string") {
|
|
23
|
+
return console.log(prefix + colorizePlaceholders(type, first), ...rest);
|
|
24
|
+
}
|
|
25
|
+
return console.log(prefix, first, ...rest);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const functions = {
|
|
29
|
+
log(...args) {
|
|
30
|
+
webinyLog("log", ...args);
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
info(...args) {
|
|
34
|
+
webinyLog("info", ...args);
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
success(...args) {
|
|
38
|
+
webinyLog("success", ...args);
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
debug(...args) {
|
|
42
|
+
webinyLog("debug", ...args);
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
warning(...args) {
|
|
46
|
+
webinyLog("warning", ...args);
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
error(...args) {
|
|
50
|
+
webinyLog("error", ...args);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
functions.log.highlight = chalk.highlight;
|
|
55
|
+
functions.log.hl = chalk.highlight;
|
|
56
|
+
functions.info.highlight = chalk.blue;
|
|
57
|
+
functions.info.hl = chalk.blueBright;
|
|
58
|
+
functions.success.highlight = chalk.green;
|
|
59
|
+
functions.success.hl = chalk.green;
|
|
60
|
+
functions.debug.highlight = chalk.gray;
|
|
61
|
+
functions.debug.hl = chalk.gray;
|
|
62
|
+
functions.warning.highlight = chalk.yellow;
|
|
63
|
+
functions.warning.hl = chalk.yellow;
|
|
64
|
+
functions.error.highlight = chalk.red;
|
|
65
|
+
functions.error.hl = chalk.red;
|
|
66
|
+
|
|
67
|
+
module.exports = functions;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const { sendEvent } = require("@webiny/telemetry/cli");
|
|
2
|
+
const getProject = require("./getProject");
|
|
3
|
+
|
|
4
|
+
module.exports = ({ event, properties, extraPayload }) => {
|
|
5
|
+
const project = getProject();
|
|
6
|
+
if (project.config.cli && project.config.cli.telemetry === false) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return sendEvent({
|
|
11
|
+
event,
|
|
12
|
+
properties,
|
|
13
|
+
extraPayload
|
|
14
|
+
});
|
|
15
|
+
};
|