@lakutata/cli 1.0.37 → 2.1.0-alpha.4

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.
Files changed (214) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +6 -26
  3. package/package.json +28 -56
  4. package/src/CLIApp.ts +86 -0
  5. package/src/controllers/CommandLineController.ts +34 -0
  6. package/src/lib/ProjectTypeConfig.ts +20 -0
  7. package/src/lib/SpecialChar.ts +8 -0
  8. package/src/lib/components/DeGitPuller.ts +41 -0
  9. package/src/lib/components/Spinner.ts +48 -0
  10. package/src/lib/providers/Creator.ts +125 -0
  11. package/src/lib/providers/Information.ts +221 -0
  12. package/src/options/CreateProjectOptions.ts +82 -0
  13. package/src/options/LakutataInfoOptions.ts +4 -0
  14. package/tsconfig.json +3 -33
  15. package/.eslintrc.json +0 -47
  16. package/.idea/codeStyles/Project.xml +0 -18
  17. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  18. package/.idea/dbnavigator.xml +0 -457
  19. package/.idea/inspectionProfiles/Project_Default.xml +0 -10
  20. package/.idea/lakutata-cli.iml +0 -14
  21. package/.idea/modules.xml +0 -8
  22. package/.idea/vcs.xml +0 -6
  23. package/LICENSE +0 -21
  24. package/assets/lakutata-banner.png +0 -0
  25. package/assets/lakutata_logo.jpg +0 -0
  26. package/build/CLI.d.ts +0 -2
  27. package/build/CLI.js +0 -13
  28. package/build/CLI.js.map +0 -1
  29. package/build/Deploy.d.ts +0 -1
  30. package/build/Deploy.js +0 -129
  31. package/build/Deploy.js.map +0 -1
  32. package/build/constants/GitIgnore.d.ts +0 -1
  33. package/build/constants/GitIgnore.js +0 -157
  34. package/build/constants/GitIgnore.js.map +0 -1
  35. package/build/constants/LicenseList.d.ts +0 -4
  36. package/build/constants/LicenseList.js +0 -68
  37. package/build/constants/LicenseList.js.map +0 -1
  38. package/build/interfaces/IApplicationInfo.d.ts +0 -4
  39. package/build/interfaces/IApplicationInfo.js +0 -3
  40. package/build/interfaces/IApplicationInfo.js.map +0 -1
  41. package/build/interfaces/IComponentInfo.d.ts +0 -4
  42. package/build/interfaces/IComponentInfo.js +0 -3
  43. package/build/interfaces/IComponentInfo.js.map +0 -1
  44. package/build/interfaces/IGenerator.d.ts +0 -3
  45. package/build/interfaces/IGenerator.js +0 -3
  46. package/build/interfaces/IGenerator.js.map +0 -1
  47. package/build/interfaces/IModuleInfo.d.ts +0 -4
  48. package/build/interfaces/IModuleInfo.js +0 -3
  49. package/build/interfaces/IModuleInfo.js.map +0 -1
  50. package/build/interfaces/IPluginInfo.d.ts +0 -4
  51. package/build/interfaces/IPluginInfo.js +0 -3
  52. package/build/interfaces/IPluginInfo.js.map +0 -1
  53. package/build/interfaces/IPreparePackageConfigOptions.d.ts +0 -19
  54. package/build/interfaces/IPreparePackageConfigOptions.js +0 -3
  55. package/build/interfaces/IPreparePackageConfigOptions.js.map +0 -1
  56. package/build/interfaces/IProjectGeneratorOptions.d.ts +0 -16
  57. package/build/interfaces/IProjectGeneratorOptions.js +0 -3
  58. package/build/interfaces/IProjectGeneratorOptions.js.map +0 -1
  59. package/build/interfaces/IProjectInfo.d.ts +0 -14
  60. package/build/interfaces/IProjectInfo.js +0 -3
  61. package/build/interfaces/IProjectInfo.js.map +0 -1
  62. package/build/lib/LatestVersion.d.ts +0 -1
  63. package/build/lib/LatestVersion.js +0 -13
  64. package/build/lib/LatestVersion.js.map +0 -1
  65. package/build/lib/generators/application/ApplicationGenerator.d.ts +0 -18
  66. package/build/lib/generators/application/ApplicationGenerator.js +0 -84
  67. package/build/lib/generators/application/ApplicationGenerator.js.map +0 -1
  68. package/build/lib/generators/application/files/AppFile.d.ts +0 -8
  69. package/build/lib/generators/application/files/AppFile.js +0 -36
  70. package/build/lib/generators/application/files/AppFile.js.map +0 -1
  71. package/build/lib/generators/application/files/ConfigFile.d.ts +0 -9
  72. package/build/lib/generators/application/files/ConfigFile.js +0 -81
  73. package/build/lib/generators/application/files/ConfigFile.js.map +0 -1
  74. package/build/lib/generators/component/ComponentGenerator.d.ts +0 -17
  75. package/build/lib/generators/component/ComponentGenerator.js +0 -75
  76. package/build/lib/generators/component/ComponentGenerator.js.map +0 -1
  77. package/build/lib/generators/component/files/ComponentFile.d.ts +0 -8
  78. package/build/lib/generators/component/files/ComponentFile.js +0 -45
  79. package/build/lib/generators/component/files/ComponentFile.js.map +0 -1
  80. package/build/lib/generators/component/files/ComponentTestFile.d.ts +0 -8
  81. package/build/lib/generators/component/files/ComponentTestFile.js +0 -35
  82. package/build/lib/generators/component/files/ComponentTestFile.js.map +0 -1
  83. package/build/lib/generators/module/ModuleGenerator.d.ts +0 -17
  84. package/build/lib/generators/module/ModuleGenerator.js +0 -85
  85. package/build/lib/generators/module/ModuleGenerator.js.map +0 -1
  86. package/build/lib/generators/module/files/ModuleFile.d.ts +0 -8
  87. package/build/lib/generators/module/files/ModuleFile.js +0 -116
  88. package/build/lib/generators/module/files/ModuleFile.js.map +0 -1
  89. package/build/lib/generators/module/files/ModuleTestFile.d.ts +0 -8
  90. package/build/lib/generators/module/files/ModuleTestFile.js +0 -35
  91. package/build/lib/generators/module/files/ModuleTestFile.js.map +0 -1
  92. package/build/lib/generators/plugin/PluginGenerator.d.ts +0 -17
  93. package/build/lib/generators/plugin/PluginGenerator.js +0 -75
  94. package/build/lib/generators/plugin/PluginGenerator.js.map +0 -1
  95. package/build/lib/generators/plugin/files/PluginFile.d.ts +0 -8
  96. package/build/lib/generators/plugin/files/PluginFile.js +0 -50
  97. package/build/lib/generators/plugin/files/PluginFile.js.map +0 -1
  98. package/build/lib/generators/plugin/files/PluginTestFile.d.ts +0 -8
  99. package/build/lib/generators/plugin/files/PluginTestFile.js +0 -35
  100. package/build/lib/generators/plugin/files/PluginTestFile.js.map +0 -1
  101. package/build/lib/generators/project/ProjectGenerator.d.ts +0 -27
  102. package/build/lib/generators/project/ProjectGenerator.js +0 -157
  103. package/build/lib/generators/project/ProjectGenerator.js.map +0 -1
  104. package/build/lib/generators/project/ProjectSourceFile.d.ts +0 -5
  105. package/build/lib/generators/project/ProjectSourceFile.js +0 -7
  106. package/build/lib/generators/project/ProjectSourceFile.js.map +0 -1
  107. package/build/lib/generators/project/configs/ProjectEslintrcConfig.d.ts +0 -37
  108. package/build/lib/generators/project/configs/ProjectEslintrcConfig.js +0 -51
  109. package/build/lib/generators/project/configs/ProjectEslintrcConfig.js.map +0 -1
  110. package/build/lib/generators/project/configs/ProjectPackageConfig.d.ts +0 -1
  111. package/build/lib/generators/project/configs/ProjectPackageConfig.js +0 -32
  112. package/build/lib/generators/project/configs/ProjectPackageConfig.js.map +0 -1
  113. package/build/lib/generators/project/configs/ProjectTypescriptConfig.d.ts +0 -25
  114. package/build/lib/generators/project/configs/ProjectTypescriptConfig.js +0 -39
  115. package/build/lib/generators/project/configs/ProjectTypescriptConfig.js.map +0 -1
  116. package/build/lib/manipulators/CreateComponentManipulator.d.ts +0 -3
  117. package/build/lib/manipulators/CreateComponentManipulator.js +0 -71
  118. package/build/lib/manipulators/CreateComponentManipulator.js.map +0 -1
  119. package/build/lib/manipulators/CreateDockerFileManipulator.d.ts +0 -3
  120. package/build/lib/manipulators/CreateDockerFileManipulator.js +0 -124
  121. package/build/lib/manipulators/CreateDockerFileManipulator.js.map +0 -1
  122. package/build/lib/manipulators/CreateModuleManipulator.d.ts +0 -3
  123. package/build/lib/manipulators/CreateModuleManipulator.js +0 -142
  124. package/build/lib/manipulators/CreateModuleManipulator.js.map +0 -1
  125. package/build/lib/manipulators/CreatePluginManipulator.d.ts +0 -3
  126. package/build/lib/manipulators/CreatePluginManipulator.js +0 -76
  127. package/build/lib/manipulators/CreatePluginManipulator.js.map +0 -1
  128. package/build/lib/manipulators/CreateProcessManipulator.d.ts +0 -3
  129. package/build/lib/manipulators/CreateProcessManipulator.js +0 -61
  130. package/build/lib/manipulators/CreateProcessManipulator.js.map +0 -1
  131. package/build/lib/manipulators/CreateThreadManipulator.d.ts +0 -3
  132. package/build/lib/manipulators/CreateThreadManipulator.js +0 -61
  133. package/build/lib/manipulators/CreateThreadManipulator.js.map +0 -1
  134. package/build/lib/manipulators/application/ApplicationIndexManipulator.d.ts +0 -1
  135. package/build/lib/manipulators/application/ApplicationIndexManipulator.js +0 -162
  136. package/build/lib/manipulators/application/ApplicationIndexManipulator.js.map +0 -1
  137. package/build/lib/menus/MainMenu.d.ts +0 -1
  138. package/build/lib/menus/MainMenu.js +0 -160
  139. package/build/lib/menus/MainMenu.js.map +0 -1
  140. package/build/lib/menus/initializeMenus/InitializeApplicationProject.d.ts +0 -1
  141. package/build/lib/menus/initializeMenus/InitializeApplicationProject.js +0 -93
  142. package/build/lib/menus/initializeMenus/InitializeApplicationProject.js.map +0 -1
  143. package/build/lib/menus/initializeMenus/InitializeComponentProject.d.ts +0 -1
  144. package/build/lib/menus/initializeMenus/InitializeComponentProject.js +0 -93
  145. package/build/lib/menus/initializeMenus/InitializeComponentProject.js.map +0 -1
  146. package/build/lib/menus/initializeMenus/InitializeModuleProject.d.ts +0 -1
  147. package/build/lib/menus/initializeMenus/InitializeModuleProject.js +0 -93
  148. package/build/lib/menus/initializeMenus/InitializeModuleProject.js.map +0 -1
  149. package/build/lib/menus/initializeMenus/InitializePluginProject.d.ts +0 -1
  150. package/build/lib/menus/initializeMenus/InitializePluginProject.js +0 -93
  151. package/build/lib/menus/initializeMenus/InitializePluginProject.js.map +0 -1
  152. package/build/lib/menus/manipulateMenus/ManipulateApplicationProject.d.ts +0 -1
  153. package/build/lib/menus/manipulateMenus/ManipulateApplicationProject.js +0 -60
  154. package/build/lib/menus/manipulateMenus/ManipulateApplicationProject.js.map +0 -1
  155. package/build/lib/menus/manipulateMenus/ManipulateComponentProject.d.ts +0 -1
  156. package/build/lib/menus/manipulateMenus/ManipulateComponentProject.js +0 -9
  157. package/build/lib/menus/manipulateMenus/ManipulateComponentProject.js.map +0 -1
  158. package/build/lib/menus/manipulateMenus/ManipulateModuleProject.d.ts +0 -1
  159. package/build/lib/menus/manipulateMenus/ManipulateModuleProject.js +0 -49
  160. package/build/lib/menus/manipulateMenus/ManipulateModuleProject.js.map +0 -1
  161. package/build/lib/menus/manipulateMenus/ManipulatePluginProject.d.ts +0 -1
  162. package/build/lib/menus/manipulateMenus/ManipulatePluginProject.js +0 -9
  163. package/build/lib/menus/manipulateMenus/ManipulatePluginProject.js.map +0 -1
  164. package/src/CLI.ts +0 -7
  165. package/src/Deploy.ts +0 -124
  166. package/src/constants/GitIgnore.ts +0 -153
  167. package/src/constants/LicenseList.ts +0 -64
  168. package/src/interfaces/IApplicationInfo.ts +0 -5
  169. package/src/interfaces/IComponentInfo.ts +0 -5
  170. package/src/interfaces/IGenerator.ts +0 -3
  171. package/src/interfaces/IModuleInfo.ts +0 -5
  172. package/src/interfaces/IPluginInfo.ts +0 -5
  173. package/src/interfaces/IPreparePackageConfigOptions.ts +0 -11
  174. package/src/interfaces/IProjectGeneratorOptions.ts +0 -15
  175. package/src/interfaces/IProjectInfo.ts +0 -10
  176. package/src/lib/LatestVersion.ts +0 -6
  177. package/src/lib/generators/application/ApplicationGenerator.ts +0 -97
  178. package/src/lib/generators/application/files/AppFile.ts +0 -35
  179. package/src/lib/generators/application/files/ConfigFile.ts +0 -82
  180. package/src/lib/generators/component/ComponentGenerator.ts +0 -87
  181. package/src/lib/generators/component/files/ComponentFile.ts +0 -45
  182. package/src/lib/generators/component/files/ComponentTestFile.ts +0 -36
  183. package/src/lib/generators/module/ModuleGenerator.ts +0 -97
  184. package/src/lib/generators/module/files/ModuleFile.ts +0 -116
  185. package/src/lib/generators/module/files/ModuleTestFile.ts +0 -36
  186. package/src/lib/generators/plugin/PluginGenerator.ts +0 -87
  187. package/src/lib/generators/plugin/files/PluginFile.ts +0 -50
  188. package/src/lib/generators/plugin/files/PluginTestFile.ts +0 -36
  189. package/src/lib/generators/project/ProjectGenerator.ts +0 -205
  190. package/src/lib/generators/project/ProjectSourceFile.ts +0 -7
  191. package/src/lib/generators/project/configs/ProjectEslintrcConfig.ts +0 -47
  192. package/src/lib/generators/project/configs/ProjectPackageConfig.ts +0 -28
  193. package/src/lib/generators/project/configs/ProjectTypescriptConfig.ts +0 -35
  194. package/src/lib/manipulators/CreateComponentManipulator.ts +0 -66
  195. package/src/lib/manipulators/CreateDockerFileManipulator.ts +0 -121
  196. package/src/lib/manipulators/CreateModuleManipulator.ts +0 -137
  197. package/src/lib/manipulators/CreatePluginManipulator.ts +0 -71
  198. package/src/lib/manipulators/CreateProcessManipulator.ts +0 -56
  199. package/src/lib/manipulators/CreateThreadManipulator.ts +0 -56
  200. package/src/lib/manipulators/application/ApplicationIndexManipulator.ts +0 -169
  201. package/src/lib/menus/MainMenu.ts +0 -148
  202. package/src/lib/menus/initializeMenus/InitializeApplicationProject.ts +0 -84
  203. package/src/lib/menus/initializeMenus/InitializeComponentProject.ts +0 -84
  204. package/src/lib/menus/initializeMenus/InitializeModuleProject.ts +0 -84
  205. package/src/lib/menus/initializeMenus/InitializePluginProject.ts +0 -84
  206. package/src/lib/menus/manipulateMenus/ManipulateApplicationProject.ts +0 -60
  207. package/src/lib/menus/manipulateMenus/ManipulateComponentProject.ts +0 -13
  208. package/src/lib/menus/manipulateMenus/ManipulateModuleProject.ts +0 -49
  209. package/src/lib/menus/manipulateMenus/ManipulatePluginProject.ts +0 -13
  210. package/src/tests/generators/GenerateApplication.spec.ts +0 -16
  211. package/src/tests/generators/GenerateComponent.spec.ts +0 -16
  212. package/src/tests/generators/GenerateModule.spec.ts +0 -16
  213. package/src/tests/generators/GeneratePlugin.spec.ts +0 -16
  214. package/typings.d.ts +0 -4
