Skip to content

Commit

Permalink
chore: 🤖 update nx
Browse files Browse the repository at this point in the history
  • Loading branch information
NetanelBasal committed Feb 21, 2024
1 parent 3716ca4 commit bd15cc8
Show file tree
Hide file tree
Showing 9 changed files with 3,494 additions and 2,968 deletions.
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Nx 18 enables using plugins to infer targets by default
# This is disabled for existing workspaces to maintain compatibility
# For more info, see: https://nx.dev/concepts/inferred-tasks
NX_ADD_PLUGINS=false
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ testem.log
# System Files
.DS_Store
Thumbs.db

.nx/cache
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

/dist
/coverage

/.nx/cache
112 changes: 65 additions & 47 deletions docs-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ const jsdoc2md = require('jsdoc-to-markdown');
const fs = require('fs');
const path = require('path');
const glob = require('glob');
const { minify } = require("terser");
const { minify } = require('terser');

function imageModifier(generator) {
// we chain the query param to trigger refetching of the image.
return '<img src={`${'+generator+'()}?${Math.random()}}`} alt="Random image"/>';
return (
'<img src={`${' + generator + '()}?${Math.random()}}`} alt="Random image"/>'
);
}

function stringModifier(generator) {
Expand All @@ -23,62 +25,77 @@ const functionModifiers = {
randImg: imageModifier,
randChanceBoolean: 'randChanceBoolean({chanceTrue: 0.78}).toString()',
rand: 'rand([1,2,3])',
randBetweenDate: 'randBetweenDate({ from: new Date(\'10/07/2020\'), to: new Date(\'10/07/2025\') }).toString()',
randBetweenDate:
"randBetweenDate({ from: new Date('10/07/2020'), to: new Date('10/07/2025') }).toString()",
randTextRange: 'randTextRange({ min: 10, max: 100 })',
}
};

const skipLivePreview = ['seed'];

