Skip to content

Commit

Permalink
merge: pull in changes from next
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Apr 16, 2022
2 parents a6cf5c7 + 1b480ea commit 5cd9dca
Show file tree
Hide file tree
Showing 156 changed files with 9,651 additions and 1,569 deletions.
1 change: 1 addition & 0 deletions .adiorc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = {
"path",
"https",
"follow-redirects",
"child_process",
"os",
"fs",
"util",
Expand Down
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
**/node_modules/
**/dist/
**/lib/
**/build/
**/.out/
**/*.d.ts
idea.js
scripts
packages/ui/src/RichTextEditor/editorjs/**
packages/ui/rmwc/**
packages-v6/pb-editor/**
packages-v6/pb-editor/**
packages-v6/core/**/artifacts/**
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ module.exports = {
"@typescript-eslint/no-use-before-define": 0,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/no-explicit-any": 0,
// Temporarily disable this rule
"@typescript-eslint/no-non-null-assertion": 0,
curly: ["error"],
"jest/expect-expect": 0,
// Sometimes we have to use expect() inside try/catch clause (for async calls).
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea
.webpack
.webiny
.artifacts
.env*
.npmrc
htpasswd
Expand All @@ -15,7 +16,8 @@ yarn-debug.log*
yarn-error.log*
dist/
lib/
build/
api/**/build/
apps/**/build/
.files/
.changelog
.verdaccio
Expand Down
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
"prettier": "prettier \"**/**/*.{js,jsx,ts,tsx,json}\" --config .prettierrc.js",
"prettier:check": "yarn prettier --check",
"prettier:fix": "yarn prettier --write",
"lint:fix": "yarn eslint:fix && yarn prettier:fix",
"setup-project": "node scripts/setupProject",
"setup-env-files": "node scripts/setupEnvFiles",
"setup-ci-cypress": "node scripts/setupCiCypress",
Expand All @@ -149,15 +150,16 @@
"validate-packages": "node scripts/validatePackages.js",
"lerna:version:latest": "yarn lerna version --force-publish --conventional-graduate --yes",
"lerna:publish:latest": "yarn lerna publish from-package --yes",
"lerna:version:beta": "yarn lerna version --conventional-prerelease --force-publish --preid beta --yes",
"lerna:version:beta": "yarn lerna version prerelease --conventional-prerelease --force-publish --preid beta --yes",
"lerna:publish:beta": "yarn lerna publish from-package --dist-tag beta --yes",
"lerna:version:verdaccio": "yarn lerna version --conventional-prerelease --force-publish --preid next --no-push --no-changelog --yes",
"lerna:version:verdaccio": "yarn lerna version prerelease --conventional-prerelease --force-publish --preid next --no-push --no-changelog --yes",
"lerna:publish:verdaccio": "yarn lerna publish from-package --dist-tag next --registry=\"http://localhost:4873\" --no-verify-access --no-verify-registry --yes",
"lerna:version:experimental": "yarn lerna version --conventional-prerelease --preid experimental --force-publish --no-push --no-changelog --yes",
"lerna:version:experimental": "yarn lerna version prerelease --conventional-prerelease --preid experimental --force-publish --no-push --no-changelog --yes",
"lerna:publish:experimental": "yarn lerna publish from-package --dist-tag experimental --yes",
"verdaccio:start": "yarn verdaccio -c ./.verdaccio.yaml",
"verdaccio:start:detached": "yarn pm2 start \"yarn verdaccio:start\"",
"webiny": "./node_modules/.bin/webiny",
"wby": "./node_modules/.bin/wby",
"webiny-ui-build-storybook": "cd packages/ui && cross-env OUT=../../netlify-static yarn build-storybook"
},
"husky": {
Expand Down Expand Up @@ -213,14 +215,16 @@
"@rmwc/base": "link:./packages/ui/rmwc/base",
"@types/react": "16.14.2",
"@typescript/lib-dom": "npm:@types/web@*",
"@types/webpack": "^5.28.0",
"react": "16.14.0",
"react-dom": "16.14.0",
"pretty-format": "25.5.0",
"typescript": "4.5.5",
"codex-tooltip": "1.0.2",
"@pulumi/pulumi": "3.19.0",
"@pulumi/aws": "4.28.0",
"@types/eslint": "8.2.1"
"@types/eslint": "8.2.1",
"yargs": "^17.3.1"
},
"packageManager": "yarn@3.1.0"
}
7 changes: 7 additions & 0 deletions packages-v6/admin/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from "react";

