rootless-config 1.4.5 → 1.4.6

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": "rootless-config",
3
- "version": "1.4.5",
3
+ "version": "1.4.6",
4
4
  "description": "Store project config files outside the project root, auto-deploy them where tools expect them.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,21 +1,62 @@
1
- /*-------- rootless setup — one-command full root cleanup: init + migrate + prepare --------*/
1
+ /*-------- rootless setup — one-command full root cleanup: init + normalize + migrate --------*/
2
2
 
3
3
  import path from 'node:path'
4
+ import { readdir, rename } from 'node:fs/promises'
4
5
  import { createLogger } from '../../utils/logger.js'
6
+ import { fileExists, ensureDir } from '../../utils/fsUtils.js'
7
+ import { isPatchable } from '../../core/scriptPatcher.js'
5
8
  import initCmd from './init.js'
6
9
  import migrateCmd from './migrate.js'
7
- import prepareCmd from './prepare.js'
10
+
11
+ /**
12
+ * Fix files that ended up in the wrong subfolder from a previous run.
13
+ * Non-patchable files (web assets, docs, scripts) belong in assets/, not configs/.
14
+ */
15
+ async function normalizeContainer(containerPath, logger) {
16
+ const configsDir = path.join(containerPath, 'configs')
17
+ const assetsDir = path.join(containerPath, 'assets')
18
+ if (!(await fileExists(configsDir))) return
19
+
20
+ const entries = await readdir(configsDir, { withFileTypes: true })
21
+ for (const e of entries) {
22
+ if (!e.isFile()) continue
23
+ if (!isPatchable(e.name)) {
24
+ // Not a tool config — belongs in assets/
25
+ await ensureDir(assetsDir)
26
+ await rename(
27
+ path.join(configsDir, e.name),
28
+ path.join(assetsDir, e.name)
29
+ )
30
+ logger.debug(`Normalized: .root/configs/${e.name} → .root/assets/${e.name}`)
31
+ }
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Count total files managed across all .root subdirectories.
37
+ */
38
+ async function countRootFiles(containerPath) {
39
+ let total = 0
40
+ for (const sub of ['env', 'assets', 'configs']) {
41
+ const dir = path.join(containerPath, sub)
42
+ if (!(await fileExists(dir))) continue
43
+ const entries = await readdir(dir, { withFileTypes: true })
44
+ total += entries.filter(e => e.isFile()).length
45
+ }
46
+ return total
47
+ }
8
48
 
9
49
  export default {
10
50
  name: 'setup',
11
- description: 'Full automated root cleanup: init .root, migrate all configs, prepare (copy + patch scripts)',
51
+ description: 'Full automated root cleanup: move ALL files into .root container (run prepare to deploy)',
12
52
 
13
53
  async handler(args) {
14
54
  const logger = createLogger({ verbose: args.verbose ?? false })
15
55
  const projectRoot = args.cwd ? path.resolve(args.cwd) : process.cwd()
56
+ const containerPath = path.join(projectRoot, '.root')
16
57
 
17
58
  logger.info('─────────────────────────────────────────')
18
- logger.info(' rootless setup — cleaning your project root')
59
+ logger.info(' rootless setup — moving everything to .root/')
19
60
  logger.info('─────────────────────────────────────────')
20
61
  logger.info('')
21
62
 
@@ -24,31 +65,36 @@ export default {
24
65
  await initCmd.handler({ ...args, yes: true, cwd: projectRoot })
25
66
  logger.info('')
26
67
 
27
- // ── Step 2: migrate ───────────────────────────────────────────────────────
28
- logger.info('[2/3] Migrating config files from root…')
29
- await migrateCmd.handler({ ...args, yes: true, cwd: projectRoot })
68
+ // ── Step 2: normalize existing .root structure (fix misrouted files) ──────
69
+ logger.info('[2/3] Normalizing .root structure…')
70
+ await normalizeContainer(containerPath, logger)
71
+ logger.success('Structure normalized')
30
72
  logger.info('')
31
73
 
32
- // ── Step 3: prepare ───────────────────────────────────────────────────────
33
- logger.info('[3/3] Preparing root (copying mandatory files + patching scripts)…')
34
- await prepareCmd.handler({ ...args, yes: true })
74
+ // ── Step 3: migrate ALL files from root → .root/ ──────────────────────────
75
+ logger.info('[3/3] Migrating files from root to .root/…')
76
+ await migrateCmd.handler({ ...args, yes: true, cwd: projectRoot })
35
77
  logger.info('')
36
78
 
79
+ const total = await countRootFiles(containerPath)
80
+
37
81
  logger.info('─────────────────────────────────────────')
38
- logger.success('Setup complete! Your project root is clean.')
39
- logger.info('')
40
- logger.info('What happened:')
41
- logger.info(' • .root/ container created')
42
- logger.info(' • Config files moved to .root/configs/')
43
- logger.info(' .env* files moved to .root/env/')
44
- logger.info(' Web assets moved to .root/assets/')
45
- logger.info(' • package.json scripts patched with --config flags')
46
- logger.info(' Mandatory files copied back to root (prepare)')
47
- logger.info('')
48
- logger.info('Next steps:')
49
- logger.info(' rootless statussee what\'s managed')
50
- logger.info(' rootless doctor — verify everything is wired correctly')
51
- logger.info(' rootless watch — auto-sync on .root/ changes')
82
+ logger.success(`Setup complete! ${total} files now managed in .root/`)
83
+ logger.info('')
84
+ logger.info('Your project root is now clean.')
85
+ logger.info('')
86
+ logger.info(' .root/env/ — .env files')
87
+ logger.info(' .root/assets/ — web assets, HTML, images, scripts')
88
+ logger.info(' .root/configs/ tool configs (vite, eslint, jest…)')
89
+ logger.info('')
90
+ logger.info(' Files were REMOVED from root.')
91
+ logger.info(' Run the following before deploying or starting the project:')
92
+ logger.info('')
93
+ logger.info(' rootless preparecopies files back to root')
94
+ logger.info('')
95
+ logger.info('Other commands:')
96
+ logger.info(' rootless status — show what is managed')
97
+ logger.info(' rootless watch — auto-sync .root/ → root on changes')
52
98
  logger.info('─────────────────────────────────────────')
53
99
  },
54
100
  }