Skip to content

Commit

Permalink
Improve npm ci/update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiriVulpes committed Jan 7, 2025
1 parent f44d63e commit f18d224
Show file tree
Hide file tree
Showing 9 changed files with 866 additions and 1,073 deletions.
1,844 changes: 798 additions & 1,046 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions src/package-lock.json

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

4 changes: 3 additions & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"private": true,
"dependencies": {
"api.fluff4.me": "^1.0.231",
"prosemirror-example-setup": "1.2.3",
"prosemirror-markdown": "1.13.1",
"prosemirror-state": "1.4.3",
"prosemirror-view": "1.34.3",
"source-map-support": "0.5.21"
},
"devDependencies": {
"api.fluff4.me": "^1.0.233"
}
}
4 changes: 2 additions & 2 deletions tasks/chiri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Env from './utility/Env'
import Task from './utility/Task'

export default Task('chiri', () =>
Task.cli(Env.ENVIRONMENT === 'dev' ? { env: {} } : {}, 'chiri', 'style/index.chiri', '--out', 'docs', '--out-dts', 'src'))
Task.cli(Env.ENVIRONMENT === 'dev' ? { env: {} } : {}, 'NPM:chiri', 'style/index.chiri', '--out', 'docs', '--out-dts', 'src'))

export const chiriwatch = Task('chiriwatch', () =>
Task.cli(
Expand All @@ -15,4 +15,4 @@ export const chiriwatch = Task('chiriwatch', () =>
CHIRI_INSPECT_PORT: Env.CHIRI_INSPECT_PORT,
},
},
'chiri', 'style/index.chiri', '--out', 'docs', '--out-dts', 'src', '-w'))
'NPM:chiri', 'style/index.chiri', '--out', 'docs', '--out-dts', 'src', '-w'))
44 changes: 37 additions & 7 deletions tasks/ci_dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default Task('ci:dev', async () => {
if (Env.ENVIRONMENT !== 'dev')
return

await Task.cli('PATH:npm', 'ci')
const packageJsonString = await fs.readFile('./package.json', 'utf8')

type Link = [name: string, path: string]
const linkModules = (Env.NPM_LINK ?? '')
Expand All @@ -19,28 +19,58 @@ export default Task('ci:dev', async () => {
.map(([name, modulePath]) => [name, modulePath.startsWith('"') ? modulePath.slice(1, -1) : modulePath] as Link)
.map(([name, modulePath]) => [name, path.resolve(`../${modulePath}`)] as Link)

const packageJsonString = await fs.readFile('./package.json', 'utf8')
////////////////////////////////////
//#region Uninstall custom stuff

const uninstallModules = ['lint', ...linkModules.map(([name]) => name)]
await Task.cli('NPM:PATH:npm', 'uninstall', ...uninstallModules, '--save', '--no-audit', '--no-fund')

//#endregion
////////////////////////////////////

await Task.cli('NPM:PATH:npm', 'ci', '--no-audit', '--no-fund')

////////////////////////////////////
//#region Update lint config

Log.info(`Fetching ${ansi.lightCyan('lint@latest')}...`)
let response = ''
await Task.cli({ stdout: data => response += data.toString() }, 'PATH:git', 'ls-remote', 'https://github.com/fluff4me/lint.git', 'HEAD')
const lintSHA = response.trim().split(/\s+/)[0]
if (!lintSHA)
throw new Error('Failed to get SHA of latest commit of lint repository')

Log.info(`Installing ${ansi.lightCyan(`lint#${lintSHA}`)}...`)
const lintPackageVersionString = `github:fluff4me/lint#${lintSHA}`
await Task.cli('NPM:PATH:npm', 'install', lintPackageVersionString, '--save-dev', '--no-audit', '--no-fund')

//#endregion
////////////////////////////////////

const packageLockJsonString = await fs.readFile('./package-lock.json', 'utf8')

////////////////////////////////////
//#region Link local packages

let error: Error | undefined
try {
for (const [name] of linkModules)
await Task.cli('PATH:npm', 'uninstall', name)

for (const [name, linkModule] of linkModules) {
Log.info(`Linking ${ansi.lightCyan(name)}...`)
await Task.cli('PATH:npm', 'link', linkModule, '--save')
await Task.cli('NPM:PATH:npm', 'link', linkModule, '--save', '--no-audit', '--no-fund')
}
}
catch (err) {
error = err as never
}

//#endregion
////////////////////////////////////

await fs.writeFile('./package.json', packageJsonString)
await fs.writeFile('./package-lock.json', packageLockJsonString)

if (error) {
await Task.cli('PATH:npm', 'ci')
await Task.cli('NPM:PATH:npm', 'ci', '--no-audit', '--no-fund')
console.error(error)
process.exit(1)
}
Expand Down
4 changes: 2 additions & 2 deletions tasks/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import Log from './utility/Log'
import Task from './utility/Task'

export default Task('install', async () => {
await Task.cli({ cwd: 'src' }, 'PATH:npm', Env.ENVIRONMENT === 'dev' ? 'install' : 'ci')
await Task.cli({ cwd: 'src' }, 'NPM:PATH:npm', Env.ENVIRONMENT === 'dev' ? 'install' : 'ci', '--no-audit', '--no-fund')
if (Env.ENVIRONMENT === 'dev') {
Log.info(`Installing ${ansi.lightCyan('api.fluff4.me@latest')}...`)
await Task.cli({ cwd: 'src' }, 'PATH:npm', 'install', 'api.fluff4.me@latest')
await Task.cli({ cwd: 'src' }, 'NPM:PATH:npm', 'install', 'api.fluff4.me@latest', '--save-dev', '--no-audit', '--no-fund')
}

const typesPath = 'src/node_modules/api.fluff4.me/index.d.ts'
Expand Down
4 changes: 2 additions & 2 deletions tasks/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ class Reformatter {
}

export default Task('ts', task => task.series(
() => Task.cli({ cwd: 'src', stdout: new Reformatter().out }, 'tsc', '--pretty',
() => Task.cli({ cwd: 'src', stdout: new Reformatter().out }, 'NPM:tsc', '--pretty',
...options),
() => fs.unlink('docs/index.tsbuildinfo')))

export const tsWatch = Task('ts (watch)', () =>
Task.cli({ cwd: 'src', stdout: new Reformatter().out }, 'tsc', '--watch', '--preserveWatchOutput', '--pretty',
Task.cli({ cwd: 'src', stdout: new Reformatter().out }, 'NPM:tsc', '--watch', '--preserveWatchOutput', '--pretty',
...options))
13 changes: 9 additions & 4 deletions tasks/utility/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,22 @@ namespace Task {
export function cli (options: ITaskCLIOptions, command: string, ...args: string[]): Promise<void>
export function cli (options: ITaskCLIOptions | string, command?: string, ...args: string[]) {
return new Promise<void>((resolve, reject) => {
const ext = process.platform === 'win32' ? '.cmd' : ''

if (typeof options === 'string') {
args.unshift(command!)
command = options
options = {}
}

command = command!
command = command.startsWith('PATH:') ? command.slice(5) : path.resolve(`node_modules/.bin/${command}`)
const childProcess = spawn(command + ext, [...args],

if (command.startsWith('NPM:'))
command = `${command.slice(4)}${process.platform === 'win32' ? '.cmd' : ''}`

command = command.startsWith('PATH:')
? command.slice(5)
: path.resolve(`node_modules/.bin/${command}`)

const childProcess = spawn(command, [...args],
{ stdio: [process.stdin, options.stdout ? 'pipe' : process.stdout, process.stderr], cwd: options.cwd, env: options.env })

if (options.stdout)
Expand Down
4 changes: 2 additions & 2 deletions tasks/weaving.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Task from './utility/Task'

export default Task('weave', () =>
Task.cli('weaving', './lang', '--out', './docs', '--outTypes', './src'))
Task.cli('NPM:weaving', './lang', '--out', './docs', '--outTypes', './src'))

export const weavewatch = Task('weavewatch', () =>
Task.cli(
{
env: {
},
},
'weaving', './lang', '--watch', '--out', './docs', '--outTypes', './src', '--outWhitespace'))
'NPM:weaving', './lang', '--watch', '--out', './docs', '--outTypes', './src', '--outWhitespace'))

0 comments on commit f18d224

Please sign in to comment.