mrgrain / projen-from-git

A projen project that can be used directly from a git repository w/o publishing.
MIT License
3 stars 1 forks source link

Error installing from git #4

Open iOnline247 opened 1 year ago

iOnline247 commented 1 year ago

Running this command after checking in all the files from npx projen build on the boilerplate repo. npx projen new --from git+ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/boilerplate.git

During the installation, this error is thrown and the install stops:

Error: No projects found after installing git+ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/boilerplate.git. The module must export at least one class which extends projen.Project
    at initProjectFromModule (C:\Users\MatthewB\Documents\ps\test-projen\app\node_modules\projen\lib\cli\cmds\new.js:207:15)
    at Object.handler (C:\Users\MatthewB\Documents\ps\test-projen\app\node_modules\projen\lib\cli\cmds\new.js:101:20)
    at Object.runCommand (C:\Users\MatthewB\Documents\ps\test-projen\app\node_modules\projen\node_modules\yargs\build\index.cjs:446:48)
    at Object.parseArgs [as _parseArgs] (C:\Users\MatthewB\Documents\ps\test-projen\app\node_modules\projen\node_modules\yargs\build\index.cjs:2697:57)
    at Function.get [as argv] (C:\Users\MatthewB\Documents\ps\test-projen\app\node_modules\projen\node_modules\yargs\build\index.cjs:2651:25)
    at main (C:\Users\MatthewB\Documents\ps\test-projen\app\node_modules\projen\lib\cli\index.js:49:21)
    at Object.<anonymous> (C:\Users\MatthewB\Documents\ps\test-projen\app\node_modules\projen\lib\cli\index.js:70:1)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
mrgrain commented 1 year ago

Thanks! I should update the example code. But basically replace the code in index.ts with something like

import * as projen from 'projen';

export class MyProject extends projen.Project {
}
iOnline247 commented 1 year ago

Aye captain! Thanks!

Just so I'm clear, the ./src/index.ts file will be the .projenrc.ts file after installing from git for a new app?

mrgrain commented 1 year ago

Almost. ./src/index.ts will export your custom project class. If you are extending an existing project, your code can make any changes as required. If it's a completely new type, you will have to setup everything.

The content of .projenrc.ts is generated based on metadata. Assuming you only export a single project, that one will be used. Any required options will either be auto-filled (like author) or use the value as provided by the projen new command. Any optional options that have the @featured jsdoc flag will be put in as commented code sample.

iOnline247 commented 1 year ago

I gave it a go with extending AwsCdkTypeScriptApp but get this error.

Error: No projects found after installing git+ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/boilerplate.git. The module must export at least one class which extends projen.Project
    at initProjectFromModule (C:\Users\MatthewB\Documents\ps\test-projen\app\node_modules\projen\lib\cli\cmds\new.js:207:15)
    at Object.handler (C:\Users\MatthewB\Documents\ps\test-projen\app\node_modules\projen\lib\cli\cmds\new.js:101:20)
    at Object.runCommand (C:\Users\MatthewB\Documents\ps\test-projen\app\node_modules\projen\node_modules\yargs\build\index.cjs:446:48)
    at Object.parseArgs [as _parseArgs] (C:\Users\MatthewB\Documents\ps\test-projen\app\node_modules\projen\node_modules\yargs\build\index.cjs:2697:57)
    at Function.get [as argv] (C:\Users\MatthewB\Documents\ps\test-projen\app\node_modules\projen\node_modules\yargs\build\index.cjs:2651:25)
    at main (C:\Users\MatthewB\Documents\ps\test-projen\app\node_modules\projen\lib\cli\index.js:49:21)
    at Object.<anonymous> (C:\Users\MatthewB\Documents\ps\test-projen\app\node_modules\projen\lib\cli\index.js:70:1)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)

Here's the source from the boilerplate repo (./src/index.ts)

import { awscdk, javascript } from 'projen';

export interface PanlBoilerplateRepoProps extends awscdk.AwsCdkTypeScriptAppOptions {}

class PanlBoilerplateApp extends awscdk.AwsCdkTypeScriptApp {
  constructor(options: PanlBoilerplateRepoProps) {
    super(options);
  }
}

const cdkVersion = '2.60.0';
const project = new PanlBoilerplateApp({
  authorName: 'Matthew Bramer',
  name: 'boilerplate',
  packageManager: javascript.NodePackageManager.NPM,
  defaultReleaseBranch: 'deploy',
  cdkVersion,
  readme: {
    filename: 'README.md',
    contents: '# replace this',
  },
  deps: [`aws-cdk-lib@${cdkVersion}`, 'constructs@10.1.94'],
  devDeps: ['@mrgrain/projen-from-git@mrgrain/projen-from-git', 'typescript', 'projen@latest'],

  // description: undefined,  /* The description is just a string that helps people understand the purpose of the package. */
  // packageName: undefined,  /* The "name" in package.json. */
});

project.synth();
mrgrain commented 1 year ago

Yeah, so this file is not for calling code or creating an instance of your class but for for defining a class.

Something like this should work:

import { awscdk, javascript } from 'projen';

const cdkVersion = '2.60.0';

export interface PanlBoilerplateRepoProps extends awscdk.AwsCdkTypeScriptAppOptions {}

export class PanlBoilerplateApp extends awscdk.AwsCdkTypeScriptApp {
  constructor(options: PanlBoilerplateRepoProps) {
    super({
      // these options can be overwritten 
      authorName: 'Matthew Bramer',
      name: 'boilerplate',
      packageManager: javascript.NodePackageManager.NPM,
      defaultReleaseBranch: 'deploy',
      readme: {
        filename: 'README.md',
        contents: '# replace this',
      },
      ...options,
      // any options down here would be forced and not changeable
      cdkVersion,
    });
   // deps are better added like this
   this.addDeps(`aws-cdk-lib@${cdkVersion}`, 'constructs@10.1.94');
  }
}
iOnline247 commented 1 year ago

It's working! Thank you... Here is something that the shell reports back, even though the project is populated with all the files I expect.

image

I'm getting this same error with using the commit-ish suffix or without it. This is what is in package.json after installation:

"git+ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/boilerplate.git#18a028e97ff7f9d671c66a007608e096684dd0a4": "*",

mrgrain commented 1 year ago

Yeah you need to use projen new --from <package-name>@<git-remote>

See https://github.com/mrgrain/projen-from-git#usage