create-foldkit-app 0.17.0 → 0.17.1
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.
package/dist/commands/create.js
CHANGED
|
@@ -60,10 +60,10 @@ const validateProject = (name, projectPath, packageManager) => Effect.gen(functi
|
|
|
60
60
|
return yield* Effect.fail(`Package manager '${packageManager}' is not available. Please install it first.`);
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
|
-
const setupProject = (name, projectPath, example) => Effect.gen(function* () {
|
|
63
|
+
const setupProject = (name, projectPath, example, packageManager) => Effect.gen(function* () {
|
|
64
64
|
yield* Console.log(chalk.blue('🚀 Creating your Foldkit app...'));
|
|
65
65
|
yield* Console.log('');
|
|
66
|
-
yield* createProject(name, projectPath, example);
|
|
66
|
+
yield* createProject(name, projectPath, example, packageManager);
|
|
67
67
|
yield* Console.log(chalk.green(`✅ Created project`));
|
|
68
68
|
yield* Console.log('');
|
|
69
69
|
});
|
|
@@ -118,7 +118,7 @@ export const create = (input) => Effect.gen(function* () {
|
|
|
118
118
|
const path = yield* Path.Path;
|
|
119
119
|
const projectPath = path.resolve(name);
|
|
120
120
|
yield* validateProject(name, projectPath, packageManager);
|
|
121
|
-
yield* setupProject(name, projectPath, example);
|
|
121
|
+
yield* setupProject(name, projectPath, example, packageManager);
|
|
122
122
|
yield* installProjectDependencies(projectPath, packageManager, example);
|
|
123
123
|
yield* displaySuccessMessage(name, packageManager);
|
|
124
124
|
return name;
|
package/dist/utils/files.js
CHANGED
|
@@ -2,18 +2,21 @@ import { Array, Effect, FileSystem, Match, Option, Path, Record, Ref, Schema, St
|
|
|
2
2
|
import { HttpClient, HttpClientRequest, } from 'effect/unstable/http';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
const GITHUB_API_BASE_URL = 'https://api.github.com/repos/foldkit/foldkit/contents/examples';
|
|
5
|
-
const
|
|
6
|
-
const fs = yield* FileSystem.FileSystem;
|
|
5
|
+
const getTemplateRoot = Effect.gen(function* () {
|
|
7
6
|
const path = yield* Path.Path;
|
|
8
7
|
const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
-
|
|
8
|
+
return path.resolve(currentDir, '..', '..', 'templates');
|
|
9
|
+
});
|
|
10
|
+
const getTemplateFiles = (templateDir) => Effect.gen(function* () {
|
|
11
|
+
const fs = yield* FileSystem.FileSystem;
|
|
12
|
+
const path = yield* Path.Path;
|
|
10
13
|
const fileContentByPath = yield* Ref.make({});
|
|
11
14
|
const processEntry = (dir) => (entry) => Effect.gen(function* () {
|
|
12
15
|
const fullPath = path.join(dir, entry);
|
|
13
16
|
const stat = yield* fs.stat(fullPath);
|
|
14
17
|
yield* Match.value(stat.type).pipe(Match.when('Directory', () => processDirectory(fullPath)), Match.when('File', () => Effect.gen(function* () {
|
|
15
18
|
const content = yield* fs.readFileString(fullPath);
|
|
16
|
-
const relativePath = path.relative(
|
|
19
|
+
const relativePath = path.relative(templateDir, fullPath);
|
|
17
20
|
yield* Ref.update(fileContentByPath, files => ({
|
|
18
21
|
...files,
|
|
19
22
|
[relativePath]: content,
|
|
@@ -26,20 +29,31 @@ const getBaseFiles = Effect.gen(function* () {
|
|
|
26
29
|
concurrency: 'unbounded',
|
|
27
30
|
});
|
|
28
31
|
});
|
|
29
|
-
yield* processDirectory(
|
|
32
|
+
yield* processDirectory(templateDir);
|
|
30
33
|
return yield* Ref.get(fileContentByPath);
|
|
31
34
|
});
|
|
32
|
-
|
|
33
|
-
yield*
|
|
34
|
-
yield*
|
|
35
|
-
yield*
|
|
35
|
+
const getBaseFiles = Effect.gen(function* () {
|
|
36
|
+
const path = yield* Path.Path;
|
|
37
|
+
const templateRoot = yield* getTemplateRoot;
|
|
38
|
+
return yield* getTemplateFiles(path.join(templateRoot, 'base'));
|
|
36
39
|
});
|
|
37
|
-
const
|
|
40
|
+
const getPackageManagerFiles = (packageManager) => Effect.gen(function* () {
|
|
38
41
|
const fs = yield* FileSystem.FileSystem;
|
|
39
42
|
const path = yield* Path.Path;
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
+
const templateRoot = yield* getTemplateRoot;
|
|
44
|
+
const templateDir = path.join(templateRoot, 'package-managers', packageManager);
|
|
45
|
+
const isTemplateDirectoryPresent = yield* fs.exists(templateDir);
|
|
46
|
+
if (isTemplateDirectoryPresent) {
|
|
47
|
+
return yield* getTemplateFiles(templateDir);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return {};
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const createFiles = (projectPath, files) => Effect.gen(function* () {
|
|
54
|
+
const fs = yield* FileSystem.FileSystem;
|
|
55
|
+
const path = yield* Path.Path;
|
|
56
|
+
yield* pipe(files, Record.toEntries, Effect.forEach(([filePath, content]) => Effect.gen(function* () {
|
|
43
57
|
const targetPath = Match.value(filePath).pipe(Match.when('gitignore', () => '.gitignore'), Match.when('ignore', () => '.ignore'), Match.orElse(() => filePath));
|
|
44
58
|
const fullPath = path.join(projectPath, targetPath);
|
|
45
59
|
const dirPath = path.dirname(fullPath);
|
|
@@ -47,11 +61,29 @@ const createBaseFiles = (projectPath) => Effect.gen(function* () {
|
|
|
47
61
|
yield* fs.writeFileString(fullPath, content);
|
|
48
62
|
}), { concurrency: 'unbounded' }));
|
|
49
63
|
});
|
|
64
|
+
const createBaseFiles = (projectPath) => Effect.gen(function* () {
|
|
65
|
+
const fs = yield* FileSystem.FileSystem;
|
|
66
|
+
yield* fs.makeDirectory(projectPath, { recursive: true });
|
|
67
|
+
const baseFiles = yield* getBaseFiles;
|
|
68
|
+
yield* createFiles(projectPath, baseFiles);
|
|
69
|
+
});
|
|
70
|
+
const createPackageManagerFiles = (projectPath, packageManager) => Effect.gen(function* () {
|
|
71
|
+
const packageManagerFiles = yield* getPackageManagerFiles(packageManager);
|
|
72
|
+
yield* createFiles(projectPath, packageManagerFiles);
|
|
73
|
+
});
|
|
74
|
+
export const createProject = (name, projectPath, example, packageManager) => Effect.gen(function* () {
|
|
75
|
+
yield* createBaseFiles(projectPath);
|
|
76
|
+
yield* modifyBaseFiles(projectPath, name);
|
|
77
|
+
yield* createPackageManagerFiles(projectPath, packageManager);
|
|
78
|
+
yield* createExampleFiles(projectPath, example);
|
|
79
|
+
});
|
|
50
80
|
const modifyBaseFiles = (projectPath, name) => Effect.gen(function* () {
|
|
51
81
|
const fs = yield* FileSystem.FileSystem;
|
|
52
82
|
const path = yield* Path.Path;
|
|
53
83
|
const packageJsonPath = path.join(projectPath, 'package.json');
|
|
54
|
-
|
|
84
|
+
const content = yield* fs.readFileString(packageJsonPath);
|
|
85
|
+
const updatedContent = String.replace('my-foldkit-app', name)(content);
|
|
86
|
+
yield* fs.writeFileString(packageJsonPath, updatedContent);
|
|
55
87
|
});
|
|
56
88
|
const GitHubFileEntry = Schema.Struct({
|
|
57
89
|
name: Schema.String,
|
package/package.json
CHANGED