console.log("Admin component");

export const Admin: React.FC = ({ children }) => {
return <>{children}</>;
};
9 changes: 9 additions & 0 deletions packages-v6/admin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"private": true,
"name": "@webiny/admin",
"sideEffects": false,
"main": "./src/index.tsx",
"dependencies": {
"react": "^16.14.0"
}
}
11 changes: 11 additions & 0 deletions packages-v6/cli/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
presets: [
[
"@babel/env",
{
modules: "commonjs"
}
],
"@babel/typescript"
]
};
29 changes: 29 additions & 0 deletions packages-v6/cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"private": true,
"name": "@webiny/cli2",
"version": "5.25.0",
"sideEffects": false,
"bin": {
"wby": "./src/bin.js"
},
"main": "./src/index.ts",
"scripts": {
"build": "yarn wby build package"
},
"dependencies": {
"@webiny/core": "^5.25.0",
"execa": "^5.1.1",
"load-json-file": "^6.2.0",
"ts-morph": "^14.0.0",
"yargs": "^17.3.1"
},
"devDependencies": {
"@types/yargs": "^17.0.8",
"ts-node": "^10.5.0"
},
"webiny": {
"moduleTypes": [
"cjs"
]
}
}
12 changes: 12 additions & 0 deletions packages-v6/cli/src/bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env node
process.env.NODE_PATH = process.cwd();

require("ts-node").register({
dir: process.cwd()
});

const { runCli } = require("./cli");
(async () => {
await runCli();
process.exit();
})();
65 changes: 65 additions & 0 deletions packages-v6/cli/src/buildPackage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import execa from "execa";
import loadJson from "load-json-file";
import { join } from "path";

interface BuildPackageParams {
directory: string;
}

enum ModuleType {
ESM = "esm",
CJS = "cjs"
}

interface WebinyPackageConfig {
moduleTypes: ModuleType[];
}

function getBabelParams(type: ModuleType): string[] {
return [
"src",
"--extensions",
".ts,.tsx",
"--out-dir",
`lib/${type}`,
"--source-maps",
"--copy-files"
];
}

export async function buildPackage({ directory }: BuildPackageParams) {
const packageJson: Record<string, unknown> = await loadJson(join(directory, "package.json"));
if (!packageJson) {
throw Error(`package.json not found in "${directory}"!`);
}

const config = packageJson["webiny"] as WebinyPackageConfig | undefined;
const moduleTypes = config ? config.moduleTypes : [ModuleType.CJS, ModuleType.ESM];

const promises = [];

// Build ESM
if (moduleTypes.includes(ModuleType.ESM)) {
promises.push(
execa("babel", getBabelParams(ModuleType.ESM), {
cwd: directory,
env: { BABEL_ENV: ModuleType.ESM }
})
);
}

// Build CJS
if (moduleTypes.includes(ModuleType.CJS)) {
promises.push(
execa("babel", getBabelParams(ModuleType.CJS), {
cwd: directory,
env: { BABEL_ENV: ModuleType.CJS }
})
);
}

// Generate TS declarations
promises.push(execa("ttsc", ["-p", "tsconfig.build.json"], { cwd: directory }));

return await Promise.all(promises);
}
72 changes: 72 additions & 0 deletions packages-v6/cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import * as yargs from "yargs";
import type { MiddlewareFunction, Options } from "yargs";
import { Webiny } from "@webiny/core";

