@alessiofrittoli/package-configs 1.8.0-alpha.7 → 1.8.0-alpha.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alessiofrittoli/package-configs",
3
- "version": "1.8.0-alpha.7",
3
+ "version": "1.8.0-alpha.9",
4
4
  "description": "Utility library that offers base configurations for your packages.",
5
5
  "type": "module",
6
6
  "author": {
@@ -1,4 +1,4 @@
1
- const { default: installDependencies } = require('./install-dependencies.cjs')
1
+ const installDependencies = require('./install-dependencies.cjs')
2
2
  const { Chain } = require('@alessiofrittoli/chain-functions')
3
3
  const project = require('../../package.json')
4
4
  const { readFileSync } = require('fs')
@@ -43,8 +43,6 @@ const isExternalPackage = ({ root, name }) => {
43
43
  */
44
44
  const getProcessRoot = () => process.env.INIT_CWD || process.cwd()
45
45
 
46
- // export type PostInstallChainFn = () => void | Promise<void>
47
-
48
46
  /**
49
47
  * @type import('@alessiofrittoli/chain-functions/types').LastChainLink<() => void | Promise<void>>
50
48
  */
@@ -53,10 +51,12 @@ const lastChainLink = () => () => {
53
51
  package: project.name,
54
52
  message: `Post-Install done. Thank you for installing ${project.name}!`,
55
53
  })
54
+
55
+ process.exit(0)
56
56
  }
57
57
 
58
58
  /**
59
- * @type import('@alessiofrittoli/chain-functions/types').ChainFactory<( { cwd }: { cwd: string } ) => void | Promise<void>>
59
+ * @type import('@alessiofrittoli/chain-functions/types').ChainFactory<( params: { cwd: string; scriptsDir: string } ) => void | Promise<void>>
60
60
  */
61
61
  const postInstallChain = [installDependencies, lastChainLink]
62
62
 
@@ -67,9 +67,8 @@ const runChain = async () => {
67
67
  return process.exit(0)
68
68
  }
69
69
 
70
- await Chain.functions(postInstallChain)({ cwd })
71
-
72
- process.exit(0)
70
+ await Chain.functions(postInstallChain)({ cwd, scriptsDir: __dirname })
73
71
  }
74
72
 
75
- runChain().catch(console.error)
73
+ // oxlint-disable-next-line typescript/no-floating-promises
74
+ runChain()
@@ -1,7 +1,8 @@
1
+ const { openSync, existsSync, readFileSync, writeFileSync } = require('fs')
1
2
  const { ReadStream, WriteStream } = require('tty')
2
3
  const { execSync } = require('child_process')
3
4
  const prompts = require('prompts')
4
- const { openSync } = require('fs')
5
+ const path = require('path')
5
6
 
6
7
  // // example writing user input data to stdout
7
8
 
@@ -48,16 +49,31 @@ const isCIEnv = () =>
48
49
  const arrayUnique = array => (array.length <= 0 ? array : [...new Set(array)])
49
50
 
50
51
  /**
51
- * @type import('@alessiofrittoli/chain-functions/types').ChainLink<( { cwd }: { cwd: string } ) => void | Promise<void>>
52
+ * @type import('@alessiofrittoli/chain-functions/types').ChainLink<( params: { cwd: string; scriptsDir: string } ) => void | Promise<void>>
52
53
  */
53
54
  const installDependencies = next => async params => {
54
55
  if (isCIEnv()) {
55
56
  return next(params)
56
57
  }
57
58
 
58
- const { cwd } = params
59
+ const { cwd, scriptsDir } = params
59
60
 
60
61
  try {
62
+ const stateFilePath = path.resolve(scriptsDir, 'post-install-data.json')
63
+
64
+ if (existsSync(stateFilePath)) {
65
+ try {
66
+ const file = JSON.parse(
67
+ readFileSync(path.resolve(scriptsDir, 'post-install-data.json'), 'utf-8'),
68
+ )
69
+ if (file.installDependencies.done) {
70
+ return next(params)
71
+ }
72
+ } catch {
73
+ return next(params)
74
+ }
75
+ }
76
+
61
77
  const inputPath = process.platform === 'win32' ? 'CONIN$' : '/dev/tty'
62
78
  const outputPath = process.platform === 'win32' ? 'CONOUT$' : '/dev/tty'
63
79
  const stdin = !process.stdin.isTTY ? new ReadStream(openSync(inputPath, 'r')) : undefined
@@ -167,9 +183,10 @@ const installDependencies = next => async params => {
167
183
 
168
184
  const installCommand = engine === 'npm' ? 'npm install --save-dev' : 'pnpm add --save-dev'
169
185
 
170
- // execSync(`${installCommand} ${dependenciesChoice.join(' ')}`, { cwd, stdio: 'inherit' })
171
186
  execSync(`${installCommand} ${dependenciesChoice.join(' ')}`, { cwd, stdio: 'ignore' })
172
187
 
188
+ writeFileSync(stateFilePath, JSON.stringify({ installDependencies: { done: true } }))
189
+
173
190
  return next(params)
174
191
  } catch {
175
192
  return next(params)
@@ -0,0 +1 @@
1
+ {"installDependencies":{"done":true}}