Skip to content

Commit

Permalink
Adding the builder-add schematics to installe the cli globally
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyperxq committed Apr 3, 2024
1 parent da59892 commit ee1495d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pbuilder/astro",
"version": "1.0.4",
"version": "1.1.1",
"description": "A set schematics for astro",
"scripts": {
"build": "rollup -c --bundleConfigAsCjs",
Expand Down
44 changes: 32 additions & 12 deletions packages/astro/src/builder-add/builder-add.factory.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
import { Rule, SchematicContext, Tree, noop } from '@angular-devkit/schematics';
import { NodeDependencyType, addPackageJsonDependency, installDependencies } from '../utils';
import { Rule, noop } from '@angular-devkit/schematics';
import { Spinner, logger, spawnAsync } from '../utils';

export function addFactory({ installCli, packageManager }: { installCli: boolean; packageManager: string }): Rule {
export function addFactory({
installCli,
packageManager,
}: {
installCli: boolean | string;
packageManager: string;
}): Rule {
return () => {
return installCli ? installCliDev(packageManager) : noop();
const shouldInstallCli = installCli === 'false' ? false : !!installCli;
return shouldInstallCli ? installCliDev(packageManager) : noop();
};
}

function installCliDev(packageManager: string): Rule {
return (tree: Tree, context: SchematicContext) => {
addPackageJsonDependency(tree, {
type: NodeDependencyType.Dev,
name: '@pbuilder/astro-cli',
version: '1.0.0',
overwrite: true,
});
return async () => {
const packageManagerCommands = {
npm: 'install',
yarn: 'add',
pnpm: 'add',
cnpm: 'install',
bun: 'add',
};

return installDependencies(context, packageManager);
try {
await spawnAsync(
packageManager,
[packageManagerCommands[packageManager], `--save-dev --save-exact @pbuilder/astro-cli -g`],
{
cwd: process.cwd(),
stdio: 'inherit',
shell: true,
},
);
} catch (e) {
logger.error(e.message);
}
};
}
2 changes: 1 addition & 1 deletion packages/astro/src/builder-add/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"installCli": {
"type": "string",
"description": "Install the astro cli into the project",
"x-prompt": "Would you like to install the pastro CLI instead to use the generic schematic CLI?",
"x-prompt": "Would you like to install the pastro CLI globally?",
"default": false,
"aliases": [
"ic"
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/builder-generate/component/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"$id": "EmptyFolder",
"title": "Add a component",
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% if(layoutName) { %>---
import <%= layoutName %> from '<%= relativeLayoutPath %>';
---
<layoutName>
</layoutName><% } else { %>---
<<%= layoutName %>>
</<%= layoutName %>><% } else { %>---
---<% }%>
7 changes: 2 additions & 5 deletions packages/astro/src/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
"builder-add": {
"description": "Builder add for astro collection",
"factory": "./builder-add/builder-add.factory#addFactory",
"schema": "./builder-add/schema.json",
"aliases": [
"p"
]
"schema": "./builder-add/schema.json"
},
"layout": {
"description": "Allows to create astro layout",
Expand All @@ -30,7 +27,7 @@
"factory": "./builder-generate/page/page.factory#pageFactory",
"schema": "./builder-generate/page/schema.json",
"aliases": [
"p"
"pg"
]
}
}
Expand Down

0 comments on commit ee1495d

Please sign in to comment.