@jakubmazanec/carson-templates 0.1.0-265acad → 0.1.0-2f12db0
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/main.d.ts +8 -4
- package/dist/main.js +97 -11
- package/dist/main.js.map +1 -1
- package/package.json +7 -5
- package/src/main.ts +105 -13
- package/templates/projects/carson-templates/.swcrc.ejs +28 -0
- package/templates/projects/carson-templates/README.md.insert.header.ejs +12 -0
- package/templates/projects/carson-templates/config.json +4 -0
- package/templates/projects/carson-templates/jest.config.ts.ejs +30 -0
- package/templates/projects/carson-templates/package.json.create.ejs +15 -0
- package/templates/projects/carson-templates/package.json.ejs +36 -0
- package/templates/projects/carson-templates/src/main.ts.check.ejs +5 -0
- package/templates/projects/carson-templates/src/main.ts.create.ejs +4 -0
- package/templates/projects/carson-templates/tests/tsconfig.json.ejs +17 -0
- package/templates/projects/carson-templates/tsconfig.json.ejs +14 -0
- package/templates/projects/carson-templates/tsconfig.typecheck.json.ejs +14 -0
- package/templates/projects/carson-templates/typedoc.config.cjs.ejs +12 -0
- package/templates/projects/changesets-changelog/.swcrc.ejs +30 -0
- package/templates/projects/changesets-changelog/README.md.insert.header.ejs +12 -0
- package/templates/projects/changesets-changelog/config.json +4 -0
- package/templates/projects/changesets-changelog/jest.config.ts.ejs +24 -0
- package/templates/projects/changesets-changelog/package.json.create.ejs +15 -0
- package/templates/projects/changesets-changelog/package.json.ejs +28 -0
- package/templates/projects/changesets-changelog/src/main.ts.check.ejs +5 -0
- package/templates/projects/changesets-changelog/src/main.ts.create.ejs +4 -0
- package/templates/projects/changesets-changelog/tests/tsconfig.json.ejs +17 -0
- package/templates/projects/changesets-changelog/tsconfig.json.ejs +14 -0
- package/templates/projects/changesets-changelog/tsconfig.typecheck.json.ejs +15 -0
- package/templates/projects/eslint-config/.swcrc.ejs +30 -0
- package/templates/projects/eslint-config/README.md.insert.header.ejs +12 -0
- package/templates/projects/eslint-config/config.json +4 -0
- package/templates/projects/eslint-config/jest.config.ts.ejs +24 -0
- package/templates/projects/eslint-config/package.json.create.ejs +15 -0
- package/templates/projects/eslint-config/package.json.ejs +33 -0
- package/templates/projects/eslint-config/src/main.ts.check.ejs +5 -0
- package/templates/projects/eslint-config/src/main.ts.create.ejs +4 -0
- package/templates/projects/eslint-config/tests/tsconfig.json.ejs +17 -0
- package/templates/projects/eslint-config/tsconfig.json.ejs +14 -0
- package/templates/projects/eslint-config/tsconfig.typecheck.json.ejs +14 -0
- package/templates/projects/library/.swcrc.ejs +28 -0
- package/templates/projects/library/README.md.insert.header.ejs +12 -0
- package/templates/projects/library/config.json +4 -0
- package/templates/projects/library/jest.config.ts.ejs +30 -0
- package/templates/projects/library/package.json.create.ejs +15 -0
- package/templates/projects/library/package.json.ejs +37 -0
- package/templates/projects/library/src/main.ts.check.ejs +5 -0
- package/templates/projects/library/src/main.ts.create.ejs +4 -0
- package/templates/projects/library/tests/tsconfig.json.ejs +17 -0
- package/templates/projects/library/tsconfig.json.ejs +14 -0
- package/templates/projects/library/tsconfig.typecheck.json.ejs +14 -0
- package/templates/projects/library/typedoc.config.cjs.ejs +12 -0
- package/templates/workspace/.changeset/config.json.ejs +28 -0
- package/templates/workspace/.editorconfig.ejs +20 -0
- package/templates/workspace/.eslintrc.cjs.ejs +25 -0
- package/templates/workspace/.github/workflows/merge-to-main-branch.yaml.ejs +53 -0
- package/templates/workspace/.github/workflows/pull-request.yaml.ejs +61 -0
- package/templates/workspace/.github/workflows/release.yaml.ejs +308 -0
- package/templates/workspace/.gitignore.ejs +249 -0
- package/templates/workspace/.prettierignore.ejs +14 -0
- package/templates/workspace/README.md.insert.ejs +10 -0
- package/templates/workspace/config.json +4 -0
- package/templates/workspace/package.json.create.ejs +10 -0
- package/templates/workspace/package.json.ejs +69 -0
- package/templates/workspace/prettier.config.js.ejs +19 -0
- package/templates/workspace/tsconfig.options.json.ejs +24 -0
- package/templates/workspace/tsconfig.typecheck.json.ejs +13 -0
- package/templates/workspace/turbo.json.ejs +54 -0
package/dist/main.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { type Workspace } from '@jakubmazanec/carson';
|
|
1
|
+
import { type Project, type Workspace } from '@jakubmazanec/carson';
|
|
2
2
|
export { default as lodash } from 'lodash';
|
|
3
|
+
export { default as semver } from 'semver';
|
|
4
|
+
export declare function getMainBranch(workspace: Workspace | Workspace<false>): string | undefined;
|
|
5
|
+
export declare function getDevelopmentBranch(workspace: Workspace | Workspace<false>): string | undefined;
|
|
3
6
|
export declare function getMajorVersion(version: string): number;
|
|
4
|
-
export declare function getDependencies(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
export declare function getDependencies(dependencies: string[], workspace: Workspace | Workspace<false>): Record<string, string>;
|
|
8
|
+
export declare function getReferences(workspace: Workspace | Workspace<false>, project: Project | Project<false>): {
|
|
9
|
+
path: string;
|
|
10
|
+
}[];
|
package/dist/main.js
CHANGED
|
@@ -1,30 +1,116 @@
|
|
|
1
|
+
import semver from 'semver';
|
|
1
2
|
export { default as lodash } from 'lodash';
|
|
3
|
+
export { default as semver } from 'semver';
|
|
4
|
+
const MAIN_BRANCH_NAMES = new Set([
|
|
5
|
+
'main',
|
|
6
|
+
'master'
|
|
7
|
+
]);
|
|
8
|
+
const DEVELOPMENT_BRANCH_NAMES = new Set([
|
|
9
|
+
'development',
|
|
10
|
+
'develop',
|
|
11
|
+
'dev'
|
|
12
|
+
]);
|
|
13
|
+
const DEPENDENCY_VERSIONS = {
|
|
14
|
+
'@changesets/cli': '^2.0.0',
|
|
15
|
+
'@jakubmazanec/carson': '^0.0.0',
|
|
16
|
+
'@jakubmazanec/carson-templates': '^0.0.0',
|
|
17
|
+
'@jest/globals': '^29.0.0',
|
|
18
|
+
'@swc/cli': '^0.1.0',
|
|
19
|
+
'@swc/core': '^1.0.0',
|
|
20
|
+
'@testing-library/jest-dom': '^5.0.0',
|
|
21
|
+
'@types/node': '^16.0.0',
|
|
22
|
+
chokidar: '^3.0.0',
|
|
23
|
+
'cross-env': '^7.0.0',
|
|
24
|
+
'del-cli': '^5.0.0',
|
|
25
|
+
eslint: '^8.0.0',
|
|
26
|
+
jest: '^29.0.0',
|
|
27
|
+
'patch-package': '^6.0.0',
|
|
28
|
+
prettier: '^2.0.0',
|
|
29
|
+
'prettier-plugin-packagejson': '^2.0.0',
|
|
30
|
+
'ts-jest': '^29.0.0',
|
|
31
|
+
'ts-node': '^10.0.0',
|
|
32
|
+
turbo: '^1.0.0',
|
|
33
|
+
typedoc: '^0.24.0',
|
|
34
|
+
'typedoc-plugin-markdown': '^3.0.0',
|
|
35
|
+
typescript: '^5.0.0'
|
|
36
|
+
};
|
|
37
|
+
export function getMainBranch(workspace) {
|
|
38
|
+
var _workspace_repository;
|
|
39
|
+
for (let branch of ((_workspace_repository = workspace.repository) === null || _workspace_repository === void 0 ? void 0 : _workspace_repository.branches) ?? []){
|
|
40
|
+
if (MAIN_BRANCH_NAMES.has(branch)) {
|
|
41
|
+
return branch;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
export function getDevelopmentBranch(workspace) {
|
|
47
|
+
var _workspace_repository;
|
|
48
|
+
for (let branch of ((_workspace_repository = workspace.repository) === null || _workspace_repository === void 0 ? void 0 : _workspace_repository.branches) ?? []){
|
|
49
|
+
if (DEVELOPMENT_BRANCH_NAMES.has(branch)) {
|
|
50
|
+
return branch;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
2
55
|
export function getMajorVersion(version) {
|
|
3
56
|
return Number(version.split('.')[0].replace(/\D/, ''));
|
|
4
57
|
}
|
|
5
|
-
export function getDependencies(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
58
|
+
export function getDependencies(dependencies, workspace) {
|
|
59
|
+
const result = {};
|
|
60
|
+
for (const dependency of dependencies){
|
|
61
|
+
const version = DEPENDENCY_VERSIONS[dependency];
|
|
62
|
+
if (version) {
|
|
63
|
+
result[dependency] = version;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const projectNames = workspace.projects.map((project)=>project.name);
|
|
67
|
+
for (const [dependencyName, dependencyVersion] of Object.entries(result)){
|
|
68
|
+
const installedDependency = workspace.allDependencies.find((dependency)=>dependencyName === dependency.name);
|
|
12
69
|
// if the dependency is already installed in the workspace, we might want to use that existing version
|
|
13
70
|
if (installedDependency) {
|
|
14
|
-
|
|
71
|
+
const version = [
|
|
15
72
|
...installedDependency.exactVersions
|
|
16
73
|
].sort().reverse()[0];
|
|
17
74
|
// if the dependency is actually a project in the workspace, we use existing version
|
|
18
75
|
if (projectNames.includes(dependencyName)) {
|
|
19
|
-
|
|
76
|
+
var _semver_prerelease;
|
|
77
|
+
if ((_semver_prerelease = semver.prerelease(version)) === null || _semver_prerelease === void 0 ? void 0 : _semver_prerelease.length) {
|
|
78
|
+
result[dependencyName] = version;
|
|
79
|
+
} else {
|
|
80
|
+
result[dependencyName] = `^${version}`;
|
|
81
|
+
}
|
|
20
82
|
}
|
|
21
83
|
// we use existing version only if major versions match; we don't want the user of this template to be able to overwrite any major version number and use potentially incompatible version
|
|
22
84
|
if (getMajorVersion(version) === getMajorVersion(dependencyVersion)) {
|
|
23
|
-
|
|
85
|
+
var _semver_prerelease1;
|
|
86
|
+
if ((_semver_prerelease1 = semver.prerelease(version)) === null || _semver_prerelease1 === void 0 ? void 0 : _semver_prerelease1.length) {
|
|
87
|
+
result[dependencyName] = version;
|
|
88
|
+
} else {
|
|
89
|
+
result[dependencyName] = `^${version}`;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
export function getReferences(workspace, project) {
|
|
97
|
+
let references = [];
|
|
98
|
+
let currentProject = project;
|
|
99
|
+
for (let dependency of workspace.allDependencies){
|
|
100
|
+
for (let project of workspace.projects){
|
|
101
|
+
if (dependency.name === project.name) {
|
|
102
|
+
for (let dependencyProject of dependency.projects){
|
|
103
|
+
if (dependencyProject.name === currentProject.name) {
|
|
104
|
+
references.push({
|
|
105
|
+
path: `${currentProject.relativePath.split('/').map(()=>'..').join('/')}/${project.relativePath}`
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
24
109
|
}
|
|
25
110
|
}
|
|
26
111
|
}
|
|
27
|
-
|
|
112
|
+
references.sort((a, b)=>a.path.localeCompare(b.path));
|
|
113
|
+
return references;
|
|
28
114
|
}
|
|
29
115
|
|
|
30
116
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/main.ts"],"sourcesContent":["import {type Workspace} from '@jakubmazanec/carson';\n\nexport {default as lodash} from 'lodash';\n\nexport function getMajorVersion(version: string) {\n return Number(version.split('.')[0]!.replace(/\\D/, ''));\n}\n\nexport function getDependencies(
|
|
1
|
+
{"version":3,"sources":["../src/main.ts"],"sourcesContent":["import {type Project, type Workspace} from '@jakubmazanec/carson';\nimport semver from 'semver';\n\nexport {default as lodash} from 'lodash';\nexport {default as semver} from 'semver';\n\nconst MAIN_BRANCH_NAMES = new Set(['main', 'master']);\nconst DEVELOPMENT_BRANCH_NAMES = new Set(['development', 'develop', 'dev']);\n\nconst DEPENDENCY_VERSIONS: Record<string, string> = {\n '@changesets/cli': '^2.0.0',\n '@jakubmazanec/carson': '^0.0.0',\n '@jakubmazanec/carson-templates': '^0.0.0',\n '@jest/globals': '^29.0.0',\n '@swc/cli': '^0.1.0',\n '@swc/core': '^1.0.0',\n '@testing-library/jest-dom': '^5.0.0',\n '@types/node': '^16.0.0',\n chokidar: '^3.0.0',\n 'cross-env': '^7.0.0',\n 'del-cli': '^5.0.0',\n eslint: '^8.0.0',\n jest: '^29.0.0',\n 'patch-package': '^6.0.0',\n prettier: '^2.0.0',\n 'prettier-plugin-packagejson': '^2.0.0',\n 'ts-jest': '^29.0.0',\n 'ts-node': '^10.0.0',\n turbo: '^1.0.0',\n typedoc: '^0.24.0',\n 'typedoc-plugin-markdown': '^3.0.0',\n typescript: '^5.0.0',\n};\n\nexport function getMainBranch(workspace: Workspace | Workspace<false>) {\n for (let branch of workspace.repository?.branches ?? []) {\n if (MAIN_BRANCH_NAMES.has(branch)) {\n return branch;\n }\n }\n\n return undefined;\n}\n\nexport function getDevelopmentBranch(workspace: Workspace | Workspace<false>) {\n for (let branch of workspace.repository?.branches ?? []) {\n if (DEVELOPMENT_BRANCH_NAMES.has(branch)) {\n return branch;\n }\n }\n\n return undefined;\n}\n\nexport function getMajorVersion(version: string) {\n return Number(version.split('.')[0]!.replace(/\\D/, ''));\n}\n\nexport function getDependencies(dependencies: string[], workspace: Workspace | Workspace<false>) {\n const result: Record<string, string> = {};\n\n for (const dependency of dependencies) {\n const version = DEPENDENCY_VERSIONS[dependency];\n\n if (version) {\n result[dependency] = version;\n }\n }\n\n const projectNames = workspace.projects.map((project) => project.name);\n\n for (const [dependencyName, dependencyVersion] of Object.entries(result)) {\n const installedDependency = workspace.allDependencies.find(\n (dependency) => dependencyName === dependency.name,\n );\n\n // if the dependency is already installed in the workspace, we might want to use that existing version\n if (installedDependency) {\n const version = [...installedDependency.exactVersions].sort().reverse()[0] as string;\n\n // if the dependency is actually a project in the workspace, we use existing version\n if (projectNames.includes(dependencyName)) {\n if (semver.prerelease(version)?.length) {\n result[dependencyName] = version;\n } else {\n result[dependencyName] = `^${version}`;\n }\n }\n\n // we use existing version only if major versions match; we don't want the user of this template to be able to overwrite any major version number and use potentially incompatible version\n if (getMajorVersion(version) === getMajorVersion(dependencyVersion)) {\n if (semver.prerelease(version)?.length) {\n result[dependencyName] = version;\n } else {\n result[dependencyName] = `^${version}`;\n }\n }\n }\n }\n\n return result;\n}\n\nexport function getReferences(\n workspace: Workspace | Workspace<false>,\n project: Project | Project<false>,\n) {\n let references = [];\n let currentProject = project;\n\n for (let dependency of workspace.allDependencies) {\n for (let project of workspace.projects) {\n if (dependency.name === project.name) {\n for (let dependencyProject of dependency.projects) {\n if (dependencyProject.name === currentProject.name) {\n references.push({\n path: `${currentProject.relativePath\n .split('/')\n .map(() => '..')\n .join('/')}/${project.relativePath}`,\n });\n }\n }\n }\n }\n }\n\n references.sort((a, b) => a.path.localeCompare(b.path));\n\n return references;\n}\n"],"names":["semver","default","lodash","MAIN_BRANCH_NAMES","Set","DEVELOPMENT_BRANCH_NAMES","DEPENDENCY_VERSIONS","chokidar","eslint","jest","prettier","turbo","typedoc","typescript","getMainBranch","workspace","branch","repository","branches","has","undefined","getDevelopmentBranch","getMajorVersion","version","Number","split","replace","getDependencies","dependencies","result","dependency","projectNames","projects","map","project","name","dependencyName","dependencyVersion","Object","entries","installedDependency","allDependencies","find","exactVersions","sort","reverse","includes","prerelease","length","getReferences","references","currentProject","dependencyProject","push","path","relativePath","join","a","b","localeCompare"],"mappings":"AACA,OAAOA,YAAY,SAAS;AAE5B,SAAQC,WAAWC,MAAM,QAAO,SAAS;AACzC,SAAQD,WAAWD,MAAM,QAAO,SAAS;AAEzC,MAAMG,oBAAoB,IAAIC,IAAI;IAAC;IAAQ;CAAS;AACpD,MAAMC,2BAA2B,IAAID,IAAI;IAAC;IAAe;IAAW;CAAM;AAE1E,MAAME,sBAA8C;IAClD,mBAAmB;IACnB,wBAAwB;IACxB,kCAAkC;IAClC,iBAAiB;IACjB,YAAY;IACZ,aAAa;IACb,6BAA6B;IAC7B,eAAe;IACfC,UAAU;IACV,aAAa;IACb,WAAW;IACXC,QAAQ;IACRC,MAAM;IACN,iBAAiB;IACjBC,UAAU;IACV,+BAA+B;IAC/B,WAAW;IACX,WAAW;IACXC,OAAO;IACPC,SAAS;IACT,2BAA2B;IAC3BC,YAAY;AACd;AAEA,OAAO,SAASC,cAAcC,SAAuC;QAChDA;IAAnB,KAAK,IAAIC,UAAUD,EAAAA,wBAAAA,UAAUE,UAAU,cAApBF,4CAAAA,sBAAs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|
|
3
|
+
"version": "0.1.0-2f12db0",
|
|
4
4
|
"description": "Collection of Carson templates.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "
|
|
7
|
+
"url": "git@github.com:jakubmazanec/js-tools.git",
|
|
8
8
|
"directory": "packages/carson-templates"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"dist",
|
|
20
|
-
"src"
|
|
20
|
+
"src",
|
|
21
|
+
"templates"
|
|
21
22
|
],
|
|
22
23
|
"scripts": {
|
|
23
24
|
"build": "swc src -d dist && tsc",
|
|
@@ -29,8 +30,9 @@
|
|
|
29
30
|
"typecheck": "tsc --project tsconfig.typecheck.json"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
|
-
"@jakubmazanec/carson": "0.1.0-
|
|
33
|
-
"lodash": "^4.17.21"
|
|
33
|
+
"@jakubmazanec/carson": "0.1.0-2f12db0",
|
|
34
|
+
"lodash": "^4.17.21",
|
|
35
|
+
"semver": "^7.3.6"
|
|
34
36
|
},
|
|
35
37
|
"devDependencies": {
|
|
36
38
|
"@jest/globals": "^29.5.0",
|
package/src/main.ts
CHANGED
|
@@ -1,39 +1,131 @@
|
|
|
1
|
-
import {type Workspace} from '@jakubmazanec/carson';
|
|
1
|
+
import {type Project, type Workspace} from '@jakubmazanec/carson';
|
|
2
|
+
import semver from 'semver';
|
|
2
3
|
|
|
3
4
|
export {default as lodash} from 'lodash';
|
|
5
|
+
export {default as semver} from 'semver';
|
|
6
|
+
|
|
7
|
+
const MAIN_BRANCH_NAMES = new Set(['main', 'master']);
|
|
8
|
+
const DEVELOPMENT_BRANCH_NAMES = new Set(['development', 'develop', 'dev']);
|
|
9
|
+
|
|
10
|
+
const DEPENDENCY_VERSIONS: Record<string, string> = {
|
|
11
|
+
'@changesets/cli': '^2.0.0',
|
|
12
|
+
'@jakubmazanec/carson': '^0.0.0',
|
|
13
|
+
'@jakubmazanec/carson-templates': '^0.0.0',
|
|
14
|
+
'@jest/globals': '^29.0.0',
|
|
15
|
+
'@swc/cli': '^0.1.0',
|
|
16
|
+
'@swc/core': '^1.0.0',
|
|
17
|
+
'@testing-library/jest-dom': '^5.0.0',
|
|
18
|
+
'@types/node': '^16.0.0',
|
|
19
|
+
chokidar: '^3.0.0',
|
|
20
|
+
'cross-env': '^7.0.0',
|
|
21
|
+
'del-cli': '^5.0.0',
|
|
22
|
+
eslint: '^8.0.0',
|
|
23
|
+
jest: '^29.0.0',
|
|
24
|
+
'patch-package': '^6.0.0',
|
|
25
|
+
prettier: '^2.0.0',
|
|
26
|
+
'prettier-plugin-packagejson': '^2.0.0',
|
|
27
|
+
'ts-jest': '^29.0.0',
|
|
28
|
+
'ts-node': '^10.0.0',
|
|
29
|
+
turbo: '^1.0.0',
|
|
30
|
+
typedoc: '^0.24.0',
|
|
31
|
+
'typedoc-plugin-markdown': '^3.0.0',
|
|
32
|
+
typescript: '^5.0.0',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export function getMainBranch(workspace: Workspace | Workspace<false>) {
|
|
36
|
+
for (let branch of workspace.repository?.branches ?? []) {
|
|
37
|
+
if (MAIN_BRANCH_NAMES.has(branch)) {
|
|
38
|
+
return branch;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getDevelopmentBranch(workspace: Workspace | Workspace<false>) {
|
|
46
|
+
for (let branch of workspace.repository?.branches ?? []) {
|
|
47
|
+
if (DEVELOPMENT_BRANCH_NAMES.has(branch)) {
|
|
48
|
+
return branch;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
4
54
|
|
|
5
55
|
export function getMajorVersion(version: string) {
|
|
6
56
|
return Number(version.split('.')[0]!.replace(/\D/, ''));
|
|
7
57
|
}
|
|
8
58
|
|
|
9
|
-
export function getDependencies(
|
|
10
|
-
|
|
11
|
-
workspace: Workspace | Workspace<false>,
|
|
12
|
-
) {
|
|
13
|
-
let dependencies = {...defaultDependencies};
|
|
59
|
+
export function getDependencies(dependencies: string[], workspace: Workspace | Workspace<false>) {
|
|
60
|
+
const result: Record<string, string> = {};
|
|
14
61
|
|
|
15
|
-
|
|
62
|
+
for (const dependency of dependencies) {
|
|
63
|
+
const version = DEPENDENCY_VERSIONS[dependency];
|
|
16
64
|
|
|
17
|
-
|
|
18
|
-
|
|
65
|
+
if (version) {
|
|
66
|
+
result[dependency] = version;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const projectNames = workspace.projects.map((project) => project.name);
|
|
71
|
+
|
|
72
|
+
for (const [dependencyName, dependencyVersion] of Object.entries(result)) {
|
|
73
|
+
const installedDependency = workspace.allDependencies.find(
|
|
19
74
|
(dependency) => dependencyName === dependency.name,
|
|
20
75
|
);
|
|
21
76
|
|
|
22
77
|
// if the dependency is already installed in the workspace, we might want to use that existing version
|
|
23
78
|
if (installedDependency) {
|
|
24
|
-
|
|
79
|
+
const version = [...installedDependency.exactVersions].sort().reverse()[0] as string;
|
|
25
80
|
|
|
26
81
|
// if the dependency is actually a project in the workspace, we use existing version
|
|
27
82
|
if (projectNames.includes(dependencyName)) {
|
|
28
|
-
|
|
83
|
+
if (semver.prerelease(version)?.length) {
|
|
84
|
+
result[dependencyName] = version;
|
|
85
|
+
} else {
|
|
86
|
+
result[dependencyName] = `^${version}`;
|
|
87
|
+
}
|
|
29
88
|
}
|
|
30
89
|
|
|
31
90
|
// we use existing version only if major versions match; we don't want the user of this template to be able to overwrite any major version number and use potentially incompatible version
|
|
32
91
|
if (getMajorVersion(version) === getMajorVersion(dependencyVersion)) {
|
|
33
|
-
|
|
92
|
+
if (semver.prerelease(version)?.length) {
|
|
93
|
+
result[dependencyName] = version;
|
|
94
|
+
} else {
|
|
95
|
+
result[dependencyName] = `^${version}`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function getReferences(
|
|
105
|
+
workspace: Workspace | Workspace<false>,
|
|
106
|
+
project: Project | Project<false>,
|
|
107
|
+
) {
|
|
108
|
+
let references = [];
|
|
109
|
+
let currentProject = project;
|
|
110
|
+
|
|
111
|
+
for (let dependency of workspace.allDependencies) {
|
|
112
|
+
for (let project of workspace.projects) {
|
|
113
|
+
if (dependency.name === project.name) {
|
|
114
|
+
for (let dependencyProject of dependency.projects) {
|
|
115
|
+
if (dependencyProject.name === currentProject.name) {
|
|
116
|
+
references.push({
|
|
117
|
+
path: `${currentProject.relativePath
|
|
118
|
+
.split('/')
|
|
119
|
+
.map(() => '..')
|
|
120
|
+
.join('/')}/${project.relativePath}`,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
34
124
|
}
|
|
35
125
|
}
|
|
36
126
|
}
|
|
37
127
|
|
|
38
|
-
|
|
128
|
+
references.sort((a, b) => a.path.localeCompare(b.path));
|
|
129
|
+
|
|
130
|
+
return references;
|
|
39
131
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: '.swcrc'
|
|
3
|
+
strategy: overwrite
|
|
4
|
+
---
|
|
5
|
+
{
|
|
6
|
+
"jsc": {
|
|
7
|
+
"parser": {
|
|
8
|
+
"syntax": "typescript",
|
|
9
|
+
"tsx": true,
|
|
10
|
+
"dynamicImport": true
|
|
11
|
+
},
|
|
12
|
+
"transform": {
|
|
13
|
+
"react": {
|
|
14
|
+
"runtime": "automatic"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"target": "es2022"
|
|
18
|
+
},
|
|
19
|
+
"module": {
|
|
20
|
+
"type": "es6"
|
|
21
|
+
},
|
|
22
|
+
"env": {
|
|
23
|
+
"targets": {
|
|
24
|
+
"node": 16
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"sourceMaps": true
|
|
28
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: 'jest.config.ts'
|
|
3
|
+
strategy: overwrite
|
|
4
|
+
---
|
|
5
|
+
export default {
|
|
6
|
+
preset: 'ts-jest/presets/default-esm',
|
|
7
|
+
globals: {
|
|
8
|
+
'ts-jest': {
|
|
9
|
+
useESM: true,
|
|
10
|
+
isolatedModules: true,
|
|
11
|
+
tsconfig: 'tsconfig.typecheck.json',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
extensionsToTreatAsEsm: ['.ts', '.tsx'],
|
|
15
|
+
moduleNameMapper: {
|
|
16
|
+
'^(\\.{1,2}/.*)\\.js$': '$1',
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
collectCoverage: true,
|
|
20
|
+
coverageDirectory: '<rootDir>/coverage/',
|
|
21
|
+
collectCoverageFrom: ['<rootDir>/src/**/*.{ts,tsx}'],
|
|
22
|
+
coverageThreshold: {
|
|
23
|
+
global: {
|
|
24
|
+
branches: 0,
|
|
25
|
+
functions: 0,
|
|
26
|
+
lines: 0,
|
|
27
|
+
statements: 0,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: 'package.json'
|
|
3
|
+
strategy: create
|
|
4
|
+
---
|
|
5
|
+
{
|
|
6
|
+
"name": "<%- project.name %>",
|
|
7
|
+
"version": "0.0.0",
|
|
8
|
+
"description": "",
|
|
9
|
+
"repository": {
|
|
10
|
+
"url": "<%- workspace.repository?.url ?? '' %>"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "Jakub Mazanec <jakub@mazanec.dev>",
|
|
14
|
+
"sideEffects": false
|
|
15
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: 'package.json'
|
|
3
|
+
strategy: merge
|
|
4
|
+
---
|
|
5
|
+
{
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"directory": "<%- project.relativePath %>"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./dist/main.js",
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src",
|
|
18
|
+
"templates"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "swc src -d dist && tsc",
|
|
22
|
+
"clean": "del-cli dist *.tsbuildinfo",
|
|
23
|
+
"document": "typedoc --options typedoc.config.cjs",
|
|
24
|
+
"format": "prettier . --write --ignore-unknown --ignore-path ../../.prettierignore",
|
|
25
|
+
"lint": "eslint .",
|
|
26
|
+
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests",
|
|
27
|
+
"typecheck": "tsc --project tsconfig.typecheck.json"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@jest/globals": "^29.5.0"
|
|
31
|
+
},
|
|
32
|
+
"packageManager": "npm@8.19.4",
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=16.20.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: 'tests/tsconfig.json'
|
|
3
|
+
strategy: overwrite
|
|
4
|
+
---
|
|
5
|
+
{
|
|
6
|
+
"extends": "../../../tsconfig.options.json",
|
|
7
|
+
"compilerOptions": {
|
|
8
|
+
"composite": false,
|
|
9
|
+
"noEmit": true
|
|
10
|
+
},
|
|
11
|
+
"include": ["./**/*"],
|
|
12
|
+
"references": [
|
|
13
|
+
{
|
|
14
|
+
"path": ".."
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: 'tsconfig.json'
|
|
3
|
+
strategy: overwrite
|
|
4
|
+
---
|
|
5
|
+
{
|
|
6
|
+
"extends": "../../tsconfig.options.json",
|
|
7
|
+
"compilerOptions": {
|
|
8
|
+
"emitDeclarationOnly": true,
|
|
9
|
+
"outDir": "./dist",
|
|
10
|
+
"rootDir": "./src"
|
|
11
|
+
},
|
|
12
|
+
"include": ["./src/**/*"],
|
|
13
|
+
"references": <%- JSON.stringify(getReferences(workspace, project), null, 2) %>
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: 'tsconfig.typecheck.json'
|
|
3
|
+
strategy: overwrite
|
|
4
|
+
---
|
|
5
|
+
{
|
|
6
|
+
"extends": "./tsconfig.json",
|
|
7
|
+
"compilerOptions": {
|
|
8
|
+
"composite": false,
|
|
9
|
+
"emitDeclarationOnly": false,
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"rootDir": "."
|
|
12
|
+
},
|
|
13
|
+
"include": ["./src/**/*", "./tests/**/*", "./*"]
|
|
14
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: '.swcrc'
|
|
3
|
+
strategy: overwrite
|
|
4
|
+
---
|
|
5
|
+
{
|
|
6
|
+
"jsc": {
|
|
7
|
+
"parser": {
|
|
8
|
+
"syntax": "typescript",
|
|
9
|
+
"tsx": true,
|
|
10
|
+
"dynamicImport": true
|
|
11
|
+
},
|
|
12
|
+
"transform": {
|
|
13
|
+
"react": {
|
|
14
|
+
"runtime": "automatic"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"target": "es2022"
|
|
18
|
+
},
|
|
19
|
+
"module": {
|
|
20
|
+
"type": "commonjs",
|
|
21
|
+
"strict": true,
|
|
22
|
+
"noInterop": true
|
|
23
|
+
},
|
|
24
|
+
"env": {
|
|
25
|
+
"targets": {
|
|
26
|
+
"node": 16
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"sourceMaps": true
|
|
30
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: 'jest.config.ts'
|
|
3
|
+
strategy: overwrite
|
|
4
|
+
---
|
|
5
|
+
export default {
|
|
6
|
+
preset: 'ts-jest/presets/default',
|
|
7
|
+
globals: {
|
|
8
|
+
'ts-jest': {
|
|
9
|
+
tsconfig: 'tsconfig.typecheck.json',
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
collectCoverage: true,
|
|
14
|
+
coverageDirectory: '<rootDir>/coverage/',
|
|
15
|
+
collectCoverageFrom: ['<rootDir>/src/**/*.{ts,tsx}'],
|
|
16
|
+
coverageThreshold: {
|
|
17
|
+
global: {
|
|
18
|
+
branches: 0,
|
|
19
|
+
functions: 0,
|
|
20
|
+
lines: 0,
|
|
21
|
+
statements: 0,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: 'package.json'
|
|
3
|
+
strategy: create
|
|
4
|
+
---
|
|
5
|
+
{
|
|
6
|
+
"name": "<%- project.name %>",
|
|
7
|
+
"version": "0.0.0",
|
|
8
|
+
"description": "",
|
|
9
|
+
"repository": {
|
|
10
|
+
"url": "<%- workspace.repository?.url ?? '' %>"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "Jakub Mazanec <jakub@mazanec.dev>",
|
|
14
|
+
"sideEffects": false
|
|
15
|
+
}
|