polen 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,70 +1,92 @@
|
|
|
1
1
|
import { Command } from '@molt/command';
|
|
2
|
-
import { Fs, Manifest, Name, Path, Str } from '@wollybeard/kit';
|
|
2
|
+
import { Err, Fs, Manifest, Name, Path, Str } from '@wollybeard/kit';
|
|
3
|
+
import * as Ansis from 'ansis';
|
|
3
4
|
import consola from 'consola';
|
|
4
5
|
import { z } from 'zod';
|
|
5
6
|
import { $ } from 'zx';
|
|
6
7
|
const Examples = z.enum([`github`, `pokemon`]);
|
|
7
8
|
const args = Command
|
|
8
9
|
.create()
|
|
9
|
-
.parameter(`name`, z.string().
|
|
10
|
+
.parameter(`name`, z.string().optional().describe(`The name of your project. Used by the package name and the default path. Defaults to a random name.`))
|
|
11
|
+
.parameter(`path`, z.string().optional().describe(`The path to a directory to create your project. Must point to an empty or non-existing directory. Defaults to a new directory named after your project in your cwd (current working directory).`))
|
|
10
12
|
.parameter(`link`, z.boolean().default(false).describe(`When installing polen, do so as a link. You must have Polen globally linked on your machine.`))
|
|
11
13
|
.parameter(`example`, Examples.default(`pokemon`).describe(`The example to use to scaffold your project.`))
|
|
14
|
+
.settings({
|
|
15
|
+
parameters: {
|
|
16
|
+
environment: {
|
|
17
|
+
$default: {
|
|
18
|
+
// todo prfix seting doesn't seem to work with Molt!
|
|
19
|
+
prefix: `POLEN_CREATE_`,
|
|
20
|
+
enabled: false,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
})
|
|
12
25
|
.parse();
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
consola.error(`Project root of name "${name}" already exists`);
|
|
26
|
+
const getProjectRoot = async () => {
|
|
27
|
+
if (args.path) {
|
|
28
|
+
const stat = await Fs.stat(args.path);
|
|
29
|
+
if (Fs.isNotFoundError(stat))
|
|
30
|
+
return args.path;
|
|
31
|
+
if (stat.isDirectory() && await Fs.isEmptyDir(args.path))
|
|
32
|
+
return args.path;
|
|
33
|
+
consola.error(`The given path ${args.path} already exists and is not an empty directory`);
|
|
22
34
|
process.exit(1);
|
|
23
35
|
}
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// Create temporary directory
|
|
37
|
-
const { stdout: tmpDir } = await $ `mktemp -d`;
|
|
38
|
-
const tmpDirPath = tmpDir.trim();
|
|
36
|
+
const findUsableName = async (isRetry) => {
|
|
37
|
+
const projectRoot = Path.join(process.cwd(), name + (isRetry ? `-${Date.now().toString(36).substring(2, 8)}` : ``));
|
|
38
|
+
const stat = await Fs.stat(projectRoot);
|
|
39
|
+
if (Fs.isNotFoundError(stat))
|
|
40
|
+
return projectRoot;
|
|
41
|
+
if (stat.isDirectory() && await Fs.isEmptyDir(projectRoot))
|
|
42
|
+
return projectRoot;
|
|
43
|
+
return await findUsableName(true);
|
|
44
|
+
};
|
|
45
|
+
return await findUsableName();
|
|
46
|
+
};
|
|
47
|
+
const copyGitRepositoryTemplate = async (input) => {
|
|
39
48
|
try {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
const tmpDirPath = await Fs.makeTemporaryDirectory();
|
|
50
|
+
const cleanup = async () => await $ `rm -rf ${tmpDirPath}`;
|
|
51
|
+
try {
|
|
52
|
+
// Clone only the specific example directory using sparse checkout
|
|
53
|
+
await $({
|
|
54
|
+
quiet: true,
|
|
55
|
+
}) `git clone --depth 1 --filter=blob:none --sparse ${input.repository.url.href} ${tmpDirPath}`;
|
|
56
|
+
await $ `cd ${tmpDirPath} && git sparse-checkout set ${input.repository.templatePath}`;
|
|
57
|
+
const templatePath = Path.join(tmpDirPath, input.repository.templatePath);
|
|
58
|
+
// Verify the example exists
|
|
59
|
+
if (!await Fs.exists(templatePath)) {
|
|
60
|
+
consola.error(`Example "${args.example}" not found in the Polen repository. Are you using the latest version of the CLI?`);
|
|
61
|
+
await cleanup();
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
await $ `mkdir -p ${input.destinationPath}`;
|
|
65
|
+
await $ `rsync -av ${templatePath}/ ${projectRoot}/`;
|
|
54
66
|
consola.success(`Your project is ready! Get Started:`);
|
|
55
67
|
}
|
|
68
|
+
finally {
|
|
69
|
+
await cleanup();
|
|
70
|
+
}
|
|
56
71
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
72
|
+
catch (error) {
|
|
73
|
+
consola.error(`Failed to scaffold example`);
|
|
74
|
+
Err.log(Err.ensure(error));
|
|
75
|
+
process.exit(1);
|
|
60
76
|
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
77
|
+
};
|
|
78
|
+
const name = Str.Case.kebab(args.name ?? Name.generate());
|
|
79
|
+
const projectRoot = await getProjectRoot();
|
|
80
|
+
console.log(``);
|
|
81
|
+
consola.info(`Creating your Polen project "${Ansis.greenBright(Str.Case.title(name))}"`);
|
|
82
|
+
consola.info(`Initializing with example "${Ansis.green(Str.Case.title(args.example))}"`);
|
|
83
|
+
await copyGitRepositoryTemplate({
|
|
84
|
+
repository: {
|
|
85
|
+
url: new URL(`https://github.com/the-guild-org/polen`),
|
|
86
|
+
templatePath: Path.join(`examples`, args.example),
|
|
87
|
+
},
|
|
88
|
+
destinationPath: projectRoot,
|
|
89
|
+
});
|
|
68
90
|
await Manifest.resource.update((manifest) => {
|
|
69
91
|
manifest.name = name;
|
|
70
92
|
manifest.description = `A new project`;
|
|
@@ -74,5 +96,5 @@ if (args.link) {
|
|
|
74
96
|
await $ `pnpm link polen`;
|
|
75
97
|
}
|
|
76
98
|
console.log(``);
|
|
77
|
-
console.log(`
|
|
99
|
+
console.log(Ansis.magenta(` cd ${Path.relative(process.cwd(), projectRoot)} && pnpm dev`));
|
|
78
100
|
//# sourceMappingURL=create.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/cli/commands/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/cli/commands/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AACpE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,OAAO,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,CAAC,EAAE,MAAM,IAAI,CAAA;AAEtB,MAAM,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAA;AAE9C,MAAM,IAAI,GAAG,OAAO;KACjB,MAAM,EAAE;KACR,SAAS,CACR,MAAM,EACN,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAC5B,qGAAqG,CACtG,CACF;KACA,SAAS,CACR,MAAM,EACN,CAAC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AAI,CAAC,OAAO,CAAC;KAClD;IACD,eAAe,EAAE,WAAW;CAC7B,CAAC,CAAA;AAEF,MAAM,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE;IAC1C,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAA;IACpB,QAAQ,CAAC,WAAW,GAAG,eAAe,CAAA;IACtC,QAAQ,CAAC,cAAc,GAAG,cAAc,CAAA;AAC1C,CAAC,EAAE,WAAW,CAAC,CAAA;AAEf,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,MAAM,CAAC,CAAA,iBAAiB,CAAA;AAC1B,CAAC;AAED,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;AACf,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A framework for delightful GraphQL developer portals",
|
|
6
6
|
"author": {
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@swc/core": "^1.11.29",
|
|
61
61
|
"@types/jsesc": "^3.0.3",
|
|
62
62
|
"@vitejs/plugin-react": "^4.4.1",
|
|
63
|
-
"@wollybeard/kit": "^0.
|
|
63
|
+
"@wollybeard/kit": "^0.26.1",
|
|
64
64
|
"@wollybeard/projector": "^0.1.0",
|
|
65
65
|
"ansis": "^4.0.0",
|
|
66
66
|
"consola": "^3.4.2",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Command } from '@molt/command'
|
|
2
|
-
import { Fs, Manifest, Name, Path, Str } from '@wollybeard/kit'
|
|
2
|
+
import { Err, Fs, Manifest, Name, Path, Str } from '@wollybeard/kit'
|
|
3
|
+
import * as Ansis from 'ansis'
|
|
3
4
|
import consola from 'consola'
|
|
4
5
|
import { z } from 'zod'
|
|
5
6
|
import { $ } from 'zx'
|
|
@@ -8,7 +9,18 @@ const Examples = z.enum([`github`, `pokemon`])
|
|
|
8
9
|
|
|
9
10
|
const args = Command
|
|
10
11
|
.create()
|
|
11
|
-
.parameter(
|
|
12
|
+
.parameter(
|
|
13
|
+
`name`,
|
|
14
|
+
z.string().optional().describe(
|
|
15
|
+
`The name of your project. Used by the package name and the default path. Defaults to a random name.`,
|
|
16
|
+
),
|
|
17
|
+
)
|
|
18
|
+
.parameter(
|
|
19
|
+
`path`,
|
|
20
|
+
z.string().optional().describe(
|
|
21
|
+
`The path to a directory to create your project. Must point to an empty or non-existing directory. Defaults to a new directory named after your project in your cwd (current working directory).`,
|
|
22
|
+
),
|
|
23
|
+
)
|
|
12
24
|
.parameter(
|
|
13
25
|
`link`,
|
|
14
26
|
z.boolean().default(false).describe(
|
|
@@ -16,73 +28,96 @@ const args = Command
|
|
|
16
28
|
),
|
|
17
29
|
)
|
|
18
30
|
.parameter(`example`, Examples.default(`pokemon`).describe(`The example to use to scaffold your project.`))
|
|
31
|
+
.settings({
|
|
32
|
+
parameters: {
|
|
33
|
+
environment: {
|
|
34
|
+
$default: {
|
|
35
|
+
// todo prfix seting doesn't seem to work with Molt!
|
|
36
|
+
prefix: `POLEN_CREATE_`,
|
|
37
|
+
enabled: false,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
})
|
|
19
42
|
.parse()
|
|
20
43
|
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const isProjectRootExists = await Fs.exists(projectRoot)
|
|
28
|
-
const isEmpty = isProjectRootExists && await Fs.isEmptyDir(projectRoot)
|
|
29
|
-
if (isProjectRootExists && !isEmpty) {
|
|
30
|
-
consola.error(`Project root of name "${name}" already exists`)
|
|
44
|
+
const getProjectRoot = async (): Promise<string> => {
|
|
45
|
+
if (args.path) {
|
|
46
|
+
const stat = await Fs.stat(args.path)
|
|
47
|
+
if (Fs.isNotFoundError(stat)) return args.path
|
|
48
|
+
if (stat.isDirectory() && await Fs.isEmptyDir(args.path)) return args.path
|
|
49
|
+
consola.error(`The given path ${args.path} already exists and is not an empty directory`)
|
|
31
50
|
process.exit(1)
|
|
32
51
|
}
|
|
33
|
-
consola.info(`creating your project in ./${name}`)
|
|
34
|
-
} else {
|
|
35
|
-
consola.info(`Current working directory is empty, creating your project here`)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Scaffold Example
|
|
39
52
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
const findUsableName = async (isRetry?: true): Promise<string> => {
|
|
54
|
+
const projectRoot = Path.join(process.cwd(), name + (isRetry ? `-${Date.now().toString(36).substring(2, 8)}` : ``))
|
|
55
|
+
const stat = await Fs.stat(projectRoot)
|
|
56
|
+
if (Fs.isNotFoundError(stat)) return projectRoot
|
|
57
|
+
if (stat.isDirectory() && await Fs.isEmptyDir(projectRoot)) return projectRoot
|
|
58
|
+
return await findUsableName(true)
|
|
59
|
+
}
|
|
46
60
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const { stdout: tmpDir } = await $`mktemp -d`
|
|
50
|
-
const tmpDirPath = tmpDir.trim()
|
|
61
|
+
return await findUsableName()
|
|
62
|
+
}
|
|
51
63
|
|
|
64
|
+
const copyGitRepositoryTemplate = async (input: {
|
|
65
|
+
repository: {
|
|
66
|
+
url: URL
|
|
67
|
+
templatePath: string
|
|
68
|
+
}
|
|
69
|
+
destinationPath: string
|
|
70
|
+
}): Promise<void> => {
|
|
52
71
|
try {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
72
|
+
const tmpDirPath = await Fs.makeTemporaryDirectory()
|
|
73
|
+
const cleanup = async () => await $`rm -rf ${tmpDirPath}`
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
// Clone only the specific example directory using sparse checkout
|
|
77
|
+
await $({
|
|
78
|
+
quiet: true,
|
|
79
|
+
})`git clone --depth 1 --filter=blob:none --sparse ${input.repository.url.href} ${tmpDirPath}`
|
|
80
|
+
await $`cd ${tmpDirPath} && git sparse-checkout set ${input.repository.templatePath}`
|
|
81
|
+
|
|
82
|
+
const templatePath = Path.join(tmpDirPath, input.repository.templatePath)
|
|
83
|
+
|
|
84
|
+
// Verify the example exists
|
|
85
|
+
if (!await Fs.exists(templatePath)) {
|
|
86
|
+
consola.error(
|
|
87
|
+
`Example "${args.example}" not found in the Polen repository. Are you using the latest version of the CLI?`,
|
|
88
|
+
)
|
|
89
|
+
await cleanup()
|
|
90
|
+
process.exit(1)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
await $`mkdir -p ${input.destinationPath}`
|
|
94
|
+
await $`rsync -av ${templatePath}/ ${projectRoot}/`
|
|
69
95
|
|
|
70
|
-
consola.success(`Done`)
|
|
71
|
-
|
|
72
|
-
if (!isCwdEmpty) {
|
|
73
96
|
consola.success(`Your project is ready! Get Started:`)
|
|
97
|
+
} finally {
|
|
98
|
+
await cleanup()
|
|
74
99
|
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
100
|
+
} catch (error) {
|
|
101
|
+
consola.error(`Failed to scaffold example`)
|
|
102
|
+
Err.log(Err.ensure(error))
|
|
103
|
+
process.exit(1)
|
|
78
104
|
}
|
|
79
|
-
} catch (error) {
|
|
80
|
-
consola.error(`Failed to scaffold example: ${error instanceof Error ? error.message : String(error)}`)
|
|
81
|
-
process.exit(1)
|
|
82
105
|
}
|
|
83
106
|
|
|
84
|
-
|
|
85
|
-
|
|
107
|
+
const name = Str.Case.kebab(args.name ?? Name.generate())
|
|
108
|
+
const projectRoot = await getProjectRoot()
|
|
109
|
+
|
|
110
|
+
console.log(``)
|
|
111
|
+
consola.info(`Creating your Polen project "${Ansis.greenBright(Str.Case.title(name))}"`)
|
|
112
|
+
|
|
113
|
+
consola.info(`Initializing with example "${Ansis.green(Str.Case.title(args.example))}"`)
|
|
114
|
+
await copyGitRepositoryTemplate({
|
|
115
|
+
repository: {
|
|
116
|
+
url: new URL(`https://github.com/the-guild-org/polen`),
|
|
117
|
+
templatePath: Path.join(`examples`, args.example),
|
|
118
|
+
},
|
|
119
|
+
destinationPath: projectRoot,
|
|
120
|
+
})
|
|
86
121
|
|
|
87
122
|
await Manifest.resource.update((manifest) => {
|
|
88
123
|
manifest.name = name
|
|
@@ -95,4 +130,4 @@ if (args.link) {
|
|
|
95
130
|
}
|
|
96
131
|
|
|
97
132
|
console.log(``)
|
|
98
|
-
console.log(`
|
|
133
|
+
console.log(Ansis.magenta(` cd ${Path.relative(process.cwd(), projectRoot)} && pnpm dev`))
|