interface ParsedOptions {
// Even though `debug` has a default value, and will always be present, we have to mark it as optional
// because the `.middleware()` function doesn't accept a generic type and will complain about any required parameter.
debug?: boolean;
env?: string;
}

export const runCli = () => {
let webiny: Webiny;

// `yargs` middleware allows us to setup Webiny based on the parsed CLI arguments.
const setupContext: MiddlewareFunction<ParsedOptions> = async args => {
if (args._.includes("build") && args._.includes("package")) {
return;
}

const { initializeWebiny } = await import("@webiny/core");
webiny = await initializeWebiny({ debug: args.debug || false, env: args.env });
};

const envOption: Record<string, Options> = { env: { type: "string", required: true } };
const watchOption: Record<string, Options> = { watch: { type: "boolean", default: false } };

return yargs
.scriptName("webiny")
.usage("$0 <cmd> [args]")
.middleware(setupContext)
.option("debug", {
default: false,
global: true,
type: "boolean"
})
.command("watch", "Watch [admin|website]", yargs => {
yargs.command("admin", "Watch the admin app", {}, async () => {
await webiny.buildAdmin({ watch: true });
});
})
.command("build", "Build [package|api|admin|website]", yargs => {
yargs.command("package", "Build a package", {}, async () => {
const { buildPackage } = await import("./buildPackage");
await buildPackage({ directory: process.cwd() });
});

yargs.command("admin", "Build the admin app", {}, async () => {
return webiny.buildAdmin({ watch: false });
});

yargs.command(
"api",
"Build API",
{ ...envOption, ...watchOption },
async ({ watch }) => {
return webiny.buildApi({ watch: Boolean(watch) });
}
);
})
.command(
"deploy-api",
"Deploy API",
{ ...envOption, preview: { type: "boolean", default: false } },
() => {
console.log("Deploy API");
// import("@webiny/deploy").then(m => m.default({ preview: args.preview }));
}
)
.help()
.parse();
};
50 changes: 50 additions & 0 deletions packages-v6/cli/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import path from "path";
import { Node, Project, SourceFile, VariableDeclaration } from "ts-morph";

const extensions = [".js", ".ts", ".tsx"];

export const getModulePath = (modulePath: string) => {
const filePath = modulePath.replace(/\\/g, "/");
if (extensions.includes(path.extname(filePath))) {
return filePath.split(".").slice(0, -1).join(".");
}
return filePath;
};

export const createMorphProject = (files: string[]) => {
const project = new Project();
for (const file of files) {
project.addSourceFileAtPath(file);
}
return project;
};

export const getDeclaration = (name: string, source: SourceFile) => {
const declaration = source.getFirstDescendant(node => {
if (!Node.isVariableDeclaration(node)) {
return false;
}

return node.getName() === name;
}) as VariableDeclaration;

if (!declaration) {
throw Error(`Unable to find "${name}" declaration!`);
}

return declaration;
};

export const getSourceFile = (project: Project, file: string) => {
if (!file) {
console.log("File variable not sent.");
return null;
}

const source = project.getSourceFile(file);
if (source) {
return source;
}

return null;
};
16 changes: 16 additions & 0 deletions packages-v6/cli/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"noEmit": false,
"declaration": true,
"emitDeclarationOnly": true,
"rootDir": "./src",
"outDir": "./lib/types",
"declarationDir": "./lib/types",
"baseUrl": ".",
"skipLibCheck": true
},
"exclude": ["./src/bin.js"],
"include": ["./src"],
"references": [{ "path": "../core/tsconfig.build.json" }]
}
15 changes: 15 additions & 0 deletions packages-v6/cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../../tsconfig.json",
"include": ["src"],
"compilerOptions": {
"baseUrl": ".",
"rootDirs": ["./src"],
"outDir": "./dist",
"declarationDir": "./dist",
"paths": {
"~/*": ["./src/*"],
"@webiny/core": ["../core/src"]
}
},
"references": [{ "path": "../core" }]
}
Loading

0 comments on commit 5cd9dca

Please sign in to comment.