-
Notifications
You must be signed in to change notification settings - Fork 618
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
156 changed files
with
9,651 additions
and
1,569 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ module.exports = { | |
"path", | ||
"https", | ||
"follow-redirects", | ||
"child_process", | ||
"os", | ||
"fs", | ||
"util", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}</>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
presets: [ | ||
[ | ||
"@babel/env", | ||
{ | ||
modules: "commonjs" | ||
} | ||
], | ||
"@babel/typescript" | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }] | ||
} |
Oops, something went wrong.