Skip to content

Commit

Permalink
Single plugin repo (#264)
Browse files Browse the repository at this point in the history
* Add check prompt.js file method.

* delete templates and support template from plugin source

* delete project type question

* update docs

* version bump 1.2.0

* cleanup react-core plugins links

* delete template args

* fix tabs import doc

Co-authored-by: Ömer Faruk APLAK <[email protected]>
  • Loading branch information
yildirayunlu and omeraplak authored Jul 16, 2021
1 parent 0b623df commit 64d068c
Show file tree
Hide file tree
Showing 37 changed files with 72 additions and 490 deletions.
4 changes: 2 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ npx superplate-cli <my-project>

Make sure you have npx installed (npx is shipped by default since npm 5.2.0)

You will be prompted with plugin options to create your project without spending hours on configurations. To find out more about Next.js plugins see the [superplate-core-plugins](https://github.com/pankod/superplate-core-plugins) and React plugins see the [superplate-react-core-plugins](https://github.com/pankod/superplate-react-core-plugins)
You will be prompted with plugin options to create your project without spending hours on configurations. To find out more about superplate core plugins see the [superplate-core-plugins](https://github.com/pankod/superplate-core-plugins).

<p align='center'>
<img src='images/cli.gif' width='500' alt='superplate example'>
Expand Down Expand Up @@ -104,7 +104,7 @@ superplate uses a plugin-based architecture. Basically, plugins are created from

The features and tools listed during the project creation process are implemented as plugins.

You can check them out in [superplate-core-plugins](https://github.com/pankod/superplate-core-plugins) and [superplate-react-core-plugins](https://github.com/pankod/superplate-react-core-plugins).
You can check them out in [superplate-core-plugins](https://github.com/pankod/superplate-core-plugins).

The default core plugins determined by <a href="https://www.pankod.com">Pankod</a> team uses on a day-to-day basis to build apps. Feel free to send PR or open an issue for new plugins you want to add.

Expand Down
14 changes: 4 additions & 10 deletions documentation/docs/development/creating-a-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ title: Creating a Plugin
sidebar_label: Creating a Plugin
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

You may need to add and modify some files to properly set up libraries with your Next.js project. What we call **plugin** is a directory with all the packages you need to install and the files you need to add and modify.

This article will show you how to create a superplate plugin from scratch and the ways superplate offers you to interact with other plugins in your source.
Expand Down Expand Up @@ -33,10 +36,6 @@ Change the values one with in the following commands:
- `plugin-repo-directory` with absolute path where the plugins repository cloned in to.



import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs
defaultValue="next"
values={[
Expand Down Expand Up @@ -240,9 +239,6 @@ module.exports = {

<br />

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs
defaultValue="next"
values={[
Expand Down Expand Up @@ -420,8 +416,6 @@ We're using `meta.json` to collect data about plugins. You can provide an url to

## Conclusion

We've created a plugin from scratch to add `styled-components` to our next project with **superplate**. If you want to check out how we created different plugins, please check out.
- Next.js [superplate-core-plugins](https://github.com/pankod/superplate-core-plugins).
- React [superplate-react-core-plugins](https://github.com/pankod/superplate-react-core-plugins).
We've created a plugin from scratch to add `styled-components` to our next project with **superplate**. If you want to check out how we created different plugins, please check out [superplate-core-plugins](https://github.com/pankod/superplate-core-plugins).

To learn more about superplate's API, you can check out [References](references).
8 changes: 4 additions & 4 deletions documentation/docs/development/how-it-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ sidebar_label: How it Works?

## Creating a Source Repository

We store our plugins apart from the cli to make them easy to modify and easy to create new plugins. You can see the core plugins:
- Next.js [superplate-core-plugins](https://github.com/pankod/superplate-core-plugins).
- React [superplate-react-core-plugins](https://github.com/pankod/superplate-react-core-plugins).
We store our plugins apart from the cli to make them easy to modify and easy to create new plugins. You can see the [superplate-core-plugins](https://github.com/pankod/superplate-core-plugins).

- Alternatively, you can create your own source from scratch.

Expand All @@ -23,7 +21,9 @@ If you choose to start from scratch. All you need to do is create a directory wi
│   ├── your-first-plugin
│   ├── another-plugin
│   ├── ...

├── template
│   ├── your-template-files
│   ├── ...
```

**sample `prompt.js`**
Expand Down
4 changes: 1 addition & 3 deletions documentation/docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ The features and tools listed during the project creation process are implemente

Plugins can be included as part of your project creation phase. 37+ plugins working in harmony with superplate UI Framework boilerplates.

See the list of core plugins:
- Next.js [superplate-core-plugins](https://github.com/pankod/superplate-core-plugins).
- React [superplate-react-core-plugins](https://github.com/pankod/superplate-react-core-plugins).
See the list of [core-plugins](https://github.com/pankod/superplate-core-plugins).

:::info
Plugins are customizable and extendable. You can develop your own plugin or modify existings.
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "superplate-cli",
"version": "1.1.6",
"version": "1.2.0",
"description": "The frontend boilerplate with superpowers",
"license": "MIT",
"repository": {
Expand Down
10 changes: 9 additions & 1 deletion src/Helper/fs/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { access } from "fs";
import { access, readdir } from "fs";
import { promisify } from "util";

export const FSHelper = {
Expand All @@ -10,4 +10,12 @@ export const FSHelper = {
return false;
}
},

ReadDir: async (path: string): Promise<string[]> => {
try {
return await promisify(readdir)(path);
} catch (e) {
return [];
}
},
};
1 change: 1 addition & 0 deletions src/Helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export { GitHelper } from "./git";
export { FSHelper } from "./fs";
export { tips } from "./tips";
export { BinaryHelper } from "./binary";
export { capitalizeFirstLetter } from "./text";
19 changes: 3 additions & 16 deletions src/Helper/source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import chalk from "chalk";
import { GitHelper, FSHelper } from "@Helper";

type SourceResponse = { path?: string; error?: string };
type GetSourceFn = (source: string) => Promise<SourceResponse>;
type GetSourceFn = (source: string | undefined) => Promise<SourceResponse>;

export const get_source: GetSourceFn = async (source) => {
/**
Expand All @@ -21,21 +21,8 @@ export const get_source: GetSourceFn = async (source) => {
);
sourceSpinner.start();

let sourcePath = source;
switch (source) {
case "react":
sourcePath =
"https://github.com/pankod/superplate-react-core-plugins.git";
break;
case "nextjs":
sourcePath =
"https://github.com/pankod/superplate-core-plugins.git";
break;
case "refine":
sourcePath =
"https://github.com/pankod/superplate-refine-core-plugins.git";
break;
}
const sourcePath =
source ?? "https://github.com/pankod/superplate-core-plugins.git";

const isPathExists = await FSHelper.IsPathExists(sourcePath);
if (isPathExists) {
Expand Down
3 changes: 3 additions & 0 deletions src/Helper/text/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const capitalizeFirstLetter = (text: string): string => {
return text.charAt(0).toUpperCase() + text.slice(1);
};
59 changes: 40 additions & 19 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import path from "path";
import commander from "commander";
import { cleanupSync } from "temp";
import { Options, SAO } from "sao";
import prompts from "prompts";
import prompts, { Choice } from "prompts";

import { get_source } from "@Helper";
import { get_source, FSHelper } from "@Helper";
import packageData from "../package.json";

const generator = path.resolve(__dirname, "./");
const templateDir = (projectType: string) =>
path.resolve(__dirname, "../templates", projectType);

const cli = async (): Promise<void> => {
clear();
Expand Down Expand Up @@ -75,22 +73,13 @@ const cli = async (): Promise<void> => {
process.exit(1);
}

const { projectType } = await prompts({
type: "select",
name: "projectType",
message: "Select your project type",
choices: [
{ title: "React", value: "react" },
{ title: "Next.js", value: "nextjs" },
],
});

/**
* get source path
*/
const { path: sourcePath, error: sourceError } = await get_source(
program.source || projectType,
);
const source = await get_source(program.source);

let { path: sourcePath } = source;
const { error: sourceError } = source;

if (sourceError) {
console.error(`${chalk.bold`${sourceError}`}`);
Expand All @@ -106,6 +95,40 @@ const cli = async (): Promise<void> => {
process.exit(1);
}

// check root prompt.js
const checkRootPrompt = await FSHelper.IsPathExists(
`${sourcePath}/prompt.js`,
);

if (sourcePath && !checkRootPrompt) {
const projectTypes: Choice[] = [];

// get project types => react,nextjs,refine ...etc
const files = await FSHelper.ReadDir(sourcePath);

for (const file of files) {
const existPromptFile = await FSHelper.IsPathExists(
`${sourcePath}/${file}/prompt.js`,
);

if (existPromptFile) {
projectTypes.push({
title: file,
value: file,
});
}
}

const { projectType } = await prompts({
type: "select",
name: "projectType",
message: "Select your project type",
choices: projectTypes,
});

sourcePath = `${sourcePath}/${projectType}`;
}

const sao = new SAO({
generator,
outDir: projectDir,
Expand All @@ -114,10 +137,8 @@ const cli = async (): Promise<void> => {
extras: {
debug: !!program.debug,
paths: {
templateDir: templateDir(projectType),
sourcePath,
},
projectType,
},
} as Options);

Expand Down
19 changes: 3 additions & 16 deletions src/saofile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,20 @@ const saoConfig: GeneratorConfig = {
process.exit(1);
}

const { sourcePath, templateDir } = sao.opts.extras.paths;
const { projectType } = sao.opts.extras;
const { sourcePath } = sao.opts.extras.paths;

const actionsArray = [
{
type: "add",
files: "**",
templateDir,
templateDir: path.join(sourcePath, "template"),
data() {
return sao.data;
},
},
{
type: "move",
templateDir,
templateDir: path.join(sourcePath, "template"),
patterns: {
gitignore: ".gitignore",
"_package.json": "package.json",
Expand All @@ -151,18 +150,6 @@ const saoConfig: GeneratorConfig = {
},
] as Action[];

/**
* Apply overrides to the template
*/
actionsArray.push({
type: "add",
files: "**",
templateDir: path.join(sourcePath, "template"),
data() {
return sao.data;
},
});

const pluginAnswers = { ...sao.answers };
delete pluginAnswers.name;

Expand Down
1 change: 0 additions & 1 deletion templates/nextjs/.gitattributes

This file was deleted.

19 changes: 0 additions & 19 deletions templates/nextjs/LICENSE

This file was deleted.

45 changes: 0 additions & 45 deletions templates/nextjs/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions templates/nextjs/_next-env.d.ts

This file was deleted.

Loading

0 comments on commit 64d068c

Please sign in to comment.