-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): scaffold out
astro add
command (#2849)
* feat(cli): scaffold out `astro add` command * added first babel transforms * Format output * Added changes confirmation * Error flow * Add dependencies * feat(cli): astro add cleanup pass * feat: add support for tailwind * chore: update lockfile * fix: types * chore: rever @proload/core bump * chore: add changeset * chore: rollback dep update * Added spinners * chore: remove extra deps * Removed extra argument * Use `execa` instead of `exec` * Changed how lines are trimmed within diffLines * refactor: move add to core * refactor: remove old add entrypoint * refactor: simplify wording * feat: improve diff * feat: improve diff and logging, add interactive prompt when no args passed * Formatted files * Added --yes * feat: improve logging for install command * Fixed execa * Added help message to add * refactor: extract consts to own file * feat: remove implicit projectRoot behavior * feat: improve error handling, existing integrations * fix(tailwind): ensure existing tailwind config is not overwritten * refactor: prefer cwd to projectRoot flag * chore: add refactor notes * refactor: throw createPrettyError > implicit bail * refactor: cleanup language * feat(cli): prompt user before generating tailwind config * fix(cli): update config generation to use cwd * fix: resolve root from cwd * chore: update changelog Co-authored-by: JuanM04 <[email protected]>
- Loading branch information
1 parent
07a64be
commit 72ef7ae
Showing
12 changed files
with
792 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
'astro': minor | ||
--- | ||
|
||
Introduce new `astro add` command to automatically configure integrations. | ||
|
||
```shell | ||
npx astro add | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
content: [], | ||
theme: { | ||
extend: {}, | ||
}, | ||
plugins: [], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import traverse from '@babel/traverse'; | ||
import generator from '@babel/generator'; | ||
import * as t from '@babel/types'; | ||
import parser from '@babel/parser'; | ||
|
||
// @ts-ignore @babel/traverse isn't ESM and needs this trick | ||
export const visit = traverse.default as typeof traverse; | ||
export { t }; | ||
|
||
export async function generate(ast: t.File) { | ||
// @ts-ignore @babel/generator isn't ESM and needs this trick | ||
const astToText = generator.default as typeof generator; | ||
const { code } = astToText(ast); | ||
return code; | ||
} | ||
|
||
export const parse = (code: string) => parser.parse(code, { sourceType: 'unambiguous', plugins: ['typescript'] }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const FIRST_PARTY_FRAMEWORKS = [ | ||
{ value: 'react', title: 'React' }, | ||
{ value: 'preact', title: 'Preact' }, | ||
{ value: 'vue', title: 'Vue' }, | ||
{ value: 'svelte', title: 'Svelte' }, | ||
{ value: 'solid-js', title: 'Solid' }, | ||
{ value: 'lit', title: 'Lit' }, | ||
]; | ||
export const FIRST_PARTY_ADDONS = [ | ||
{ value: 'tailwind', title: 'Tailwind' }, | ||
{ value: 'turbolinks', title: 'Turbolinks' }, | ||
{ value: 'partytown', title: 'Partytown' }, | ||
{ value: 'sitemap', title: 'Sitemap' }, | ||
]; | ||
export const ALIASES = new Map([ | ||
['solid', 'solid-js'], | ||
['tailwindcss', 'tailwind'], | ||
]); | ||
export const CONFIG_STUB = `import { defineConfig } from 'astro/config';\n\nexport default defineConfig({});`; | ||
export const TAILWIND_CONFIG_STUB = `module.exports = { | ||
content: [], | ||
theme: { | ||
extend: {}, | ||
}, | ||
plugins: [], | ||
}\n`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { t, visit } from './babel.js'; | ||
|
||
export function ensureImport(root: t.File, importDeclaration: t.ImportDeclaration) { | ||
let specifiersToFind = [...importDeclaration.specifiers]; | ||
|
||
visit(root, { | ||
ImportDeclaration(path) { | ||
if (path.node.source.value === importDeclaration.source.value) { | ||
path.node.specifiers.forEach((specifier) => | ||
specifiersToFind.forEach((specifierToFind, i) => { | ||
if (specifier.type !== specifierToFind.type) return; | ||
if (specifier.local.name === specifierToFind.local.name) { | ||
specifiersToFind.splice(i, 1); | ||
} | ||
}) | ||
); | ||
} | ||
}, | ||
}); | ||
|
||
if (specifiersToFind.length === 0) return; | ||
|
||
visit(root, { | ||
Program(path) { | ||
const declaration = t.importDeclaration(specifiersToFind, importDeclaration.source); | ||
const latestImport = path | ||
.get('body') | ||
.filter((statement) => statement.isImportDeclaration()) | ||
.pop(); | ||
|
||
if (latestImport) latestImport.insertAfter(declaration); | ||
else path.unshiftContainer('body', declaration); | ||
}, | ||
}); | ||
} |
Oops, something went wrong.