• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

scriptype / writ-cms / 21048924467

15 Jan 2026 10:42PM UTC coverage: 38.215% (-0.6%) from 38.816%
21048924467

push

github

scriptype
Primitively implement main cms flow

If the cms is started with ssgOptions, then proceed to initing the
editor with the rootDirectory (started from $ writ start)

Otherwise ($ writ create or desktop app), try to find the most recent
project in a workspace directory (writ projects). If found, init the
editor with the project's path. Else, proceed to onboarding.

Onboarding makes sure the workspace + a new project now exist.

While at it:
- Keep watched directory in state so when ssg.watch() is called, we can
check if a specific directory is watched or not. And if a different
directory was being watched when ssg.watch() is called, stop the watcher
and start watching the new one.
- Pass the api object itself to its members, so they can sphagettify

621 of 3681 branches covered (16.87%)

Branch coverage included in aggregate %.

0 of 109 new or added lines in 7 files covered. (0.0%)

7 existing lines in 2 files now uncovered.

2171 of 3625 relevant lines covered (59.89%)

1727.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/cms/api/models/workspace.js
NEW
1
const { homedir } = require('os')
×
NEW
2
const { join } = require('path')
×
NEW
3
const { mkdir, readdir, stat } = require('fs/promises')
×
4

NEW
5
const createWorkspaceModel = (state) => {
×
NEW
6
  const directoryName = 'writ projects'
×
NEW
7
  const directoryPath = join(homedir(), directoryName)
×
8

NEW
9
  const createProject = async (name) => {
×
NEW
10
    const path = join(directoryPath, name)
×
NEW
11
    const stats = await stat(path)
×
NEW
12
    return {
×
13
      name,
14
      path,
15
      dateModified: stats.mtime
16
    }
17
  }
18

NEW
19
  return {
×
20
    async get() {
NEW
21
      try {
×
NEW
22
        const directory = await readdir(directoryPath, { withFileTypes: true })
×
NEW
23
        const isProject = item => item.isDirectory()
×
NEW
24
        const projects = await Promise.all(
×
25
          directory
26
            .filter(isProject)
NEW
27
            .map(item => createProject(item.name))
×
NEW
28
            .sort((a, b) => b.dateModified - a.dateModified)
×
29
        )
NEW
30
        return {
×
31
          projects
32
        }
33
      } catch (e) {
NEW
34
        return {}
×
35
      }
36
    },
37

38
    async create() {
NEW
39
      try {
×
NEW
40
        console.log('api.workspace.creating workspace folder')
×
NEW
41
        await mkdir(directoryPath)
×
42
      } catch (e) {
NEW
43
        if (e.code !== 'EEXIST') {
×
NEW
44
          console.log('api.workspace.create.error', e)
×
NEW
45
          throw e
×
46
        }
NEW
47
        console.log('workspace already exists')
×
48
      }
NEW
49
      return this.get()
×
50
    },
51

52
    async createProject({ name }) {
NEW
53
      await this.create()
×
NEW
54
      const path = join(directoryPath, name)
×
NEW
55
      await mkdir(path)
×
NEW
56
      return createProject(name)
×
57
    }
58
  }
59
}
60

NEW
61
module.exports = createWorkspaceModel
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc