@toptal/davinci-syntax 14.0.9-alpha-fx-try-engines-version-dependency.8 → 14.0.9-alpha-fx-2957-remove-syntax-init-command.12

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/README.md CHANGED
@@ -6,16 +6,6 @@ Helps to check the style of your code. Provides basic linting, prettier function
6
6
 
7
7
  Use it by installing `yarn add @toptal/davinci` in your project.
8
8
 
9
- ### Init
10
-
11
- Important: If you've bootstrapped your projects by using `davinci` CLI there is _NO NEED to run `init`_ in your project because `syntax` package already set up.
12
-
13
- But if you are using `syntax` as a standalone package, before using it you have to run
14
-
15
- `davinci syntax init`
16
-
17
- Under the hood, it will prepare `.estlintrc`, `.eslintignore`, `.prettierrc`, `.stylelintrc`, `.editorconfig` files in your project, and set up hooks to check your code on commits.
18
-
19
9
  #### Commands
20
10
 
21
11
  - [`lint code`](./docs/lint-code.md): lint the project's code
@@ -2,13 +2,11 @@
2
2
 
3
3
  const cliEngine = require('@toptal/davinci-cli-shared')
4
4
 
5
- const initCommandCreator = require('../src/commands/init')
6
5
  const lintCodeCommandCreator = require('../src/commands/lint-code')
7
6
  const lintStylesCommandCreator = require('../src/commands/lint-styles')
8
7
  const lintDirsCommandCreator = require('../src/commands/lint-dirs')
9
8
 