@@ -1,36 +0,0 @@
1
- import {ProjectSourceFile} from '../../project/ProjectSourceFile'
2
- import {SourceFile} from 'ts-morph'
3
-
4
- export class ComponentTestFile extends ProjectSourceFile {
5
- readonly filePath: string
6
- private readonly className: string
7
-
8
- constructor(className: string) {
9
- super()
10
- this.className = className
11
- this.filePath = `src/tests/${className}.test.spec.ts`
12
- }
13
-
14
- initSourceFile(file: SourceFile): SourceFile {
15
- file.addImportDeclaration({namedImports: ['createApp'], moduleSpecifier: '@lakutata/core'})
16
- file.addImportDeclaration({namedImports: [this.className], moduleSpecifier: `../${this.className}`})
17
- file.addStatements(writer => {
18
- writer.write(`
19
- createApp({
20
- id:'test.app',
21
- name:'tester',
22
- components:{
23
- test:{
24
- class:${this.className}
25
- }
26
- }
27
- }).then(app=>{
28
- const testComponent:${this.className} = app.Components.get<${this.className}>('test')
29
- }).catch(e=>{
30
- console.error(e)
31
- })
32
- `)
33
- })
34
- return file
35
- }
36
- }
@@ -1,97 +0,0 @@
1
- import {IGenerator} from '../../../interfaces/IGenerator'
2
- import {IModuleInfo} from '../../../interfaces/IModuleInfo'
3
- import {ProjectGenerator} from '../project/ProjectGenerator'
4
- import {ModuleFile} from './files/ModuleFile'
5
- import {ModuleTestFile} from './files/ModuleTestFile'
6
-
7
- export class ModuleGenerator implements IGenerator {
8
- private readonly projectPath: string
9
- private readonly author: string
10
- private readonly name: string
11
- private readonly description: string
12
- private readonly keywords: string | string[]
13
- private readonly outputDir: string = 'distro'
14
- private readonly sourceDir: string = 'src'
15
- private readonly entryName: string
16
- private readonly license: string
17
- private readonly dependencies: { [name: string]: string }
18
- private readonly devDependencies: { [name: string]: string }
19
-
20
- constructor(options: IModuleInfo) {
21
- this.projectPath = options.path
22
- this.author = options.author
23
- this.name = options.name
24
- this.entryName = options.className
25
- this.description = options.description ? options.description : 'No module description'
26
- this.keywords = options.keywords ? options.keywords : []
27
- this.license = options.license ? options.license : 'UNLICENSED'
28
- this.dependencies = options.dependencies ? options.dependencies : {}
29
- this.devDependencies = options.devDependencies ? options.devDependencies : {}
30
- }
31
-
32
- /**
33
- * 生成模块项目
34
- */
35
- public async generate(): Promise<void> {
36
- const testFile = new ModuleTestFile(this.entryName)
37
- const projectGenerator = new ProjectGenerator({
38
- entry: this.entryName,
39
- projectDirectory: this.projectPath,
40
- packageOptions: {
41
- name: this.name,
42
- author: this.author,
43
- description: this.description,
44
- keywords: this.keywords,
45
- scripts: {},
46
- license: this.license,
47
- dependencies: this.dependencies,
48
- devDependencies: this.dependencies,
49
- addition: {
50
- lakutata: {
51
- type: 'module',
52
- directories: {
53
- threads: 'src/threads',
54
- processes: 'src/processes',
55
- modules: 'src/modules',
56
- components: 'src/components',
57
- plugins: 'src/plugins',
58
- exceptions: 'src/exceptions'
59
- }
60
- }
61
- }
62
- },
63
- directories: [
64
- 'src/lib',
65
- 'src/exceptions',
66
- 'src/threads',
67
- 'src/processes',
68
- 'src/modules',
69
- 'src/components',
70
- 'src/plugins',
71
- 'src/tests'
72
- ],
73
- outputDir: this.outputDir,
74
- sourceDir: this.sourceDir,
75
- importLakutataCoreInDev: true,
76
- files: [
77
- new ModuleFile(this.entryName),
78
- testFile
79
- ],
80
- testFile: testFile.filePath,
81
- ignores: {
82
- '.gitignore': [
83
- `${this.outputDir}`,
84
- ` ${this.outputDir}/*`,
85
- `./${this.outputDir}`,
86
- `/${this.outputDir}/`,
87
- `!${this.sourceDir}`
88
- ],
89
- '.npmignore': [
90
- `!./${this.outputDir}`,
91
- `./${this.sourceDir}`
92
- ]
93
- }
94
- })
95
- await projectGenerator.generate()
96
- }
97
- }
@@ -1,116 +0,0 @@
1
- import {ProjectSourceFile} from '../../project/ProjectSourceFile'
2
- import {Scope, SourceFile, StructureKind} from 'ts-morph'
3
-
4
- export class ModuleFile extends ProjectSourceFile {
5
- readonly filePath: string
6
- private readonly className: string
7
-
8
- constructor(className: string) {
9
- super()
10
- this.className = className
11
- this.filePath = `src/${className}.ts`
12
- }
13
-
14
- initSourceFile(file: SourceFile): SourceFile {
15
- file.addImportDeclaration({
16
- namedImports: ['Module', 'Configurable', 'IComponentsConfig', 'IModulesConfig', 'TPluginsConfig', 'TProcessesConfig', 'TThreadsConfig', 'TWorkflowsConfig'],
17
- moduleSpecifier: '@lakutata/core'
18
- })
19
- const moduleClass = file.addClass({
20
- name: this.className,
21
- extends: 'Module',
22
- isExported: true
23
- })
24
- moduleClass.addMembers([
25
- {
26
- docs: [{
27
- kind: StructureKind.JSDoc,
28
- description: 'Module plugins'
29
- }],
30
- kind: StructureKind.Property,
31
- name: 'plugins',
32
- isReadonly: true,
33
- scope: Scope.Protected,
34
- type: 'TPluginsConfig',
35
- initializer: '[]',
36
- decorators: [{kind: StructureKind.Decorator, name: 'Configurable()'}]
37
- },
38
- {
39
- docs: [{
40
- kind: StructureKind.JSDoc,
41
- description: 'Module components'
42
- }],
43
- kind: StructureKind.Property,
44
- name: 'components',
45
- isReadonly: true,
46
- scope: Scope.Protected,
47
- type: 'IComponentsConfig',
48
- initializer: '{}',
49
- decorators: [{kind: StructureKind.Decorator, name: 'Configurable()'}]
50
- },
51
- {
52
- docs: [{
53
- kind: StructureKind.JSDoc,
54
- description: 'Subset modules'
55
- }],
56
- kind: StructureKind.Property,
57
- name: 'modules',
58
- isReadonly: true,
59
- scope: Scope.Protected,
60
- type: 'IModulesConfig',
61
- initializer: '{}',
62
- decorators: [{kind: StructureKind.Decorator, name: 'Configurable()'}]
63
- },
64
- {
65
- docs: [{
66
- kind: StructureKind.JSDoc,
67
- description: 'Module threads'
68
- }],
69
- kind: StructureKind.Property,
70
- name: 'threads',
71
- isReadonly: true,
72
- scope: Scope.Protected,
73
- type: 'TThreadsConfig',
74
- initializer: '[]',
75
- decorators: [{kind: StructureKind.Decorator, name: 'Configurable()'}]
76
- },
77
- {
78
- docs: [{
79
- kind: StructureKind.JSDoc,
80
- description: 'Module processes'
81
- }],
82
- kind: StructureKind.Property,
83
- name: 'processes',
84
- isReadonly: true,
85
- scope: Scope.Protected,
86
- type: 'TProcessesConfig',
87
- initializer: '[]',
88
- decorators: [{kind: StructureKind.Decorator, name: 'Configurable()'}]
89
- },
90
- {
91
- docs: [{
92
- kind: StructureKind.JSDoc,
93
- description: 'Module workflows'
94
- }],
95
- kind: StructureKind.Property,
96
- name: 'workflows',
97
- isReadonly: true,
98
- scope: Scope.Protected,
99
- type: 'TWorkflowsConfig',
100
- initializer: '[]',
101
- decorators: [{kind: StructureKind.Decorator, name: 'Configurable()'}]
102
- }
103
- ])
104
- const initMethod = moduleClass.addMethod({
105
- name: 'initialize',
106
- isAsync: true,
107
- returnType: 'Promise<void>',
108
- scope: Scope.Protected
109
- })
110
- initMethod.addStatements(writer => {
111
- writer.writeLine(`//Initializer for ${this.className}`)
112
- writer.writeLine(`//Write your module initialization codes here`)
113
- })
114
- return file
115
- }
116
- }
@@ -1,36 +0,0 @@
1
- import {ProjectSourceFile} from '../../project/ProjectSourceFile'
2
- import {SourceFile} from 'ts-morph'
3
-
4
- export class ModuleTestFile extends ProjectSourceFile {
5
- readonly filePath: string
6
- private readonly className: string
7
-
8
- constructor(className: string) {
9
- super()
10
- this.className = className
11
- this.filePath = `src/tests/${className}.test.spec.ts`
12
- }
13
-
14
- initSourceFile(file: SourceFile): SourceFile {
15
- file.addImportDeclaration({namedImports: ['createApp'], moduleSpecifier: '@lakutata/core'})
16
- file.addImportDeclaration({namedImports: [this.className], moduleSpecifier: `../${this.className}`})
17
- file.addStatements(writer => {
18
- writer.write(`
19
- createApp({
20
- id:'test.app',
21
- name:'tester',
22
- modules:{
23
- test:{
24
- class:${this.className}
25
- }
26
- }
27
- }).then(app=>{
28
- const testModule:${this.className} = app.Modules.get<${this.className}>('test')
29
- }).catch(e=>{
30
- console.error(e)
31
- })
32
- `)
33
- })
34
- return file
35
- }
36
- }
@@ -1,87 +0,0 @@
1
- import {IGenerator} from '../../../interfaces/IGenerator'
2
- import {IPluginInfo} from '../../../interfaces/IPluginInfo'
3
- import {ProjectGenerator} from '../project/ProjectGenerator'
4
- import {PluginFile} from './files/PluginFile'
5
- import {PluginTestFile} from './files/PluginTestFile'
6
-
7
- export class PluginGenerator implements IGenerator {
8
- private readonly projectPath: string
9
- private readonly author: string
10
- private readonly name: string
11
- private readonly description: string
12
- private readonly keywords: string | string[]
13
- private readonly outputDir: string = 'distro'
14
- private readonly sourceDir: string = 'src'
15
- private readonly entryName: string
16
- private readonly license: string
17
- private readonly dependencies: { [name: string]: string }
18
- private readonly devDependencies: { [name: string]: string }
19
-
20
- constructor(options: IPluginInfo) {
21
- this.projectPath = options.path
22
- this.author = options.author
23
- this.name = options.name
24
- this.entryName = options.className
25
- this.description = options.description ? options.description : 'No plugin description'
26
- this.keywords = options.keywords ? options.keywords : []
27
- this.license = options.license ? options.license : 'UNLICENSED'
28
- this.dependencies = options.dependencies ? options.dependencies : {}
29
- this.devDependencies = options.devDependencies ? options.devDependencies : {}
30
- }
31
-
32
- /**
33
- * 生成插件项目
34
- */
35
- public async generate(): Promise<void> {
36
- const testFile = new PluginTestFile(this.entryName)
37
- const projectGenerator = new ProjectGenerator({
38
- entry: this.entryName,
39
- projectDirectory: this.projectPath,
40
- packageOptions: {
41
- name: this.name,
42
- author: this.author,
43
- description: this.description,
44
- keywords: this.keywords,
45
- scripts: {},
46
- license: this.license,
47
- dependencies: this.dependencies,
48
- devDependencies: this.dependencies,
49
- addition: {
50
- lakutata: {
51
- type: 'plugin',
52
- directories: {
53
- exceptions: 'src/exceptions'
54
- }
55
- }
56
- }
57
- },
58
- directories: [
59
- 'src/lib',
60
- 'src/exceptions',
61
- 'src/tests'
62
- ],
63
- outputDir: this.outputDir,
64
- sourceDir: this.sourceDir,
65
- importLakutataCoreInDev: true,
66
- files: [
67
- new PluginFile(this.entryName),
68
- testFile
69
- ],
70
- testFile: testFile.filePath,
71
- ignores: {
72
- '.gitignore': [
73
- `${this.outputDir}`,
74
- ` ${this.outputDir}/*`,
75
- `./${this.outputDir}`,
76
- `/${this.outputDir}/`,
77
- `!${this.sourceDir}`
78
- ],
79
- '.npmignore': [
80
- `!./${this.outputDir}`,
81
- `./${this.sourceDir}`
82
- ]
83
- }
84
- })
85
- await projectGenerator.generate()
86
- }
87
- }
@@ -1,50 +0,0 @@
1
- import {ProjectSourceFile} from '../../project/ProjectSourceFile'
2
- import {ModuleDeclarationKind, Scope, SourceFile, StructureKind} from 'ts-morph'
3
-
4
- export class PluginFile extends ProjectSourceFile {
5
- readonly filePath: string
6
- private readonly className: string
7
-
8
- constructor(className: string) {
9
- super()
10
- this.className = className
11
- this.filePath = `src/${className}.ts`
12
- }
13
-
14
- initSourceFile(file: SourceFile): SourceFile {
15
- file.addImportDeclaration({
16
- namedImports: ['Plugin', 'Configurable'],
17
- moduleSpecifier: '@lakutata/core'
18
- })
19
- file.addStatements([{
20
- declarationKind: ModuleDeclarationKind.Module,
21
- kind: StructureKind.Module,
22
- hasDeclareKeyword: true,
23
- name: `'@lakutata/core'`,
24
- statements: [{
25
- kind: StructureKind.Interface,
26
- name: 'Application',
27
- properties: [{
28
- name: this.className,
29
- type: this.className
30
- }]
31
- }]
32
- }])
33
- const pluginClass = file.addClass({
34
- name: this.className,
35
- extends: 'Plugin',
36
- isExported: true
37
- })
38
- const onActivationMethod = pluginClass.addMethod({
39
- name: 'onActivation',
40
- isAsync: false,
41
- returnType: 'void',
42
- scope: Scope.Protected
43
- })
44
- onActivationMethod.addStatements(writer => {
45
- writer.writeLine('//Codes in here will be executed on plugin activation')
46
- writer.writeLine('//Plugin is always executed in transient mode')
47
- })
48
- return file
49
- }
50
- }
@@ -1,36 +0,0 @@
1
- import {ProjectSourceFile} from '../../project/ProjectSourceFile'
2
- import {SourceFile} from 'ts-morph'
3
-
4
- export class PluginTestFile extends ProjectSourceFile {
5
- readonly filePath: string
6
- private readonly className: string
7
-
8
- constructor(className: string) {
9
- super()
10
- this.className = className
11
- this.filePath = `src/tests/${className}.test.spec.ts`
12
- }
13
-
14
- initSourceFile(file: SourceFile): SourceFile {
15
- file.addImportDeclaration({namedImports: ['createApp'], moduleSpecifier: '@lakutata/core'})
16
- file.addImportDeclaration({namedImports: [this.className], moduleSpecifier: `../${this.className}`})
17
- file.addStatements(writer => {
18
- writer.write(`
19
- createApp({
20
- id:'test.app',
21
- name:'tester',
22
- plugins:[
23
- {
24
- class:${this.className}
25
- }
26
- ]
27
- }).then(app=>{
28
- const testComponent:${this.className} = app.${this.className}
29
- }).catch(e=>{
30
- console.error(e)
31
- })
32
- `)
33
- })
34
- return file
35
- }
36
- }
@@ -1,205 +0,0 @@
1
- import {Project, ts} from 'ts-morph'
2
- import path from 'path'
3
- import {ProjectTypescriptConfig} from './configs/ProjectTypescriptConfig'
4
- import {ProjectPackageConfig} from './configs/ProjectPackageConfig'
5
- import {IPreparePackageConfigOptions} from '../../../interfaces/IPreparePackageConfigOptions'
6
- import {ProjectEslintrcConfig} from './configs/ProjectEslintrcConfig'
7
- import simpleGit, {GitError, RemoteWithRefs, SimpleGit, SimpleGitTaskCallback} from 'simple-git'
8
- import {IProjectGeneratorOptions} from '../../../interfaces/IProjectGeneratorOptions'
9
- import {IGenerator} from '../../../interfaces/IGenerator'
10
- import {GitIgnore} from '../../../constants/GitIgnore'
11
- import {ProjectSourceFile} from './ProjectSourceFile'
12
- import { LatestVersion } from '../../LatestVersion'
13
-
14
- export class ProjectGenerator implements IGenerator {
15
- private readonly project: Project
16
- private readonly projectDir: string
17
- private readonly packageOptions: IPreparePackageConfigOptions
18
- private readonly projectEntryPoint: string
19
- private readonly sourceDir: string
20
- private readonly outputDir: string
21
- private readonly importLakutataCoreInDev: boolean
22
- private readonly directories: string[]
23
- private readonly files: ProjectSourceFile[]
24
- private readonly ignores: { [ignoreName: string]: string[] }
25
- private readonly lakutataPackageName: string = '@lakutata/core'
26
- private readonly testFilePath: string
27
- private lakutataCoreVersion: string
28
-
29
- constructor(options: IProjectGeneratorOptions) {
30
- this.project = new Project()
31
- this.projectDir = options.projectDirectory
32
- this.projectEntryPoint = options.entry
33
- this.packageOptions = options.packageOptions
34
- this.files = options.files
35
- this.testFilePath = options.testFile
36
- this.directories = options.directories ? options.directories : []
37
- this.sourceDir = options.sourceDir ? options.sourceDir : 'src'
38
- this.outputDir = options.outputDir ? options.outputDir : 'build'
39
- this.ignores = {'.gitignore': GitIgnore}
40
- if (options.ignores) {
41
- for (const filename of Object.keys(options.ignores)) {
42
- if (this.ignores[filename]) {
43
- this.ignores[filename] = this.ignores[filename].concat(options.ignores[filename])
44
- } else {
45
- this.ignores[filename] = options.ignores[filename]
46
- }
47
- }
48
- }
49
- this.importLakutataCoreInDev = !!options.importLakutataCoreInDev
50
- }
51
-
52
- /**
53
- * 检查框架最新版本
54
- * @private
55
- */
56
- private async checkLatestFrameworkVersion(): Promise<void> {
57
- this.lakutataCoreVersion = await LatestVersion(this.lakutataPackageName)
58
- }
59
-
60
- /**
61
- * 获取git仓库地址
62
- * @private
63
- */
64
- private async getGitRepository(): Promise<string | null> {
65
- try {
66
- const git: SimpleGit = simpleGit({
67
- baseDir: this.projectDir,
68
- binary: 'git'
69
- })
70
- return new Promise<string | null>(resolve => {
71
- const callback: SimpleGitTaskCallback & any = function <E extends GitError = GitError>(err: E, data: RemoteWithRefs[]) {
72
- if (err) {
73
- resolve(null)
74
- } else {
75
- data.forEach(repo => {
76
- if (repo.name === 'origin' && repo.refs) {
77
- resolve(repo.refs.push)
78
- }
79
- })
80
- resolve(null)
81
- }
82
- }
83
- git.getRemotes(true, callback)
84
- })
85
- } catch (e) {
86
- return null
87
- }
88
- }
89
-
90
- /**
91
- * 生成tsconfig.json
92
- * @protected
93
- */
94
- protected prepareTypescriptConfig(): void {
95
- const tsConfig = ProjectTypescriptConfig
96
- tsConfig.compilerOptions.outDir = this.outputDir
97
- tsConfig.compilerOptions.rootDir = this.sourceDir
98
- this.project.createSourceFile(path.resolve(this.projectDir, 'tsconfig.json'), JSON.stringify(ProjectTypescriptConfig, null, 2))
99
- }
100
-
101
- /**
102
- * 生成package.json
103
- * @protected
104
- */
105
- protected async preparePackageConfig(): Promise<void> {
106
- const options: IPreparePackageConfigOptions = this.packageOptions
107
- const addition = options.addition ? options.addition : {}
108
- const packageConfig = Object.assign(ProjectPackageConfig, addition)
109
- packageConfig.name = options.name
110
- packageConfig.author = options.author
111
- packageConfig.main = `./${this.outputDir}/${this.projectEntryPoint}.js`
112
- packageConfig.types = `./${this.outputDir}/${this.projectEntryPoint}.d.ts`
113
- packageConfig.description = options.description ? options.description : 'No description'
114
- packageConfig.scripts = {
115
- lakutata: 'node ./node_modules/@lakutata/cli',
116
- clean: `shx rm -rf ./${this.outputDir}`,
117
- build: `tsc`,
118
- rebuild: `npm run clean && npm run build`,
119
- prepare: `npm run compile`,
120
- compile: `npm run rebuild && shx rm -rf ./${this.outputDir}/tests/*`,
121
- test: `node -r ./node_modules/ts-node/register ${this.testFilePath}`
122
- }
123
- packageConfig.scripts = options.scripts ? Object.assign(packageConfig.scripts, options.scripts) : packageConfig.scripts
124
- packageConfig.dependencies = options.dependencies ? Object.assign(packageConfig.dependencies, options.dependencies) : packageConfig.dependencies
125
- packageConfig.devDependencies = Object.assign(options.devDependencies ? Object.assign(packageConfig.devDependencies, options.devDependencies) : packageConfig.devDependencies, {
126
- '@lakutata/cli': await LatestVersion('@lakutata/cli')
127
- })
128
- const gitRepository: string | null = await this.getGitRepository()
129
- if (gitRepository) {
130
- packageConfig.repository = {
131
- type: 'git',
132
- url: gitRepository
133
- }
134
- }
135
- if (this.importLakutataCoreInDev) {
136
- packageConfig.devDependencies[this.lakutataPackageName] = `^${this.lakutataCoreVersion}`
137
- } else {
138
- packageConfig.dependencies[this.lakutataPackageName] = `^${this.lakutataCoreVersion}`
139
- }
140
- packageConfig.keywords = options.keywords ? Array.isArray(options.keywords) ? options.keywords : [options.keywords] : ['lakutata']
141
- packageConfig.license = options.license ? options.license : 'UNLICENSED'
142
- this.project.createSourceFile(path.resolve(this.projectDir, 'package.json'), JSON.stringify(packageConfig, null, 2))
143
- }
144
-
145
- /**
146
- * 生成.eslintrc.json
147
- * @protected
148
- */
149
- protected prepareEslintConfig(): void {
150
- this.project.createSourceFile(path.resolve(this.projectDir, '.eslintrc.json'), JSON.stringify(ProjectEslintrcConfig, null, 2))
151
- }
152
-
153
- /**
154
- * 生成文件夹
155
- * @protected
156
- */
157
- protected prepareDirectories(): void {
158
- this.directories.forEach(dirPath => {
159
- this.project.createDirectory(path.resolve(this.projectDir, dirPath))
160
- this.project.createSourceFile(path.resolve(this.projectDir, dirPath, './.gitkeep'))
161
- })
162
- }
163
-
164
- /**
165
- * 生成文件
166
- */
167
- public prepareFiles() {
168
- this.files.forEach(projectSourceFile => {
169
- projectSourceFile.initSourceFile(this.project.createSourceFile(path.resolve(this.projectDir, projectSourceFile.filePath)))
170
- .formatText({
171
- indentStyle: ts.IndentStyle.Block,
172
- ensureNewLineAtEndOfFile: true,
173
- semicolons: ts.SemicolonPreference.Remove
174
- })
175
- })
176
- }
177
-
178
- /**
179
- * 生成.ignore文件
180
- */
181
- public prepareIgnores() {
182
- for (const filename of Object.keys(this.ignores)) {
183
- this.project.createSourceFile(path.resolve(this.projectDir, filename), writer => {
184
- this.ignores[filename].forEach(value => {
185
- writer.writeLine(value)
186
- })
187
- })
188
- }
189
- }
190
-
191
- /**
192
- * 生成项目
193
- */
194
- public async generate(): Promise<void> {
195
- await this.checkLatestFrameworkVersion()
196
- this.project.createDirectory(this.projectDir)
197
- await this.preparePackageConfig()
198
- this.prepareTypescriptConfig()
199
- this.prepareEslintConfig()
200
- this.prepareDirectories()
201
- this.prepareFiles()
202
- this.prepareIgnores()
203
- await this.project.save()
204
- }
205
- }
@@ -1,7 +0,0 @@
1
- import {SourceFile} from 'ts-morph'
2
-
3
- export abstract class ProjectSourceFile {
4
- public abstract readonly filePath: string
5
-
6
- public abstract initSourceFile(file: SourceFile): SourceFile
7
- }