Skip to content

Commit 64d068c

Browse files
Single plugin repo (#264)
* 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]>
1 parent 0b623df commit 64d068c

37 files changed

+72
-490
lines changed

README.MD

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ npx superplate-cli <my-project>
6868

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

71-
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)
71+
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).
7272

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

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

107-
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).
107+
You can check them out in [superplate-core-plugins](https://github.com/pankod/superplate-core-plugins).
108108

109109
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.
110110

documentation/docs/development/creating-a-plugin.md

+4-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ title: Creating a Plugin
44
sidebar_label: Creating a Plugin
55
---
66

7+
import Tabs from '@theme/Tabs';
8+
import TabItem from '@theme/TabItem';
9+
710
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.
811

912
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.
@@ -33,10 +36,6 @@ Change the values one with in the following commands:
3336
- `plugin-repo-directory` with absolute path where the plugins repository cloned in to.
3437

3538

36-
37-
import Tabs from '@theme/Tabs';
38-
import TabItem from '@theme/TabItem';
39-
4039
<Tabs
4140
defaultValue="next"
4241
values={[
@@ -240,9 +239,6 @@ module.exports = {
240239

241240
<br />
242241

243-
import Tabs from '@theme/Tabs';
244-
import TabItem from '@theme/TabItem';
245-
246242
<Tabs
247243
defaultValue="next"
248244
values={[
@@ -420,8 +416,6 @@ We're using `meta.json` to collect data about plugins. You can provide an url to
420416

421417
## Conclusion
422418

423-
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.
424-
- Next.js [superplate-core-plugins](https://github.com/pankod/superplate-core-plugins).
425-
- React [superplate-react-core-plugins](https://github.com/pankod/superplate-react-core-plugins).
419+
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).
426420

427421
To learn more about superplate's API, you can check out [References](references).

documentation/docs/development/how-it-works.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ sidebar_label: How it Works?
88

99
## Creating a Source Repository
1010

11-
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:
12-
- Next.js [superplate-core-plugins](https://github.com/pankod/superplate-core-plugins).
13-
- React [superplate-react-core-plugins](https://github.com/pankod/superplate-react-core-plugins).
11+
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).
1412

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

@@ -23,7 +21,9 @@ If you choose to start from scratch. All you need to do is create a directory wi
2321
│   ├── your-first-plugin
2422
│   ├── another-plugin
2523
│   ├── ...
26-
24+
├── template
25+
│   ├── your-template-files
26+
│   ├── ...
2727
```
2828

2929
**sample `prompt.js`**

documentation/docs/quick-start.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ The features and tools listed during the project creation process are implemente
4343

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

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

5048
:::info
5149
Plugins are customizable and extendable. You can develop your own plugin or modify existings.

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "superplate-cli",
3-
"version": "1.1.6",
3+
"version": "1.2.0",
44
"description": "The frontend boilerplate with superpowers",
55
"license": "MIT",
66
"repository": {

src/Helper/fs/index.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { access } from "fs";
1+
import { access, readdir } from "fs";
22
import { promisify } from "util";
33

44
export const FSHelper = {
@@ -10,4 +10,12 @@ export const FSHelper = {
1010
return false;
1111
}
1212
},
13+
14+
ReadDir: async (path: string): Promise<string[]> => {
15+
try {
16+
return await promisify(readdir)(path);
17+
} catch (e) {
18+
return [];
19+
}
20+
},
1321
};

src/Helper/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ export { GitHelper } from "./git";
1717
export { FSHelper } from "./fs";
1818
export { tips } from "./tips";
1919
export { BinaryHelper } from "./binary";
20+
export { capitalizeFirstLetter } from "./text";

src/Helper/source/index.ts

+3-16
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import chalk from "chalk";
1010
import { GitHelper, FSHelper } from "@Helper";
1111

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

1515
export const get_source: GetSourceFn = async (source) => {
1616
/**
@@ -21,21 +21,8 @@ export const get_source: GetSourceFn = async (source) => {
2121
);
2222
sourceSpinner.start();
2323

24-
let sourcePath = source;
25-
switch (source) {
26-
case "react":
27-
sourcePath =
28-
"https://github.com/pankod/superplate-react-core-plugins.git";
29-
break;
30-
case "nextjs":
31-
sourcePath =
32-
"https://github.com/pankod/superplate-core-plugins.git";
33-
break;
34-
case "refine":
35-
sourcePath =
36-
"https://github.com/pankod/superplate-refine-core-plugins.git";
37-
break;
38-
}
24+
const sourcePath =
25+
source ?? "https://github.com/pankod/superplate-core-plugins.git";
3926

4027
const isPathExists = await FSHelper.IsPathExists(sourcePath);
4128
if (isPathExists) {

src/Helper/text/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const capitalizeFirstLetter = (text: string): string => {
2+
return text.charAt(0).toUpperCase() + text.slice(1);
3+
};

src/cli.ts

+40-19
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import path from "path";
44
import commander from "commander";
55
import { cleanupSync } from "temp";
66
import { Options, SAO } from "sao";
7-
import prompts from "prompts";
7+
import prompts, { Choice } from "prompts";
88

9-
import { get_source } from "@Helper";
9+
import { get_source, FSHelper } from "@Helper";
1010
import packageData from "../package.json";
1111

1212
const generator = path.resolve(__dirname, "./");
13-
const templateDir = (projectType: string) =>
14-
path.resolve(__dirname, "../templates", projectType);
1513

1614
const cli = async (): Promise<void> => {
1715
clear();
@@ -75,22 +73,13 @@ const cli = async (): Promise<void> => {
7573
process.exit(1);
7674
}
7775

78-
const { projectType } = await prompts({
79-
type: "select",
80-
name: "projectType",
81-
message: "Select your project type",
82-
choices: [
83-
{ title: "React", value: "react" },
84-
{ title: "Next.js", value: "nextjs" },
85-
],
86-
});
87-
8876
/**
8977
* get source path
9078
*/
91-
const { path: sourcePath, error: sourceError } = await get_source(
92-
program.source || projectType,
93-
);
79+
const source = await get_source(program.source);
80+
81+
let { path: sourcePath } = source;
82+
const { error: sourceError } = source;
9483

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

98+
// check root prompt.js
99+
const checkRootPrompt = await FSHelper.IsPathExists(
100+
`${sourcePath}/prompt.js`,
101+
);
102+
103+
if (sourcePath && !checkRootPrompt) {
104+
const projectTypes: Choice[] = [];
105+
106+
// get project types => react,nextjs,refine ...etc
107+
const files = await FSHelper.ReadDir(sourcePath);
108+
109+
for (const file of files) {
110+
const existPromptFile = await FSHelper.IsPathExists(
111+
`${sourcePath}/${file}/prompt.js`,
112+
);
113+
114+
if (existPromptFile) {
115+
projectTypes.push({
116+
title: file,
117+
value: file,
118+
});
119+
}
120+
}
121+
122+
const { projectType } = await prompts({
123+
type: "select",
124+
name: "projectType",
125+
message: "Select your project type",
126+
choices: projectTypes,
127+
});
128+
129+
sourcePath = `${sourcePath}/${projectType}`;
130+
}
131+
109132
const sao = new SAO({
110133
generator,
111134
outDir: projectDir,
@@ -114,10 +137,8 @@ const cli = async (): Promise<void> => {
114137
extras: {
115138
debug: !!program.debug,
116139
paths: {
117-
templateDir: templateDir(projectType),
118140
sourcePath,
119141
},
120-
projectType,
121142
},
122143
} as Options);
123144

src/saofile.ts

+3-16
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,20 @@ const saoConfig: GeneratorConfig = {
123123
process.exit(1);
124124
}
125125

126-
const { sourcePath, templateDir } = sao.opts.extras.paths;
127-
const { projectType } = sao.opts.extras;
126+
const { sourcePath } = sao.opts.extras.paths;
128127

129128
const actionsArray = [
130129
{
131130
type: "add",
132131
files: "**",
133-
templateDir,
132+
templateDir: path.join(sourcePath, "template"),
134133
data() {
135134
return sao.data;
136135
},
137136
},
138137
{
139138
type: "move",
140-
templateDir,
139+
templateDir: path.join(sourcePath, "template"),
141140
patterns: {
142141
gitignore: ".gitignore",
143142
"_package.json": "package.json",
@@ -151,18 +150,6 @@ const saoConfig: GeneratorConfig = {
151150
},
152151
] as Action[];
153152

154-
/**
155-
* Apply overrides to the template
156-
*/
157-
actionsArray.push({
158-
type: "add",
159-
files: "**",
160-
templateDir: path.join(sourcePath, "template"),
161-
data() {
162-
return sao.data;
163-
},
164-
});
165-
166153
const pluginAnswers = { ...sao.answers };
167154
delete pluginAnswers.name;
168155

templates/nextjs/.gitattributes

-1
This file was deleted.

templates/nextjs/LICENSE

-19
This file was deleted.

templates/nextjs/README.md

-45
This file was deleted.

templates/nextjs/_next-env.d.ts

-2
This file was deleted.

0 commit comments

Comments
 (0)