10
9
  cliEngine.loadCommands([
11
- initCommandCreator,
12
10
  lintCodeCommandCreator,
13
11
  lintStylesCommandCreator,
14
12
  lintDirsCommandCreator,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toptal/davinci-syntax",
3
- "version": "14.0.9-alpha-fx-try-engines-version-dependency.8+83df4bc1",
3
+ "version": "14.0.9-alpha-fx-2957-remove-syntax-init-command.12+ec9567da",
4
4
  "description": "Lint and prettier support",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -31,9 +31,9 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@stylelint/postcss-css-in-js": "^0.37.2",
34
- "@toptal/davinci-cli-shared": "1.5.5-alpha-fx-try-engines-version-dependency.97+83df4bc1",
35
- "@toptal/davinci-dir-lint": "0.1.1-alpha-fx-try-engines-version-dependency.213+83df4bc1",
36
- "@toptal/eslint-plugin-davinci": "5.3.2-alpha-fx-try-engines-version-dependency.22+83df4bc1",
34
+ "@toptal/davinci-cli-shared": "1.5.5-alpha-fx-2957-remove-syntax-init-command.101+ec9567da",
35
+ "@toptal/davinci-dir-lint": "0.1.1-alpha-fx-2957-remove-syntax-init-command.217+ec9567da",
36
+ "@toptal/eslint-plugin-davinci": "5.3.2-alpha-fx-2957-remove-syntax-init-command.26+ec9567da",
37
37
  "@typescript-eslint/eslint-plugin": "^5.19.0",
38
38
  "@typescript-eslint/parser": "^5.30.7",
39
39
  "eslint": "^8.19.0",
@@ -67,5 +67,5 @@
67
67
  "peerDependencies": {
68
68
  "typescript": "^3 || ^4"
69
69
  },
70
- "gitHead": "83df4bc102b02ed3fe8cf02f499b4a0c46366163"
70
+ "gitHead": "ec9567daa3ea1c1c117063b4e5725009eb9a74b0"
71
71
  }
package/src/index.js CHANGED
@@ -1,11 +1,9 @@
1
- const initCommandCreator = require('./commands/init')
2
1
  const lintCodeCommandCreator = require('./commands/lint-code')
3
2
  const lintStylesCommandCreator = require('./commands/lint-styles')
4
3
  const lintDirsCommandCreator = require('./commands/lint-dirs')
5
4
 
6
5
  module.exports = {
7
6
  commands: [
8
- initCommandCreator,
9
7
  lintCodeCommandCreator,
10
8
  lintStylesCommandCreator,
11
9
  lintDirsCommandCreator,
@@ -1,183 +0,0 @@
1
- const fs = require('fs')
2
- const path = require('path')
3
- const { print, prompt } = require('@toptal/davinci-cli-shared')
4
-
5
- const copyConfigFile = async ({
6
- copyFromFile,
7
- copyToFile,
8
- promptName,
9
- promptText,
10
- }) => {
11
- if (fs.existsSync(copyToFile)) {
12
- const shouldRewrite = await prompt.confirm(promptName, promptText)
13
-
14
- if (!shouldRewrite) {
15
- return
16
- }
17
- }
18
-
19
- fs.copyFileSync(copyFromFile, copyToFile)
20
- }
21
-
22
- const copyLintConfigFile = (rootDir, currentRunningDir) => {
23
- return copyConfigFile({
24
- copyFromFile: path.join(rootDir, './src/configs/to-copy/root.eslintrc'),
25
- copyToFile: path.join(currentRunningDir, './.eslintrc'),
26
- promptName: 'eslintrc',
27
- promptText: 'Do you want to override your existing .eslintrc file?',
28
- })
29
- }
30
-
31
- const copyLintIgnoreFile = (rootDir, currentRunningDir) => {
32
- return copyConfigFile({
33
- copyFromFile: path.join(rootDir, './src/configs/to-copy/root.eslintignore'),
34
- copyToFile: path.join(currentRunningDir, './.eslintignore'),
35
- promptName: 'eslintignore',
36
- promptText: 'Do you want to override your existing .eslintignore file?',
37
- })
38
- }
39
-
40
- const copyPrettierConfigFile = (rootDir, currentRunningDir) => {
41
- return copyConfigFile({
42
- copyFromFile: path.join(
43
- rootDir,
44
- './src/configs/to-copy/root.prettierrc.js'
45
- ),
46
- copyToFile: path.join(currentRunningDir, './.prettierrc.js'),
47
- promptName: 'prettierrc',
48
- promptText: 'Do you want to override your existing .prettierrc.js file?',
49
- })
50
- }
51
-
52
- const copyEditorConfigFile = (rootDir, currentRunningDir) => {
53
- return copyConfigFile({
54
- copyFromFile: path.join(rootDir, './src/configs/to-copy/root.editorconfig'),
55
- copyToFile: path.join(currentRunningDir, './.editorconfig'),
56
- promptName: 'editorconfig',
57
- promptText: 'Do you want to override your existing .editorconfig file?',
58
- })
59
- }
60
-
61
- const copyStylelintConfigFile = (rootDir, currentRunningDir) => {
62
- return copyConfigFile({
63
- copyFromFile: path.join(rootDir, './src/configs/to-copy/root.stylelintrc'),
64
- copyToFile: path.join(currentRunningDir, './.stylelintrc'),
65
- promptName: 'stylelintrc',
66
- promptText: 'Do you want to override your existing .stylelintrc file?',
67
- })
68
- }
69
-
70
- const checkPackageJsonExists = currentRunningDir => {
71
- const packageJsonFile = path.join(currentRunningDir, './package.json')
72
-
73
- if (!fs.existsSync(packageJsonFile)) {
74
- print.red(
75
- 'You should run `npm init` in your repo before running davinci-syntax init.'
76
- )
77
-
78
- return false
79
- }
80
-
81
- return true
82
- }
83
-
84
- const addLintCommands = async currentRunningDir => {
85
- const packageJsonFile = path.join(currentRunningDir, './package.json')
86
-
87
- const configData = fs.readFileSync(packageJsonFile)
88
- const config = JSON.parse(configData)
89
-
90
- const lintCommand = config.scripts && config.scripts.lint
91
-
92
- if (lintCommand) {
93
- const shouldRewrite = await prompt.confirm(
94
- 'lintCommand',
95
- 'You have already a lint command in you package.json. Do you want to override it?'
96
- )
97
-
98
- if (!shouldRewrite) {
99
- return
100
- }
101
- }
102
-
103
- // add scripts lint command
104
- config.scripts.lint =
105
- 'davinci-syntax lint code . && davinci-syntax lint styles .'
106
-
107
- const modifiedConfigData = JSON.stringify(config, null, 2).concat('\n')
108
-
109
- fs.writeFileSync(packageJsonFile, modifiedConfigData)
110
- }
111
-
112
- const addLintStagedCommands = async currentRunningDir => {
113
- const packageJsonFile = path.join(currentRunningDir, './package.json')
114
-
115
- const configData = fs.readFileSync(packageJsonFile)
116
- const config = JSON.parse(configData)
117
-
118
- const lintStagedCommand = config.husky || config['lint-staged']
119
-
120
- if (lintStagedCommand) {
121
- const shouldRewrite = await prompt.confirm(
122
- 'lintStagedCommand',
123
- 'You have already a husky or lint-staged in you package.json. Do you want still to override them?'
124
- )
125
-
126
- if (!shouldRewrite) {
127
- return
128
- }
129
- }
130
-
131
- // add lint-staged
132
- config['lint-staged'] = {
133
- '*.{js,jsx,ts,tsx}': ['davinci-syntax lint code', 'prettier', 'git add'],
134
- 'styles.{js,jsx,ts,tsx}': [
135
- 'davinci syntax lint styles',
136
- 'prettier',
137
- 'git add',
138
- ],
139
- }
140
- // add husky
141
- config.husky = {
142
- hooks: {
143
- 'pre-commit': 'lint-staged',
144
- },
145
- }
146
-
147
- const modifiedConfigData = JSON.stringify(config, null, 2).concat('\n')
148
-
149
- fs.writeFileSync(packageJsonFile, modifiedConfigData)
150
- }
151
-
152
- const initCommand = async () => {
153
- print.green('Initializing syntax package...')
154
-
155
- const currentRunningDir = process.cwd()
156
- const rootDir = path.join(__dirname, '../..')
157
-
158
- try {
159
- await copyLintConfigFile(rootDir, currentRunningDir)
160
- await copyLintIgnoreFile(rootDir, currentRunningDir)
161
- await copyPrettierConfigFile(rootDir, currentRunningDir)
162
- await copyStylelintConfigFile(rootDir, currentRunningDir)
163
- await copyEditorConfigFile(rootDir, currentRunningDir)
164
-
165
- if (checkPackageJsonExists(currentRunningDir)) {
166
- await addLintCommands(currentRunningDir)
167
- await addLintStagedCommands(currentRunningDir)
168
- }
169
- } finally {
170
- // eslint-disable-next-line
171
- console.log('Done.')
172
- }
173
- }
174
-
175
- const initCommandCreator = {
176
- action: () => {
177
- initCommand()
178
- },
179
- command: 'init',
180
- description: 'Init the syntax package',
181
- }
182
-
183
- module.exports = initCommandCreator
@@ -1,15 +0,0 @@
1
- # top-most EditorConfig file
2
- root = true
3
-
4
- # Unix-style newlines with a newline ending every file
5
- [*]
6
- end_of_line = lf
7
- insert_final_newline = true
8
-
9
- # Consistent 2 space indentation
10
- [*]
11
- indent_style = space
12
- indent_size = 2
13
-
14
- [*.ejs.t]
15
- insert_final_newline = false
@@ -1,2 +0,0 @@
1
- /build
2
- /node_modules
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "./node_modules/@toptal/davinci-syntax/src/configs/.eslintrc"
3
- }
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- ...require('@toptal/davinci-syntax/src/configs/.prettierrc.js'),
3
- }
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "./node_modules/@toptal/davinci-syntax/src/configs/.stylelintrc"
3
- }