Skip to content
This repository has been archived by the owner on Aug 14, 2021. It is now read-only.

Commit

Permalink
start on corejam init command #5
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias von Bargen committed Oct 1, 2020
1 parent f528dd3 commit eed050c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
3 changes: 2 additions & 1 deletion examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "eslint pages/* components/*"
"lint": "eslint pages/* components/*",
"postinstall": "corejam init"
},
"license": "MIT",
"dependencies": {
Expand Down
11 changes: 5 additions & 6 deletions packages/base/src/Bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ type introspectionResult = {
data: any;
};

let plugins: Array<string>;
let introspection: any;

/**
Expand Down Expand Up @@ -40,15 +39,15 @@ function isAPlugin(packageName: null | string = null) {
/**
* Collect all corejam plugins that are currently active
* so we can bootstrap them individually.
*
* @param path
*/
export function collectPlugins(): Array<string> {
if (plugins) return plugins;

const packageJson = require(process.cwd() + "/package.json");
export function collectPlugins(path = process.cwd()): Array<string> {
const packageJson = require(path + "/package.json");
const deps = packageJson.dependencies ? Object.keys(packageJson.dependencies) : [];
const devDeps = packageJson.devDependencies ? Object.keys(packageJson.devDependencies) : [];

plugins = [];
const plugins: Array<string> = [];
//Check all the dependencies
[...deps, ...devDeps].forEach((key) => {
if (isAPlugin(key)) {
Expand Down
22 changes: 22 additions & 0 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { envRoot } from "../config";
import chalk from "chalk";
import ora from "ora";
import { collectPlugins } from '@corejam/base/dist/Bootstrap';

export async function corejamInit(_opts?: any) {
const envPackageName = require(envRoot + "/package.json").name;
const bootSpinner = ora(`Initializing Corejam App for ${chalk.bold.green(envPackageName)}...`).start();

//Root packages
collectPluginsRecurse(collectPlugins())

bootSpinner.text = "Done"
bootSpinner.stopAndPersist();
}

function collectPluginsRecurse(plugins: Array<string>) {
return plugins.forEach(plugin => {
collectPluginsRecurse(collectPlugins(plugin))
console.log(plugin)
})
}
7 changes: 7 additions & 0 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { runTest, runWCTests } from "./commands/test";
import { envRoot } from "./config";
import { copySchemaToDist } from "./helpers/copy";
import { killAll } from "./processes";
import { corejamInit } from './commands/init';

const pkg = require("../package.json");
const prog = sade("corejam");
Expand Down Expand Up @@ -84,6 +85,12 @@ prog.command("test:wc").action(async () => {
await runWCTests();
});

prog.command("init")
.describe("add `corejam init` as postInstall hook in your package.json")
.action(async () => {
await corejamInit()
});

prog
.command("static")
.option("-l, --log", "Log output to console", false)
Expand Down

0 comments on commit eed050c

Please sign in to comment.