Skip to content

Commit

Permalink
fix: continue fixes for Windows scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
GerkinDev committed Jun 26, 2022
1 parent 6632b2f commit 40f8d1d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
28 changes: 28 additions & 0 deletions package-lock.json

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

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@
"precommit": "npm run projects:patch -- diff && npm run lint -- --cache && npm run projects:build && npm run projects:test -- --onlyChanged && npm run docs",
"prepare": "npm run prepare:husky",
"prepare:husky": "run-script-os",
"prepare:husky:windows": " if exist './node_modules/husky' { husky install }",
"prepare:husky:default": "[ -d ./node_modules/husky ] && husky install || true",
"prepare:husky:windows": "if exist './node_modules/husky' { husky install }",
"projects:build": "npm run projects:patch -- apply && node ./tools/s-projects \"npm run build -- --pretty\"",
"projects:build:clean": "npm run build:clean --workspaces",
"projects:build:watch": "npm run projects:build && node ./tools/p-projects \"npm run build -- --watch --preserveWatchOutput --pretty\"",
"projects:patch": "node ./tools/typedoc-patcher --no-stash",
"projects:test": "jest",
"release": "run-script-os",
"release:windows": "echo \"Unsupported platform for release. Run this command only from an UNIX-like environment.\"",
"release:default": "./tools/release.sh",
"test:ci": "JEST_JUNIT_OUTPUT_NAME=junit.xml jest --config jest.config.ci.js --all --ci --reporters=default --reporters=jest-junit",
"release:windows": "echo \"Unsupported platform for release. Run this command only from an UNIX-like environment.\"",
"test:ci": "cross-env JEST_JUNIT_OUTPUT_NAME=junit.xml jest --config jest.config.ci.js --all --ci --reporters=default --reporters=jest-junit",
"test:ci:coverage": "npm run test:ci -- --collectCoverage",
"tools:bump-versions": "NODE_NO_WARNINGS=1 node tools/bump-versions",
"tools:infer-next-version": "NODE_NO_WARNINGS=1 node tools/infer-next-version",
"tools:packages-sync": "NODE_NO_WARNINGS=1 node tools/package-proto"
"tools:bump-versions": "cross-env NODE_NO_WARNINGS=1 node tools/bump-versions",
"tools:infer-next-version": "cross-env NODE_NO_WARNINGS=1 node tools/infer-next-version",
"tools:packages-sync": "cross-env NODE_NO_WARNINGS=1 node tools/package-proto"
},
"commitlint": {
"extends": [
Expand All @@ -61,6 +61,7 @@
"@typescript-eslint/parser": "^5.28.0",
"chalk": "^4.1.2",
"concurrently": "^7.2.2",
"cross-env": "^7.0.3",
"eslint": "^8.18.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.26.0",
Expand Down
22 changes: 13 additions & 9 deletions tools/package-proto.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const assert = require( 'assert' );
const { createHash } = require( 'crypto' );
const { readFile, writeFile, mkdir, copyFile, access, unlink } = require( 'fs/promises' );
const { resolve, join } = require( 'path' );
const { EOL } = require( 'os' );
const { resolve, join, normalize } = require( 'path' );

const { bold, yellow } = require( 'chalk' );
const { defaultsDeep, partition, memoize, isString, cloneDeep, uniq } = require( 'lodash' );

const { spawn, globAsync, selectProjects, createStash } = require( './utils' );

const normalizePath = path => normalize( path ).replace( /\\/g, '/' );
const getDocsUrl = pkgJson => `https://knodescommunity.github.io/typedoc-plugins/modules/${( pkgJson.name ?? assert.fail( 'No name' ) ).replace( /[^a-z0-9]/gi, '_' )}.html`;
/**
* @typedef {import('./utils').Project} Project
Expand Down Expand Up @@ -69,14 +71,16 @@ const packageJson = () => {
await writeFile( packagePath, JSON.stringify( newProjectPkg, null, 2 ) );
},
tearDown: async( proto, projects ) => {
await spawn( 'npx', [ 'format-package', '--write', ...projects.map( p => resolve( p.path, 'package.json' ) ) ] );
await spawn(
process.platform === 'win32' ? '.\\node_modules\\.bin\\format-package.cmd' : './node_modules/.bin/format-package',
[ '--write', ...projects.map( p => normalizePath( resolve( p.path, 'package.json' ) ) ) ] );
},
handleFile: filename => /(\/|^)package\.json$/.test( filename ),
};
};

const checksum = async file => createHash( 'md5' )
.update( await readFile( file, 'utf-8' ), 'utf-8' )
.update( ( await readFile( file, 'utf-8' ) ).replace( /\r?\n/g, '\n' ), 'utf-8' )
.digest( 'hex' );

/**
Expand All @@ -88,7 +92,7 @@ const syncFs = () => {
try {
const cacheContent = ( await tryReadFile( cacheFile, 'utf-8' ) ) ?? '';
return cacheContent
.split( '\n' )
.split( /\r?\n/ )
.filter( v => v.trim() )
.reduce( ( acc, line ) => {
const parts = line.split( '::' ).map( p => p.trim() );
Expand Down Expand Up @@ -209,10 +213,10 @@ const readme = () => {
}
let newHeader = `# ${packageContent.name}`;
if( packageContent.description ){
newHeader += `\n\n> ${packageContent.description}`;
newHeader += `${EOL}${EOL}> ${packageContent.description}`;
}
const shield = ( label, suffix, link ) => `[![${label}](https://img.shields.io${suffix}?style=for-the-badge)](${link})`;
newHeader += `\n
newHeader += `${EOL}
${shield( 'npm version', `/npm/v/${packageContent.name}`, `https://www.npmjs.com/package/${packageContent.name}` )}
${shield( 'npm downloads', `/npm/dm/${packageContent.name}`, `https://www.npmjs.com/package/${packageContent.name}` )}
[![Compatible with TypeDoc](https://img.shields.io/badge/For%20typedoc-${packageContent.peerDependencies.typedoc}-green?logo=npm&style=for-the-badge)](https://www.npmjs.com/package/typedoc)
Expand Down Expand Up @@ -252,11 +256,11 @@ For more infos, please refer to [the documentation](${getDocsUrl( packageContent
${newHeader}
<!-- HEADER end -->
`;
const headerRegex = /^<!-- HEADER -->(.*?)<!-- HEADER end -->\n/s;
const headerRegex = /^<!-- HEADER -->(.*?)<!-- HEADER end -->\r?\n/s;
if( !headerRegex.test( readmeContent ) ){
console.log( yellow( `Header not found in ${readmeFile}` ) );
}
const newReadme = newHeader + readmeContent.replace( /^<!-- HEADER -->(.*?)<!-- HEADER end -->(\n|$)/s, '' );
const newReadme = newHeader + readmeContent.replace( /^<!-- HEADER -->(.*?)<!-- HEADER end -->(\r?\n|$)/s, '' );
await writeFile( readmeFile, newReadme );
};
return {
Expand All @@ -283,7 +287,7 @@ if( require.main === module ){
}
}, { explicitProjects: [], noStash: false } );
const projects = selectProjects( explicitProjects );
const protoDir = resolve( __dirname, 'proto' );
const protoDir = normalizePath( resolve( __dirname, 'proto' ) );
( async () => {
if( !noStash ){
await createStash( `Sync packages ${projects.map( p => p.name ).join( ' ' )}` );
Expand Down

0 comments on commit 40f8d1d

Please sign in to comment.