Browse Source

feat: add CLJS project to `create-tauri-app`, fix: #2822 (#2843)

* include lockfile-lint in devDependencies

* add cljs template

* lockfile lint should be included as part of another pr

* few fixes
- Added url for the create-cljs-app project
- Added beforeDevCommand and beforeBuildCommand
- Make sure to delete redundant lockfile depending on package manager

* reinstall dependencies after deleting lockfiles

* fix eslint check

* add support for `pnpm`

Co-authored-by: amrbashir <48618675+amrbashir@users.noreply.github.com>
West 3 years ago
parent
commit
1c7ee6ec06

+ 3 - 1
tooling/create-tauri-app/src/index.ts

@@ -15,6 +15,7 @@ import { dominator } from './recipes/dominator'
 import { ngcli } from './recipes/ng-cli'
 import { svelte } from './recipes/svelte'
 import { solid } from './recipes/solid'
+import { cljs } from './recipes/cljs'
 import { install, checkPackageManager } from './dependency-manager'
 import { shell } from './shell'
 import { updatePackageJson } from './helpers/update-package-json'
@@ -126,7 +127,8 @@ const allRecipes: Recipe[] = [
   ngcli,
   svelte,
   solid,
-  dominator
+  dominator,
+  cljs
 ]
 
 const recipeByShortName = (name: string): Recipe | undefined =>

+ 78 - 0
tooling/create-tauri-app/src/recipes/cljs.ts

@@ -0,0 +1,78 @@
+// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-License-Identifier: MIT
+
+import { join } from 'path'
+import { shell } from '../shell'
+import { Recipe } from '../types/recipe'
+import { rmSync, existsSync } from 'fs'
+
+const cljs: Recipe = {
+  descriptiveName: {
+    name: 'ClojureScript (https://github.com/filipesilva/create-cljs-app)',
+    value: 'cljs'
+  },
+  shortName: 'cljs',
+  extraNpmDevDependencies: [],
+  extraNpmDependencies: [],
+  configUpdate: ({ cfg, packageManager }) => ({
+    ...cfg,
+    distDir: `../public`,
+    devPath: 'http://localhost:3000',
+    beforeDevCommand: `${
+      packageManager === 'npm' ? 'npm run' : packageManager
+    } start`,
+    beforeBuildCommand: `${
+      packageManager === 'npm' ? 'npm run' : packageManager
+    } build`
+  }),
+  preInit: async ({ cwd, cfg, packageManager }) => {
+    const npmLock = join(cwd, cfg.appName, 'package-lock.json')
+    const yarnLock = join(cwd, cfg.appName, 'yarn.lock')
+    const nodeModules = join(cwd, cfg.appName, 'node_modules')
+
+    if (packageManager === 'yarn') {
+      await shell('yarn', ['create', 'cljs-app', `${cfg.appName}`], {
+        cwd
+      })
+
+      // `create-cljs-app` has both a `package-lock.json` and a `yarn.lock`
+      // so it is better to remove conflicting lock files and install fresh node_modules
+      if (existsSync(npmLock)) rmSync(npmLock)
+      if (existsSync(nodeModules))
+        rmSync(nodeModules, {
+          recursive: true,
+          force: true
+        })
+
+      await shell('yarn', ['install'], { cwd: join(cwd, cfg.appName) })
+    } else {
+      await shell('npx', ['create-cljs-app@latest', `${cfg.appName}`], {
+        cwd
+      })
+
+      // Remove Unnecessary lockfile as above.
+      if (existsSync(yarnLock)) rmSync(yarnLock)
+      // also remove package-lock.json if current package manager is pnpm
+      if (packageManager === 'pnpm' && existsSync(npmLock)) rmSync(npmLock)
+      if (existsSync(nodeModules))
+        rmSync(nodeModules, {
+          recursive: true,
+          force: true
+        })
+
+      await shell(packageManager, ['install'], { cwd: join(cwd, cfg.appName) })
+    }
+  },
+  postInit: async ({ cfg, packageManager }) => {
+    console.log(`
+    Your installation completed.
+
+    $ cd ${cfg.appName}
+    $ ${packageManager === 'npm' ? 'npm run' : packageManager} tauri dev
+    `)
+    return await Promise.resolve()
+  }
+}
+
+export { cljs }

+ 0 - 1
tooling/create-tauri-app/src/recipes/ng-cli.ts

@@ -59,7 +59,6 @@ const ngcli: Recipe = {
     ]
   },
   preInit: async ({ cwd, cfg, answers, packageManager }) => {
-    // Angular CLI creates the folder for you
     await shell(
       'npx',
       [

+ 1 - 1
tooling/create-tauri-app/src/recipes/react.ts

@@ -110,7 +110,7 @@ export const cra: Recipe = {
           recursive: true,
           force: true
         })
-      await shell('pnpm', ['install'], { cwd })
+      await shell('pnpm', ['install'], { cwd: join(cwd, cfg.appName) })
     }
 
     await afterCra(cwd, cfg.appName, template === 'cra.ts')

+ 0 - 1
tooling/create-tauri-app/src/recipes/vite.ts

@@ -58,7 +58,6 @@ const vite: Recipe = {
       template = answers.template ? (answers.template as string) : 'vue'
     }
 
-    // Vite creates the folder for you
     if (packageManager === 'yarn') {
       await shell(
         'yarn',

+ 0 - 1
tooling/create-tauri-app/src/recipes/vue-cli.ts

@@ -16,7 +16,6 @@ const vuecli: Recipe = {
   extraNpmDependencies: [],
   configUpdate: ({ cfg }) => cfg,
   preInit: async ({ cwd, cfg, ci, packageManager }) => {
-    // Vue CLI creates the folder for you
     await shell(
       'npx',
       [

+ 1 - 1
tooling/create-tauri-app/test/spawn.test.mjs

@@ -24,7 +24,7 @@ const api = path.resolve('../api/')
 const manager = process.env.TAURI_RUN_MANAGER || 'yarn'
 const recipes = process.env.TAURI_RECIPE
   ? process.env.TAURI_RECIPE.split(',')
-  : ['vanillajs', 'cra', 'vite', 'ngcli', 'solid']
+  : ['vanillajs', 'cra', 'vite', 'ngcli', 'solid', 'cljs']
 const parallelize = process.env.TAURI_RECIPE_PARALLELIZE || false
 
 main(function* start() {