Skip to content

Commit

Permalink
Fix publish script (#1916)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong authored Jun 27, 2023
1 parent af52fc7 commit e0da6ba
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 47 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "roosterjs",
"version": "0.0.0",
"description": "Framework-independent javascript editor",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
"roosterjs-editor-dom": "",
"roosterjs-content-model-types": ""
},
"main": "./lib/index.ts",
"version": "0.0.1"
"main": "./lib/index.ts"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
"roosterjs-content-model-dom": "",
"roosterjs-content-model-types": ""
},
"main": "./lib/index.ts",
"version": "0.0.1"
"main": "./lib/index.ts"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
"dependencies": {
"roosterjs-editor-types": ""
},
"main": "./lib/index.ts",
"version": "0.0.1"
"main": "./lib/index.ts"
}
5 changes: 2 additions & 3 deletions packages-content-model/roosterjs-content-model/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "roosterjs-content-model-dom",
"name": "roosterjs-content-model",
"description": "Content Model for roosterjs (Under development)",
"dependencies": {
"tslib": "^2.3.1",
Expand All @@ -11,6 +11,5 @@
"roosterjs-content-model-editor": "",
"roosterjs-color-utils": ""
},
"main": "./lib/index.ts",
"version": "0.0.1"
"main": "./lib/index.ts"
}
4 changes: 2 additions & 2 deletions tools/buildTools/checkDependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const path = require('path');
const fs = require('fs');
const { allPackages, readPackageJson, findPackageRoot, err } = require('./common');
const { allPackages, readPackageJson, findPackageRoot, err, rootPath } = require('./common');

