Skip to content

Commit

Permalink
feat: @iceworks/[email protected] (#1053)
Browse files Browse the repository at this point in the history
* feat: support generate ice3 project

* chore: update ci node version

* chore: update registry

* chore: remove registry

* feat: dist format

* chore: version

* fix: test fail

* fix: ts error

* feat: update test case

* fix: package not found

* fix: build error

* fix: export function is not correct

* fix: lint

* fix: test

* fix: tsconfig

* chore: remove beta version

* test: add timeout
  • Loading branch information
luhc228 authored Mar 8, 2023
1 parent 4304638 commit 5049e1a
Show file tree
Hide file tree
Showing 23 changed files with 519 additions and 331 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/auto-publisher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 14
registry-url: https://registry.npmjs.org/
- run: |
npm i
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/beta-publisher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 14
registry-url: https://registry.npmjs.org/
- run: |
npm i
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
node-version: [12.x]
node-version: [14.x]

steps:
- uses: actions/checkout@v2
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
],
"scripts": {
"setup": "npm run setup:packages && npm run setup:extensions",
"setup:packages": "npm run packages:install && lerna clean --yes && npm run packages:link && npm run packages:build",
"setup:packages": "npm run packages:install && npm run packages:link && npm run packages:build",
"setup:extensions": "npm run extensions:install && npm run extensions:link",
"ci:setup": "npm run env && npm run setup:packages",
"test": "NODE_ENV=unittest LOG_LEVEL=verbose jest",
"packages:install": "rm -rf node_modules && rm -rf ./packages/*/node_modules && rm -rf ./packages/*/package-lock.json && SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/ yarn install",
"packages:install": "rm -rf node_modules && rm -rf ./packages/*/node_modules && rm -rf ./packages/*/package-lock.json && yarn install",
"packages:link": "lerna link",
"packages:watch": "ts-node ./scripts/watch.ts",
"packages:build": "npm run packages:clean && ts-node ./scripts/build.ts",
Expand Down Expand Up @@ -87,7 +87,6 @@
"lodash.padstart": "^4.6.1",
"lodash.unionby": "^4.8.0",
"markdownlint": "^0.20.4",
"nsfw": "^1.2.7",
"package-json": "^6.5.0",
"pify": "^5.0.0",
"prettier": "^2.2.1",
Expand Down
4 changes: 4 additions & 0 deletions packages/generate-project/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# `@iceworks/generate-project`

## 2.0.0

- [chore]: support generate ice.js 3 scaffolds

## 1.4.6

- [chore]: update taobao npm registry from `https://registry.npm.taobao.org` to `https://registry.npmmirror.com`
Expand Down
12 changes: 7 additions & 5 deletions packages/generate-project/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import { downloadAndGenerateProject } from '@iceworks/generate-project';

await downloadAndGenerateProject(
projectDir,
npmName,
npmVersion,
npmRegistry?,
projectName?,
ejsOptions?,
scaffoldNpmName,
{
version,
registry,
extraDependencies,
ejsOptions,
}
);
```
15 changes: 9 additions & 6 deletions packages/generate-project/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@iceworks/generate-project",
"version": "1.4.6",
"version": "2.0.0",
"description": "Generator project",
"files": [
"lib/"
],
"engines": {
"node": ">=12"
"node": ">=12.20.0"
},
"main": "lib/index.js",
"repository": {
Expand All @@ -22,14 +22,17 @@
},
"dependencies": {
"@appworks/constant": "^0.1.0",
"ejs": "^3.1.3",
"ejs": "^3.1.8",
"fs-extra": "^8.1.0",
"glob": "^7.1.6",
"ice-npm-utils": "^3.0.0",
"ora": "^4.0.3"
"ora": "^5.4.1",
"prettier": "^2.7.1"
},
"gitHead": "fc5b35f95ab4cc24898845916acf598c2f34d576",
"devDependencies": {
"@types/fs-extra": "^9.0.1"
"@types/ejs": "^3.1.2",
"@types/fs-extra": "^8.0.0",
"@types/prettier": "^2.7.2",
"typescript": "^4.9.5"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import { downloadAndGenerateProject } from '..';

const tmpPath = path.resolve(__dirname, '../../.tmp');

jest.setTimeout(60 * 1000);

beforeAll(async () => {
await fs.ensureDir(tmpPath);
})

test('generate ice3-lite scaffold', async () => {
const projectDir = path.resolve(tmpPath, 'ice-lite');
await fs.ensureDir(projectDir);

await downloadAndGenerateProject(
projectDir,
'@ice/lite-scaffold',
{
ejsOptions: {
appConfig: {
importDeclarationsStr: `import type { Manifest } from '@ice/plugin-pha/types';
import { defineSpmConfig } from '@ali/ice-plugin-spm/types';
`,
exportDeclarationsStr: `
export const spmConfig = defineSpmConfig(() => {
return {
spmA: 'spmA',
}
});
export const phaManifest: Manifest = {
routes: [
'index',
],
}
`,
},
iceConfig: {
importDeclarationsStr: `import def from '@ali/ice-plugin-def';
import pha from '@ice/plugin-pha';
import spm from '@ali/ice-plugin-spm';\n`,
optionsStr: `
plugins: [
def(),
pha(),
spm(),
],
`,
},
esLintConfigOptions: `{
extends: []
}`,
},
extraDependencies: {
devDependencies: {
'@ali/ice-plugin-def': '^1.0.0',
'@ali/ice-plugin-spm': '^1.0.0',
'@ice/plugin-pha': '^2.0.0',
},
},
}
);

const pkgJsonPath = path.join(projectDir, 'package.json');
const pkgJsonContent = await fs.readJSON(pkgJsonPath);
expect(pkgJsonContent.version).toBe('0.1.0');
expect(Object.keys(pkgJsonContent.devDependencies).includes('@ali/ice-plugin-def')).toBeTruthy();
expect(Object.keys(pkgJsonContent.devDependencies).includes('@ali/ice-plugin-spm')).toBeTruthy();
expect(Object.keys(pkgJsonContent.devDependencies).includes('@ice/plugin-pha')).toBeTruthy();

const appConfigPath = path.join(projectDir, 'src/app.ts');
const appConfigContent = await fs.readFile(appConfigPath, 'utf-8');
expect(appConfigContent.includes('export const phaManifest')).toBeTruthy();
expect(appConfigContent.includes('export const spmConfig')).toBeTruthy();
expect(appConfigContent.includes(`import type { Manifest } from '@ice/plugin-pha/types';
import { defineSpmConfig } from '@ali/ice-plugin-spm/types';`)).toBeTruthy();

const configPath = path.join(projectDir, 'ice.config.mts');
const configContent = await fs.readFile(configPath, 'utf-8');
expect(configContent.includes(`import def from '@ali/ice-plugin-def';
import pha from '@ice/plugin-pha';
import spm from '@ali/ice-plugin-spm';`)).toBeTruthy();
expect(configContent.includes('plugins: [def(), pha(), spm()]')).toBeTruthy();

const eslintConfig = path.join(projectDir, '.eslintrc.cjs');
const eslintConfigContent = await fs.readFile(eslintConfig, 'utf-8');
expect(eslintConfigContent.includes("extends: [],")).toBeTruthy();
})

test('generate antd-pro scaffold', async () => {
const projectDir = path.resolve(tmpPath, 'antd-pro');
await fs.ensureDir(projectDir);

await downloadAndGenerateProject(
projectDir,
'@ice/antd-pro-scaffold',
{
ejsOptions: {
appConfig: {
configStr: `router: {
type: 'hash',
},`,
},
iceConfig: {
importDeclarationsStr: `import def from '@ali/ice-plugin-def';\n`,
options: {
pluginItemsStr: `def(),`
},
},
esLintConfigOptions: `{
extends: []
}`,
},
extraDependencies: {
devDependencies: {
'@ali/ice-plugin-def': '^1.0.0',
},
}
}
);

const pkgJsonPath = path.join(projectDir, 'package.json');
const pkgJsonContent = await fs.readJSON(pkgJsonPath);
expect(pkgJsonContent.version).toBe('0.1.0');
expect(Object.keys(pkgJsonContent.devDependencies).includes('@ali/ice-plugin-def')).toBeTruthy();

const appConfigPath = path.join(projectDir, 'src/app.ts');
const appConfigContent = await fs.readFile(appConfigPath, 'utf-8');
expect(appConfigContent.includes(`router: {
type: 'hash',
},`)).toBeTruthy();

const configPath = path.join(projectDir, 'ice.config.mts');
const configContent = await fs.readFile(configPath, 'utf-8');
expect(configContent.includes(`import def from '@ali/ice-plugin-def';`)).toBeTruthy();
expect(configContent.includes('plugins: [request(), store(), auth(), def()]')).toBeTruthy();

const eslintConfig = path.join(projectDir, '.eslintrc.cjs');
const eslintConfigContent = await fs.readFile(eslintConfig, 'utf-8');
expect(eslintConfigContent.includes("extends: [],")).toBeTruthy();
})

test('generate fusion-pro scaffold', async () => {
const projectDir = path.resolve(tmpPath, 'fusion-pro');
await fs.ensureDir(projectDir);

await downloadAndGenerateProject(
projectDir,
'@ice/fusion-pro-scaffold',
{
ejsOptions: {
appConfig: {
configStr: `router: {
type: 'hash',
},`,
},
iceConfig: {
importDeclarationsStr: `import def from '@ali/ice-plugin-def';\n`,
options: {
pluginItemsStr: `def(),`
},
},
esLintConfigOptions: `{
extends: []
}`,
},
extraDependencies: {
devDependencies: {
'@ali/ice-plugin-def': '^1.0.0',
},
}
}
);

const pkgJsonPath = path.join(projectDir, 'package.json');
const pkgJsonContent = await fs.readJSON(pkgJsonPath);
expect(pkgJsonContent.version).toBe('0.1.0');
expect(Object.keys(pkgJsonContent.devDependencies).includes('@ali/ice-plugin-def')).toBeTruthy();

const appConfigPath = path.join(projectDir, 'src/app.ts');
const appConfigContent = await fs.readFile(appConfigPath, 'utf-8');
expect(appConfigContent.includes(`router: {
type: 'hash',
},`)).toBeTruthy();

const configPath = path.join(projectDir, 'ice.config.mts');
const configContent = await fs.readFile(configPath, 'utf-8');
expect(configContent.includes(`import def from '@ali/ice-plugin-def';`)).toBeTruthy();
expect(configContent.includes('plugins: [request(), store(), auth(), def()]')).toBeTruthy();

const eslintConfig = path.join(projectDir, '.eslintrc.cjs');
const eslintConfigContent = await fs.readFile(eslintConfig, 'utf-8');
expect(eslintConfigContent.includes("extends: [],")).toBeTruthy();
})
45 changes: 0 additions & 45 deletions packages/generate-project/src/__tests__/index.ts

This file was deleted.

23 changes: 23 additions & 0 deletions packages/generate-project/src/addDependenciesToPkgJson.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as path from 'path';
import * as fse from 'fs-extra';

export interface ExtraDependencies {
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
}

export default async function addDependencies(extraDependencies: ExtraDependencies, projectDir: string) {
const pkgJsonPath = path.join(projectDir, 'package.json');
if (!await fse.pathExists(pkgJsonPath)) {
throw new Error(`Path ${pkgJsonPath} does not exist.`);
}
const pkgJson = await fse.readJSON(path.join(projectDir, 'package.json'));
Object.entries(extraDependencies).forEach(([depType, value]) => {
if (!pkgJson[depType]) {
pkgJson[depType] = {};
}
pkgJson[depType] = { ...value, ...pkgJson[depType] };
});

await fse.writeJSON(pkgJsonPath, pkgJson, { spaces: 2 });
}
Loading

0 comments on commit 5049e1a

Please sign in to comment.