Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install quire-11ty to a project sub-directory #652

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/cli/bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env -S node --no-warnings

process.removeAllListeners('warning')

import cli from '#src/main.js'
import packageConfig from '#root/package.json' assert { type: 'json' }
import updateNotifier from 'update-notifier'

process.removeAllListeners('warning')

const INTERVAL = Object.freeze({
MINUTES: 1000 * 60 * 1,
HOURLY: 1000 * 60 * 60,
Expand Down
9 changes: 5 additions & 4 deletions packages/cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"conf": "^11.0.1",
"cross-env": "^7.0.3",
"del": "^7.0.0",
"epubjs-cli": "^0.1.1",
"epubjs-cli": "^0.1.2",
"execa": "^6.1.0",
"fs-extra": "^11.1.0",
"hosted-git-info": "^6.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/11ty/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const getEleventyRoot = () => {
// } catch (error) {
// throw new Error(`[CLI:11ty] Unable to read project directory for eleventy config ${error}`)
// }
return projectRoot
return path.join(projectRoot, '11ty')
}

export const eleventyRoot = getEleventyRoot()
Expand Down
40 changes: 20 additions & 20 deletions packages/cli/src/lib/quire/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ async function install(version, options={}) {
* these must be `devDependencies` so that they are not bundled into
* the final `_site` package when running `quire build`
*/
const currentWorkingDirectory = cwd()
const versionDir = path.join(absoluteInstallPath, version)
chdir(versionDir)
await execaCommand('npm cache clean --force')
Expand All @@ -193,7 +192,7 @@ async function install(version, options={}) {
* @return {Promise}
*/
async function installInProject(projectPath, version, options={}) {
console.debug(`[CLI:quire] installing quire-11ty@${version} into ${projectPath}`)
console.debug(`[CLI:quire] installing ${PACKAGE_NAME}@${version} into ${projectPath}`)

/**
* delete `package.json` from starter project, as it will be replaced with
Expand All @@ -206,58 +205,59 @@ async function installInProject(projectPath, version, options={}) {
.rm(['package.json'])
.catch((error) => console.error('[CLI:error] ', error))

const temp11tyDirectory = '.temp'
const installPath = path.join(projectPath, '11ty')
const tempDir = '.temp'
/**
* `Destination` is relative to `node_modules` of the working-directory
* so we have included a relative path to parent directory in order to
* install versions to a different local path.
* Destination is relative to `node_modules` in the working-directory,
* in order to install to a different local path we set `Desitination`
* to a path relative to the parent directory then copy to `installDir`.
* @see https://github.com/scott-lin/install-npm-version
*/
const installOptions = {
Destination: path.join('..', temp11tyDirectory),
Destination: path.join('..', tempDir),
Debug: false,
Overwrite: options.force || options.overwrite || false,
Verbosity: options.debug ? 'Debug' : 'Silent',
WorkingDirectory: projectPath
}
await inv.Install(`${PACKAGE_NAME}@${version}`, installOptions)

// delete empty `node_modules` directory that `install-npm-version` creates
// Delete the empty `node_modules` directory created by `install-npm-version`
const invNodeModulesDir = path.join(projectPath, 'node_modules')
if (fs.existsSync(invNodeModulesDir)) fs.rmdir(invNodeModulesDir)

// Copy all files installed in `.temp` to projectPath
fs.copySync(path.join(projectPath, '.temp'), projectPath)
// Copy files installed in temp to the install directory
fs.copySync(path.join(projectPath, tempDir), installPath)

console.debug('[CLI:quire] installing dev dependencies into quire project')
/**
* Manually install necessary dev dependencies to run 11ty;
* these must be `devDependencies` so that they are not bundled into
* the final `_site` package when running `quire build`
*/
await execaCommand('npm cache clean --force', { cwd: projectPath })
await execaCommand('npm cache clean --force', { cwd: installPath })
try {
await execaCommand('npm install --save-dev', { cwd: projectPath })
await execaCommand('npm install --save-dev', { cwd: installPath })
} catch(error) {
console.warn(`[CLI:error]`, error)
fs.removeSync(projectPath)
fs.removeSync(installPath)
return
}

const eleventyFilesToCommit = fs
.readdirSync(path.join(projectPath, temp11tyDirectory))
.filter((filePath) => filePath !== 'node_modules')
// const eleventyFilesToCommit = fs
// .readdirSync(tempDir)
// .filter((filePath) => filePath !== 'node_modules')

eleventyFilesToCommit.push('package-lock.json')
// eleventyFilesToCommit.push('package-lock.json')

/**
* Create an additional commit of new `@thegetty/quire-11ty` files in repository
* @todo use a localized string for the commit message
*/
await git.add(eleventyFilesToCommit).commit('Adds `@thegetty/quire-11ty` files')
// await git.add(eleventyFilesToCommit).commit('Adds `@thegetty/quire-11ty` files')

// remove temporary 11ty install directory
fs.removeSync(path.join(projectPath, temp11tyDirectory))
// Delete the temporary 11ty install directory
fs.removeSync(path.join(projectPath, tempDir))
}

/**
Expand Down