function getPossibleNames(dir, objectName) {
return [
Expand Down Expand Up @@ -88,7 +88,7 @@ const GlobalAllowedCrossPackageDependency = [

function checkDependency() {
allPackages.forEach(packageName => {
const packageRoot = findPackageRoot(packageName);
const packageRoot = path.join(rootPath, findPackageRoot(packageName));

var packageJson = readPackageJson(packageName, true /*readFromSourceFolder*/);
var dependencies = Object.keys(packageJson.dependencies);
Expand Down
27 changes: 17 additions & 10 deletions tools/buildTools/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ const assign = require('object-assign');
const toposort = require('toposort');
const webpack = require('webpack');

const packagesName = 'packages';
const packagesUiName = 'packages-ui';
const packagesContentModelName = 'packages-content-model';

const rootPath = path.join(__dirname, '../..');
const packagesPath = path.join(rootPath, 'packages');
const packagesUiPath = path.join(rootPath, 'packages-ui');
const packagesContentModelPath = path.join(rootPath, 'packages-content-model');
const packagesPath = path.join(rootPath, packagesName);
const packagesUiPath = path.join(rootPath, packagesUiName);
const packagesContentModelPath = path.join(rootPath, packagesContentModelName);
const nodeModulesPath = path.join(rootPath, 'node_modules');
const typescriptPath = path.join(nodeModulesPath, 'typescript/lib/tsc.js');
const distPath = path.join(rootPath, 'dist');
Expand Down Expand Up @@ -84,17 +88,17 @@ function err(message) {

function findPackageRoot(packageName) {
return packages.indexOf(packageName) >= 0
? packagesPath
? packagesName
: packagesUI.indexOf(packageName) >= 0
? packagesUiPath
? packagesUiName
: packagesContentModel.indexOf(packageName) >= 0
? packagesContentModelPath
? packagesContentModelName
: null;
}

function readPackageJson(packageName, readFromSourceFolder) {
const packageJsonFilePath = path.join(
readFromSourceFolder ? findPackageRoot(packageName) : distPath,
readFromSourceFolder ? rootPath + '/' + findPackageRoot(packageName) : distPath,
packageName,
'package.json'
);
Expand Down Expand Up @@ -145,7 +149,7 @@ function getWebpackExternalCallback(externalLibraryPairs, internalLibraries) {
}

const buildConfig = {
rooster: {
packages: {
targetPath: roosterJsDistPath,
packEntry: path.join(packagesPath, 'roosterjs/lib/index.ts'),
jsFileBaseName: 'rooster',
Expand All @@ -155,7 +159,7 @@ const buildConfig = {
targetFileName: 'rooster',
externalHandler: undefined,
},
roosterReact: {
'packages-ui': {
targetPath: roosterJsUiDistPath,
packEntry: path.join(packagesUiPath, 'roosterjs-react/lib/index.ts'),
jsFileBaseName: 'rooster-react',
Expand All @@ -167,7 +171,7 @@ const buildConfig = {
dependsOnRoosterJs: true,
dependsOnReact: true,
},
roosterContentModel: {
'packages-content-model': {
targetPath: contentModelDistPath,
packEntry: path.join(packagesContentModelPath, 'roosterjs-content-model/lib/index.ts'),
jsFileBaseName: 'rooster-content-model',
Expand All @@ -183,6 +187,8 @@ const buildConfig = {
},
};

const versions = JSON.parse(fs.readFileSync(path.join(rootPath, 'versions.json')));

module.exports = {
rootPath,
packagesPath,
Expand All @@ -208,4 +214,5 @@ module.exports = {
getWebpackExternalCallback,
contentModelDistPath,
buildConfig,
versions,
};
20 changes: 10 additions & 10 deletions tools/buildTools/dts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const {
rootPath,
distPath,
roosterJsDistPath,
mainPackageJson,
nodeModulesPath,
runNode,
err,
buildConfig,
versions,
} = require('./common');

const namePlaceholder = '__NAME__';
Expand Down Expand Up @@ -319,8 +319,8 @@ function publicElement(element) {
});
}

function generateDts(library, isAmd, queue) {
var version = JSON.stringify(mainPackageJson.version).replace(/"/g, '');
function generateDts(library, isAmd, queue, version) {
var version = JSON.stringify(version).replace(/"/g, '');
var content = '';
content += `// Type definitions for roosterjs (Version ${version})\r\n`;
content += '// Generated by dts tool from roosterjs\r\n';
Expand Down Expand Up @@ -444,7 +444,7 @@ function dts(isAmd, target) {
});

const dtsQueue = createQueue(rootPath, distPath, startFileName, tsFiles, externalHandler);
const dtsContent = generateDts(libraryName, isAmd, dtsQueue);
const dtsContent = generateDts(libraryName, isAmd, dtsQueue, versions[target]);
const fileName = `${targetFileName}${isAmd ? '-amd' : ''}.d.ts`;
const fullFileName = path.join(targetPath, fileName);

Expand Down Expand Up @@ -475,32 +475,32 @@ function dts(isAmd, target) {
module.exports = {
dtsCommonJs: {
message: `Generating type definition file (rooster.d.ts) for CommonJs...`,
callback: () => dts(false /*isAmd*/, 'rooster'),
callback: () => dts(false /*isAmd*/, 'packages'),
enabled: options => options.dts,
},
dtsAmd: {
message: `Generating type definition file (rooster-amd.d.ts) for AMD...`,
callback: () => dts(true /*isAmd*/, 'rooster'),
callback: () => dts(true /*isAmd*/, 'packages'),
enabled: options => options.dts,
},
dtsCommonJsUi: {
message: `Generating type definition file (rooster-react.d.ts) for CommonJs...`,
callback: () => dts(false /*isAmd*/, 'roosterReact'),
callback: () => dts(false /*isAmd*/, 'packages-ui'),
enabled: options => options.dts,
},
dtsAmdUi: {
message: `Generating type definition file (rooster-react-amd.d.ts) for AMD...`,
callback: () => dts(true /*isAmd*/, 'roosterReact'),
callback: () => dts(true /*isAmd*/, 'packages-ui'),
enabled: options => options.dts,
},
dtsCommonJsContentModel: {
message: `Generating type definition file (rooster-content-model.d.ts) for CommonJs...`,
callback: () => dts(false /*isAmd*/, 'roosterContentModel'),
callback: () => dts(false /*isAmd*/, 'packages-content-model'),
enabled: options => options.dts,
},
dtsAmdContentModel: {
message: `Generating type definition file (rooster-content-model-amd.d.ts) for AMD...`,
callback: () => dts(true /*isAmd*/, 'roosterContentModel'),
callback: () => dts(true /*isAmd*/, 'packages-content-model'),
enabled: options => options.dts,
},
};
18 changes: 15 additions & 3 deletions tools/buildTools/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ const path = require('path');
const mkdirp = require('mkdirp');
const fs = require('fs');
const processConstEnum = require('./processConstEnum');
const { allPackages, distPath, readPackageJson, mainPackageJson, err } = require('./common');
const {
allPackages,
distPath,
readPackageJson,
mainPackageJson,
err,
findPackageRoot,
versions,
} = require('./common');

function normalize() {
const knownCustomizedPackages = {};

allPackages.forEach(packageName => {
const versionKey = findPackageRoot(packageName);
const version = versions[versionKey];
const packageJson = readPackageJson(packageName, true /*readFromSourceFolder*/);

Object.keys(packageJson.dependencies).forEach(dep => {
Expand All @@ -18,7 +28,9 @@ function normalize() {
} else if (knownCustomizedPackages[dep]) {
packageJson.dependencies[dep] = '^' + knownCustomizedPackages[dep];
} else if (allPackages.indexOf(dep) > -1) {
packageJson.dependencies[dep] = '^' + mainPackageJson.version;
var depKey = findPackageRoot(dep);
var depVersion = versions[depKey];
packageJson.dependencies[dep] = '^' + depVersion;
} else if (mainPackageJson.dependencies && mainPackageJson.dependencies[dep]) {
packageJson.dependencies[dep] = mainPackageJson.dependencies[dep];
} else if (!packageJson.dependencies[dep]) {
Expand All @@ -29,7 +41,7 @@ function normalize() {
if (packageJson.version) {
knownCustomizedPackages[packageName] = packageJson.version;
} else {
packageJson.version = mainPackageJson.version;
packageJson.version = version;
}

packageJson.typings = './lib/index.d.ts';
Expand Down
28 changes: 16 additions & 12 deletions tools/buildTools/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,32 @@ function createStep(isProduction, isAmd, target) {
}

module.exports = {
commonJsDebug: createStep(false /*isProduction*/, false /*isAmd*/, 'rooster'),
commonJsProduction: createStep(true /*isProduction*/, false /*isAmd*/, 'rooster'),
amdDebug: createStep(false /*isProduction*/, true /*isAmd*/, 'rooster'),
amdProduction: createStep(true /*isProduction*/, true /*isAmd*/, 'rooster'),
commonJsDebugUi: createStep(false /*isProduction*/, false /*isAmd*/, 'roosterReact'),
commonJsProductionUi: createStep(true /*isProduction*/, false /*isAmd*/, 'roosterReact'),
amdDebugUi: createStep(false /*isProduction*/, true /*isAmd*/, 'roosterReact'),
amdProductionUi: createStep(true /*isProduction*/, true /*isAmd*/, 'roosterReact'),
commonJsDebug: createStep(false /*isProduction*/, false /*isAmd*/, 'packages'),
commonJsProduction: createStep(true /*isProduction*/, false /*isAmd*/, 'packages'),
amdDebug: createStep(false /*isProduction*/, true /*isAmd*/, 'packages'),
amdProduction: createStep(true /*isProduction*/, true /*isAmd*/, 'packages'),
commonJsDebugUi: createStep(false /*isProduction*/, false /*isAmd*/, 'packages-ui'),
commonJsProductionUi: createStep(true /*isProduction*/, false /*isAmd*/, 'packages-ui'),
amdDebugUi: createStep(false /*isProduction*/, true /*isAmd*/, 'packages-ui'),
amdProductionUi: createStep(true /*isProduction*/, true /*isAmd*/, 'packages-ui'),
commonJsDebugContentModel: createStep(
false /*isProduction*/,
false /*isAmd*/,
'roosterContentModel'
'packages-content-model'
),
commonJsProductionContentModel: createStep(
true /*isProduction*/,
false /*isAmd*/,
'roosterContentModel'
'packages-content-model'
),
amdDebugContentModel: createStep(
false /*isProduction*/,
true /*isAmd*/,
'packages-content-model'
),
amdDebugContentModel: createStep(false /*isProduction*/, true /*isAmd*/, 'roosterContentModel'),
amdProductionContentModel: createStep(
true /*isProduction*/,
true /*isAmd*/,
'roosterContentModel'
'packages-content-model'
),
};
5 changes: 5 additions & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"packages": "0.0.0",
"packages-ui": "0.0.0",
"packages-content-model": "0.0.0"
}

0 comments on commit e0da6ba

Please sign in to comment.