jsdoc2md.getTemplateData({
files: glob.sync('packages/falso/src/lib/*.ts'),
configure: 'jsdoc.json'
}).then(res => {
const categories = res.reduce((acc, current) => {
const category = current.category.toLowerCase();

// Handle multiple categories
if (category.includes(',')) {
const categories = category.split(', ');
categories.forEach((c) => {
if (!acc[c]) {
acc[c] = [];
jsdoc2md
.getTemplateData({
files: glob.sync('packages/falso/src/lib/*.ts'),
configure: 'jsdoc.json',
})
.then((res) => {
const categories = res.reduce((acc, current) => {
const category = current.category.toLowerCase();

// Handle multiple categories
if (category.includes(',')) {
const categories = category.split(', ');
categories.forEach((c) => {
if (!acc[c]) {
acc[c] = [];
}

acc[c].push({
...current,
category: c,
});
});
} else {
if (!acc[category]) {
acc[category] = [];
}

acc[c].push({
...current,
category: c,
});
});
}
else {
if (!acc[category]) {
acc[category] = [];
acc[category].push(current);
}

acc[category].push(current);
}

return acc;
}, {});
return acc;
}, {});

const docsOutputPath = path.join('docs', 'docs', 'auto-generated');
if (!fs.existsSync(docsOutputPath)) {
fs.mkdirSync(docsOutputPath);
}

for (let [category, items] of Object.entries(categories)) {
let md = `---\nslug: /${category.toLowerCase()}\n---\n\n# ${capitalize(category)}\n\n`;
const docsOutputPath = path.join('docs', 'docs', 'auto-generated');
if (!fs.existsSync(docsOutputPath)) {
fs.mkdirSync(docsOutputPath);
}

md += items.sort((funcA, funcB) => sortFunctions(funcA, funcB)).map(getDocsSection).join('');
for (let [category, items] of Object.entries(categories)) {
let md = `---\nslug: /${category.toLowerCase()}\n---\n\n# ${capitalize(
category
)}\n\n`;

md += items
.sort((funcA, funcB) => sortFunctions(funcA, funcB))
.map(getDocsSection)
.join('');

fs.writeFileSync(
path.join(docsOutputPath, `${category.toLowerCase()}.mdx`),
md,
{ encoding: 'utf8' }
);
}

fs.writeFileSync(path.join(docsOutputPath, `${category.toLowerCase()}.mdx`), md, { encoding: 'utf8' });
}
const [falsoESMPath] = glob.sync('dist/packages/falso/index.esm.js');

const [falsoESMPath] = glob.sync('dist/packages/falso/index.js');
minify(fs.readFileSync(falsoESMPath, "utf8")).then((minified) => {
fs.writeFileSync(path.join('docs', 'src', 'theme', 'ReactLiveScope', 'falso.min.js'), minified.code);
minify(fs.readFileSync(falsoESMPath, 'utf8')).then((minified) => {
fs.writeFileSync(
path.join('docs', 'src', 'theme', 'ReactLiveScope', 'falso.min.js'),
minified.code
);
});
});
});

function sortFunctions(funcA, funcB) {
if (funcA.name < funcB.name) {
Expand All @@ -97,7 +114,9 @@ function capitalize(string) {
}

function getDocsSection({ name, description, examples }) {
let section = `### \`\`\`${name}\`\`\`\n\n${description}\n\n\`\`\`ts\nimport { ${name} } from '@ngneat/falso';\n\n${examples.join('\n')}\n\`\`\`\n\n`;
let section = `### \`\`\`${name}\`\`\`\n\n${description}\n\n\`\`\`ts\nimport { ${name} } from '@ngneat/falso';\n\n${examples.join(
'\n'
)}\n\`\`\`\n\n`;

if (!skipLivePreview.includes(name)) {
let funcCall = `${name}()`;
Expand All @@ -111,5 +130,4 @@ function getDocsSection({ name, description, examples }) {
}

return section;

}
64 changes: 44 additions & 20 deletions migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,46 @@
"package": "nx",
"name": "rm-default-collection-npm-scope"
},
{
"cli": "nx",
"version": "17.3.0-beta.6",
"description": "Updates the nx wrapper.",
"implementation": "./src/migrations/update-17-3-0/update-nxw",
"package": "nx",
"name": "17.3.0-update-nx-wrapper"
},
{
"cli": "nx",
"version": "18.0.0-beta.2",
"description": "Updates .env to disabled adding plugins when generating projects in an existing Nx workspace",
"implementation": "./src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces",
"x-repair-skip": true,
"package": "nx",
"name": "18.0.0-disable-adding-plugins-for-existing-workspaces"
},
{
"version": "17.1.0-beta.2",
"description": "Move jest executor options to nx.json targetDefaults",
"implementation": "./src/migrations/update-17-1-0/move-options-to-target-defaults",
"package": "@nx/jest",
"name": "move-options-to-target-defaults"
},
{
"cli": "nx",
"version": "16.9.0-beta.1",
"description": "Replace imports of Module Federation utils frm @nx/devkit to @nx/webpack",
"implementation": "./src/migrations/update-16-9-0/migrate-mf-util-usage",
"package": "@nx/devkit",
"name": "update-16-9-0-migrate-mf-usage-to-webpack"
},
{
"cli": "nx",
"version": "16.6.0-beta.0",
"description": "Explicitly set 'updateBuildableProjectDepsInPackageJson' to 'true' in targets that rely on that value as the default.",
"factory": "./src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps",
"package": "@nx/rollup",
"name": "explicitly-set-projects-to-update-buildable-deps"
},
{
"cli": "nx",
"version": "17-2-6-beta.1",
Expand Down Expand Up @@ -78,49 +111,40 @@
"package": "@nx/js",
"name": "update-17-0-0-remove-deprecated-build-options"
},
{
"cli": "nx",
"version": "16.9.0-beta.1",
"description": "Replace imports of Module Federation utils frm @nx/devkit to @nx/webpack",
"implementation": "./src/migrations/update-16-9-0/migrate-mf-util-usage",
"package": "@nx/devkit",
"name": "update-16-9-0-migrate-mf-usage-to-webpack"
},
{
"cli": "nx",
"version": "16.6.0-beta.0",
"description": "Explicitly set 'updateBuildableProjectDepsInPackageJson' to 'true' in targets that rely on that value as the default.",
"factory": "./src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps",
"package": "@nx/rollup",
"name": "explicitly-set-projects-to-update-buildable-deps"
},
{
"version": "16.8.0",
"description": "update-16-8-0-add-ignored-files",
"implementation": "./src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files",
"package": "@nx/linter",
"package": "@nx/eslint",
"name": "update-16-8-0-add-ignored-files"
},
{
"version": "17.0.0-beta.7",
"description": "update-17-0-0-rename-to-eslint",
"implementation": "./src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint",
"package": "@nx/linter",
"package": "@nx/eslint",
"name": "update-17-0-0-rename-to-eslint"
},
{
"version": "17.1.0-beta.1",
"description": "Updates for @typescript-utils/utils v6.9.1+",
"implementation": "./src/migrations/update-17-1-0/update-typescript-eslint",
"package": "@nx/linter",
"package": "@nx/eslint",
"name": "update-typescript-eslint"
},
{
"version": "17.2.0-beta.0",
"description": "Simplify eslintFilePatterns",
"implementation": "./src/migrations/update-17-2-0/simplify-eslint-patterns",
"package": "@nx/linter",
"package": "@nx/eslint",
"name": "simplify-eslint-patterns"
},
{
"version": "17.2.9",
"description": "Move executor options to target defaults",
"implementation": "./src/migrations/update-17-2-9/move-options-to-target-defaults",
"package": "@nx/eslint",
"name": "move-options-to-target-defaults"
}
]
}
31 changes: 17 additions & 14 deletions nx.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{
"tasksRunnerOptions": {
"default": {
"runner": "nx/tasks-runners/default",
"options": {
"cacheableOperations": ["build", "lint", "test", "e2e"]
}
}
},
"extends": "nx/presets/core.json",
"npmScope": "faker",
"affected": {
"defaultBase": "main"
},
Expand All @@ -27,13 +18,25 @@
},
"targetDefaults": {
"build": {
"inputs": ["production", "^production"]
"inputs": ["production", "^production"],
"cache": true
},
"test": {
"inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"]
"@nx/jest:jest": {
"inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"],
"cache": true,
"options": {
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
}
},
"lint": {
"inputs": ["default", "{workspaceRoot}/.eslintrc.json"]
"@nx/eslint:lint": {
"inputs": ["default", "{workspaceRoot}/.eslintrc.json"],
"cache": true
}
},
"pluginsConfig": {
Expand Down
Loading

0 comments on commit bd15cc8

Please sign in to comment.