@nera-static/nera 1.5.0 → 1.5.1

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/scaffold.js +27 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nera-static/nera",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "The Nera CLI — scaffold, build, preview and update a Nera static site with one command over the @nera-static/core engine",
5
5
  "type": "module",
6
6
  "bin": {
package/src/scaffold.js CHANGED
@@ -34,20 +34,32 @@ const CURRENT_DIR = new Set(['.', './'])
34
34
 
35
35
  export const isCurrentDir = (projectName) => CURRENT_DIR.has(projectName)
36
36
 
37
+ // Letters NFKD does not decompose into a base letter plus an accent.
38
+ const LETTER_FOLDS = { ß: 'ss', æ: 'ae', œ: 'oe', ø: 'o', ł: 'l', đ: 'd' }
39
+
40
+ // npm refuses these names outright, and longer ones than this.
41
+ const NPM_RESERVED = new Set(['node_modules', 'favicon.ico'])
42
+ const NPM_MAX_LENGTH = 214
43
+
37
44
  // The package name for a site scaffolded in place, derived from the folder's
38
- // basename and normalised until it passes validateProjectName: accents
39
- // dropped (`Bäckerei` → `backerei`), lower-case, each run of other characters
40
- // → one `-`, no leading dot, dash or underscore.
45
+ // basename and normalised until it passes validateProjectName and npm's own
46
+ // rules: accents dropped (`Bäckerei` → `backerei`, `Straße` → `strasse`),
47
+ // lower-case, each run of other characters → one `-`, no leading dot, dash or
48
+ // underscore, at most 214 characters. `nera-site` when nothing usable is left.
41
49
  export function projectNameFromDir(dir) {
42
50
  const name = path
43
51
  .basename(path.resolve(dir))
52
+ .toLowerCase()
53
+ .replace(/[ßæœøłđ]/g, (c) => LETTER_FOLDS[c])
44
54
  .normalize('NFKD')
45
55
  .replace(/[\u0300-\u036f]/g, '')
46
- .toLowerCase()
47
56
  .replace(/[^a-z0-9._-]+/g, '-')
48
57
  .replace(/^[._-]+/, '')
49
- .replace(/-+$/, '')
50
- return name === '' ? 'nera-site' : validateProjectName(name)
58
+ .slice(0, NPM_MAX_LENGTH)
59
+ .replace(/[-.]+$/, '')
60
+ return name === '' || NPM_RESERVED.has(name)
61
+ ? 'nera-site'
62
+ : validateProjectName(name)
51
63
  }
52
64
 
53
65
  // In-place scaffolding only goes ahead in an empty folder. Dotfiles such as
@@ -195,8 +207,15 @@ export async function scaffoldProject(projectName, options = {}) {
195
207
  execFileSync('npm', args, { cwd: targetDir, stdio: 'inherit' })
196
208
  }
197
209
 
210
+ // `npm run dev`, not `nera dev`: it works without a global `nera`.
211
+ const nextSteps = [
212
+ ...(inPlace ? [] : [`cd ${projectName}`]),
213
+ ...(install ? [] : ['npm install']),
214
+ 'npm run dev',
215
+ ]
198
216
  console.log('✅ Done!')
199
- const cdLine = inPlace ? '' : ` cd ${projectName}\n`
200
- console.log(`👉 Next steps:\n${cdLine} nera dev\n`)
217
+ console.log(
218
+ `👉 Next steps:\n${nextSteps.map((l) => ` ${l}\n`).join('')}`
219
+ )
201
220
  return targetDir
202
221
  }